mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Implementation of memory usage monitor.
This commit is contained in:
@@ -669,7 +669,7 @@ void ImGuiToolkit::Bar(float value, float in, float out, float min, float max, c
|
||||
|
||||
|
||||
ImVec2 pos0 = ImLerp(bb.Min, bb.Max, 0.1);
|
||||
ImVec2 pos1 = ImLerp(bb.Min, bb.Max, 0.2);
|
||||
// ImVec2 pos1 = ImLerp(bb.Min, bb.Max, 0.2);
|
||||
float step = (bb.Max.x - bb.Min.x) / 100.f;
|
||||
int i = 0;
|
||||
for (float tic = bb.Min.x; tic < bb.Max.x; tic += step, ++i) {
|
||||
@@ -797,15 +797,17 @@ void ImGuiToolkit::ShowStats(bool *p_open, int* p_corner)
|
||||
{
|
||||
|
||||
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
||||
if (ImGui::IsMousePosValid())
|
||||
ImGui::Text("Mouse (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
|
||||
else
|
||||
ImGui::Text("Mouse <invalid>");
|
||||
// if (ImGui::IsMousePosValid())
|
||||
// ImGui::Text("Mouse (%.1f,%.1f)", io.MousePos.x, io.MousePos.y);
|
||||
// else
|
||||
// ImGui::Text("Mouse <invalid>");
|
||||
|
||||
ImGui::Text("Window (%.1f,%.1f)", io.DisplaySize.x, io.DisplaySize.y);
|
||||
ImGui::Text("HiDPI (retina) %s", io.DisplayFramebufferScale.x > 1.f ? "on" : "off");
|
||||
// ImGui::Text("HiDPI (retina) %s", io.DisplayFramebufferScale.x > 1.f ? "on" : "off");
|
||||
// ImGui::Text("DPI Scale (%.1f,%.1f)", io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
|
||||
ImGui::Text("Rendering %.1f FPS", io.Framerate);
|
||||
ImGui::Text("Memory %s", SystemToolkit::byte_to_string( SystemToolkit::memory_usage()).c_str() );
|
||||
// ImGui::Text("Memory %.ld MB", SystemToolkit::memory_usage());
|
||||
ImGui::PopFont();
|
||||
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
|
||||
@@ -14,6 +14,7 @@ using namespace std;
|
||||
#include <include/dirent.h>
|
||||
#define PATH_SEP '\\'
|
||||
#elif defined(LINUX) or defined(APPLE)
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
@@ -33,6 +34,32 @@ using namespace std;
|
||||
#include "SystemToolkit.h"
|
||||
|
||||
|
||||
|
||||
long SystemToolkit::memory_usage() {
|
||||
struct rusage r_usage;
|
||||
getrusage(RUSAGE_SELF,&r_usage);
|
||||
return r_usage.ru_maxrss;
|
||||
// return r_usage.ru_isrss;
|
||||
}
|
||||
|
||||
string SystemToolkit::byte_to_string(long b)
|
||||
{
|
||||
double numbytes = static_cast<double>(b);
|
||||
ostringstream oss;
|
||||
|
||||
std::list<std::string> list = {" Bytes", " KB", " MB", " GB", " TB"};
|
||||
std::list<std::string>::iterator i = list.begin();
|
||||
|
||||
while(numbytes >= 1024.0 && i != list.end())
|
||||
{
|
||||
i++;
|
||||
numbytes /= 1024.0;
|
||||
}
|
||||
oss << std::fixed << std::setprecision(2) << numbytes << *i;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
string SystemToolkit::date_time_string()
|
||||
{
|
||||
chrono::system_clock::time_point now = chrono::system_clock::now();
|
||||
|
||||
@@ -50,6 +50,12 @@ namespace SystemToolkit
|
||||
|
||||
// try to open the file with system
|
||||
void open(const std::string& path);
|
||||
|
||||
// (tries to) return maximum resident set size used (in kilobytes)
|
||||
long memory_usage();
|
||||
|
||||
// get a string to display memory size with unit KB, MB, GB, TB
|
||||
std::string byte_to_string(long b);
|
||||
}
|
||||
|
||||
#endif // SYSTEMTOOLKIT_H
|
||||
|
||||
Reference in New Issue
Block a user