Skip to content

Commit

Permalink
moved ram and cpu usage to separate window
Browse files Browse the repository at this point in the history
  • Loading branch information
xLPMG committed Jan 26, 2024
1 parent 7a47c90 commit b1ee961
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/systeminfo/SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ void tsunami_lab::systeminfo::SystemInfo::getRAMUsage(double &o_totalRAM, double
long long l_totalPhysMem = l_memInfo.totalram;
// Multiply in next statement to avoid int overflow on right hand side...
l_totalPhysMem *= l_memInfo.mem_unit;
l_totalPhysMem *= m_bytesToGB;
l_totalPhysMem *= m_bytesToGiB;
o_totalRAM = l_totalPhysMem;

long long l_physMemUsed = l_memInfo.totalram - l_memInfo.freeram;
// Multiply in next statement to avoid int overflow on right hand side...
l_physMemUsed *= l_memInfo.mem_unit;
l_physMemUsed *= m_bytesToGB;
l_physMemUsed *= m_bytesToGiB;
o_usedRAM = l_physMemUsed;

#elif __APPLE__ || __MACH__
Expand All @@ -73,7 +73,7 @@ void tsunami_lab::systeminfo::SystemInfo::getRAMUsage(double &o_totalRAM, double
unsigned long l_length = sizeof(int64_t);
sysctl(l_mib, 2, &l_physicalMemoryLong, &l_length, NULL, 0);
double l_physicalMemoryDouble = l_physicalMemoryLong;
l_physicalMemoryDouble *= m_bytesToGB;
l_physicalMemoryDouble *= m_bytesToGiB;
o_totalRAM = l_physicalMemoryDouble;

std::array<char, 128> l_buffer;
Expand Down Expand Up @@ -135,7 +135,7 @@ void tsunami_lab::systeminfo::SystemInfo::getRAMUsage(double &o_totalRAM, double
l_pages -= std::stol(l_valueString);
}
}
o_usedRAM = (l_pages * (double)l_pagesize) * m_bytesToGB;
o_usedRAM = (l_pages * (double)l_pagesize) * m_bytesToGiB;
#endif
}

Expand Down
14 changes: 7 additions & 7 deletions src/systeminfo/SystemInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class tsunami_lab::systeminfo::SystemInfo
{
private:

//! Conversion constant from bytes to gigabytes (1/1000^3)
double m_bytesToGB = 0.000000001;
//! Conversion constant from bytes to gibibytes (1/1000^3)
double m_bytesToGiB = 0.00000000093132257;

//! To check whether its the first time of reading cpu usage data; Linux only
bool m_firstCPURead = true;
[[maybe_unused]] bool m_firstCPURead = true;

struct CPUData
{
Expand All @@ -43,7 +43,7 @@ class tsunami_lab::systeminfo::SystemInfo
};

//! Vector for last read cpu usage data; Linux only
std::vector<CPUData> m_lastData;
[[maybe_unused]] std::vector<CPUData> m_lastData;

/**
* Reads CPU usage data from /proc/stat
Expand All @@ -59,22 +59,22 @@ class tsunami_lab::systeminfo::SystemInfo
SystemInfo();

/**
* Gets RAM usage data.
* Gets RAM usage data in GiB.
*
* @param o_totalRAM output pointer for total RAM value.
* @param o_usedRAM output pointer for used RAM value.
*/
void getRAMUsage(double &o_totalRAM, double &o_usedRAM);

/**
* @brief Gets CPU usage data.
* @brief Gets CPU usage data in percent.
*
* This function collects CPU usage data. On MacOS it will return one
* value as the overall CPU usage over all cores. This value is read from
* the "top" command. On Linux, /proc/stat is read and the
* values are calculated for each core.
*
* @return Vector with CPU usage in percent for each core.
* @return vector with CPU usage in percent for each core.
*/
std::vector<float> getCPUUsage();
};
Expand Down
88 changes: 56 additions & 32 deletions src/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ int tsunami_lab::ui::GUI::exec(std::string i_cmd, std::string i_outputFile)
return system(commandChars);
}

void tsunami_lab::ui::GUI::updateData()
void tsunami_lab::ui::GUI::updateSystemInfo()
{
if (m_connected)
{
m_communicator.sendToServer(xlpmg::messageToJsonString(xlpmg::GET_SYSTEM_INFORMATION), false);
std::string l_responseString = m_communicator.receiveFromServer(false);
m_communicator.sendToServer(xlpmg::messageToJsonString(xlpmg::GET_SYSTEM_INFORMATION), m_logSystemInfoDataTransmission);
std::string l_responseString = m_communicator.receiveFromServer(m_logSystemInfoDataTransmission);
if (json::accept(l_responseString))
{
xlpmg::Message l_responseMessage = xlpmg::jsonToMessage(json::parse(l_responseString));
Expand Down Expand Up @@ -186,6 +186,7 @@ int tsunami_lab::ui::GUI::launch()
bool showCompilerOptionsWindow = false;
bool showClientLog = false;
bool showSimulationParameterWindow = false;
bool showSystemInfoWindow = false;

ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

Expand Down Expand Up @@ -215,34 +216,12 @@ int tsunami_lab::ui::GUI::launch()

ImGui::NewFrame();

if (m_lastDataUpdate <= std::chrono::system_clock::now())
{
updateData();
m_lastDataUpdate = std::chrono::system_clock::now() + std::chrono::seconds(m_dataUpdateFrequency);
}

if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);

// Main window
{
ImGui::Begin("Welcome to the Tsunami Simulator GUI!");

if (m_cpuData.size() > 0)
{
ImGui::ProgressBar(m_cpuData[0] / 100, ImVec2(0.0f, 0.0f));
ImGui::SameLine();
ImGui::Text("Overall CPU usage");
for (unsigned long i = 1; i < m_cpuData.size(); ++i)
{
ImGui::ProgressBar(m_cpuData[i] / 100, ImVec2(0.0f, 0.0f));
ImGui::SameLine();
ImGui::Text("%s %lu", "CPU: ", i-1);
}
}

ImGui::Text("%f / %f GB RAM usage", m_usedRAM, m_totalRAM);

//-------------------------------------------//
//-----------------MAIN TABS-----------------//
//-------------------------------------------//
Expand Down Expand Up @@ -302,7 +281,7 @@ int tsunami_lab::ui::GUI::launch()
ImGui::SameLine();
if (ImGui::Button("Check connection"))
{
m_connected = m_communicator.isConnected;
m_connected = m_communicator.isConnected;
}
ImGui::BeginDisabled(!m_connected);
ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(1.0f, 0.6f, 0.6f));
Expand Down Expand Up @@ -483,6 +462,7 @@ int tsunami_lab::ui::GUI::launch()
ImGui::Checkbox("Edit compiler/runtime options", &showCompilerOptionsWindow);
ImGui::Checkbox("Edit simulation parameters", &showSimulationParameterWindow);
ImGui::Checkbox("Show client log", &showClientLog);
ImGui::Checkbox("Show system info", &showSystemInfoWindow);
ImGui::EndTabItem();
}
//------------------------------------------//
Expand Down Expand Up @@ -542,14 +522,13 @@ int tsunami_lab::ui::GUI::launch()
if (json::accept(response))
{
xlpmg::Message responseMessage = xlpmg::jsonToMessage(json::parse(response));
m_currentTimeStep = responseMessage.args.value("currentTimeStep", (int) 0);
m_maxTimeSteps = responseMessage.args.value("maxTimeStep", (int) 0);
m_timePerTimeStep = responseMessage.args.value("timePerTimeStep", (int) 0);
m_estimatedLeftTime = ((m_maxTimeSteps-m_currentTimeStep) * m_timePerTimeStep) /1000;
m_currentTimeStep = responseMessage.args.value("currentTimeStep", (int)0);
m_maxTimeSteps = responseMessage.args.value("maxTimeStep", (int)0);
m_timePerTimeStep = responseMessage.args.value("timePerTimeStep", (int)0);
m_estimatedLeftTime = ((m_maxTimeSteps - m_currentTimeStep) * m_timePerTimeStep) / 1000;

std::cout << responseMessage.args << std::endl;
}

}
ImGui::Text("current Time Step: %i", m_currentTimeStep);
ImGui::Text("Max Time Steps: %i", m_maxTimeSteps);
Expand Down Expand Up @@ -1117,6 +1096,51 @@ int tsunami_lab::ui::GUI::launch()
ImGui::TextWrapped("Our advice: only set config data before running a simulation and if you are not writing into an existing solution file.");
ImGui::End();
}
//--------------------------------------------//
//-------------SYSTEM INFORMATION-------------//
//--------------------------------------------//
if (showSystemInfoWindow)
{
if (m_lastDataUpdate <= std::chrono::system_clock::now())
{
updateSystemInfo();
m_lastDataUpdate = std::chrono::system_clock::now() + std::chrono::seconds(m_systemInfoUpdateFrequency);
}

ImGui::Begin("System information");

ImGui::Text("%f / %f GiB RAM usage", m_usedRAM, m_totalRAM);

if (m_cpuData.size() > 0)
{
ImGui::ProgressBar(m_cpuData[0] / 100, ImVec2(0.0f, 0.0f));
ImGui::SameLine();
ImGui::Text("%% overall CPU usage");

if (ImGui::TreeNode("Core info"))
{
for (unsigned long i = 1; i < m_cpuData.size(); ++i)
{
ImGui::ProgressBar(m_cpuData[i] / 100, ImVec2(0.0f, 0.0f));
ImGui::SameLine();
ImGui::Text("%s %lu", "CPU: ", i - 1);
}
ImGui::TreePop();
}
}
if (ImGui::TreeNode("Update settings"))
{
ImGui::InputInt("Update frequency", &m_systemInfoUpdateFrequency, 0);
ImGui::SetItemTooltip("in seconds");
ImGui::SameLine();
HelpMarker("The server will update data with a constant frequency. With this option, you can only specify the frequency with which the client/gui is getting that data from the server.");
m_systemInfoUpdateFrequency = abs(m_systemInfoUpdateFrequency);

ImGui::Checkbox("Log data transmission", &m_logSystemInfoDataTransmission);
ImGui::TreePop();
}
ImGui::End();
}

//-------------------------------------------//
//-------------CONNECTION STATUS-------------//
Expand Down
9 changes: 4 additions & 5 deletions src/ui/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class tsunami_lab::ui::GUI
bool m_connected = false;

std::chrono::time_point<std::chrono::system_clock> m_lastDataUpdate;
int m_dataUpdateFrequency = 5;
int m_systemInfoUpdateFrequency = 2;
bool m_logSystemInfoDataTransmission = false;
int m_clientReadBufferSize = m_communicator.BUFF_SIZE_READ_DEFAULT;
int m_clientSendBufferSize = m_communicator.BUFF_SIZE_READ_DEFAULT;
int m_serverReadBufferSize = m_communicator.BUFF_SIZE_READ_DEFAULT;
Expand Down Expand Up @@ -145,11 +146,9 @@ class tsunami_lab::ui::GUI
json createConfigJson();

/**
* Updates local config parameters with current server data.
*
* TODO: implementation
* Gets info on CPU and RAM usage from the server.
*/
void updateData();
void updateSystemInfo();

public:
/**
Expand Down

0 comments on commit b1ee961

Please sign in to comment.