mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
improved stats with memory usage (OSX)
This commit is contained in:
@@ -208,10 +208,11 @@ bool ImGuiToolkit::ButtonIconMultistate(std::vector<std::pair<int, int> > icons,
|
|||||||
Sum id = std::for_each(icons.begin(), icons.end(), Sum());
|
Sum id = std::for_each(icons.begin(), icons.end(), Sum());
|
||||||
ImGui::PushID( id.sum );
|
ImGui::PushID( id.sum );
|
||||||
|
|
||||||
int s = CLAMP(*state, 0, icons.size() - 1);
|
int num_button = static_cast<int>(icons.size()) -1;
|
||||||
|
int s = CLAMP(*state, 0, num_button);
|
||||||
if ( ButtonIcon( icons[s].first, icons[s].second ) ){
|
if ( ButtonIcon( icons[s].first, icons[s].second ) ){
|
||||||
++s;
|
++s;
|
||||||
if (s > icons.size() -1)
|
if (s > num_button)
|
||||||
*state = 0;
|
*state = 0;
|
||||||
else
|
else
|
||||||
*state = s;
|
*state = s;
|
||||||
@@ -530,7 +531,7 @@ bool ImGuiToolkit::TimelineSliderEdit(const char* label, guint64 *time, guint64
|
|||||||
|
|
||||||
// segments behavior
|
// segments behavior
|
||||||
float time_segment_begin = 0.f;
|
float time_segment_begin = 0.f;
|
||||||
float time_segment_end = 0.f;
|
// float time_segment_end = 0.f;
|
||||||
if (right_mouse_press) {
|
if (right_mouse_press) {
|
||||||
time_segment_begin = 0.f;
|
time_segment_begin = 0.f;
|
||||||
}
|
}
|
||||||
@@ -797,25 +798,17 @@ void ImGuiToolkit::ShowStats(bool *p_open, int* p_corner)
|
|||||||
{
|
{
|
||||||
|
|
||||||
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
||||||
// 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("Window %.0f x %.0f", 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("Refresh %.1f FPS", io.Framerate);
|
||||||
ImGui::Text("Rendering %.1f FPS", io.Framerate);
|
ImGui::Text("Memory %s", SystemToolkit::byte_to_string( SystemToolkit::memory_usage()).c_str() );
|
||||||
ImGui::Text("Memory %s", SystemToolkit::byte_to_string( SystemToolkit::memory_usage()).c_str() );
|
|
||||||
// ImGui::Text("Memory %.ld MB", SystemToolkit::memory_usage());
|
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
|
||||||
if (ImGui::BeginPopupContextWindow())
|
if (ImGui::BeginPopupContextWindow())
|
||||||
{
|
{
|
||||||
if (ImGui::MenuItem("Custom", NULL, corner == -1)) *p_corner = -1;
|
if (ImGui::MenuItem("Custom", NULL, corner == -1)) *p_corner = -1;
|
||||||
// if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0;
|
|
||||||
if (ImGui::MenuItem("Top", NULL, corner == 1)) *p_corner = 1;
|
if (ImGui::MenuItem("Top", NULL, corner == 1)) *p_corner = 1;
|
||||||
// if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2;
|
|
||||||
if (ImGui::MenuItem("Bottom", NULL, corner == 3)) *p_corner = 3;
|
if (ImGui::MenuItem("Bottom", NULL, corner == 3)) *p_corner = 3;
|
||||||
if (p_open && ImGui::MenuItem("Close")) *p_open = false;
|
if (p_open && ImGui::MenuItem("Close")) *p_open = false;
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -12,7 +13,9 @@ using namespace std;
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define mkdir(dir, mode) _mkdir(dir)
|
#define mkdir(dir, mode) _mkdir(dir)
|
||||||
#include <include/dirent.h>
|
#include <include/dirent.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
#define PATH_SEP '\\'
|
#define PATH_SEP '\\'
|
||||||
|
#define PATH_SETTINGS "\\\AppData\\Roaming\\"
|
||||||
#elif defined(LINUX) or defined(APPLE)
|
#elif defined(LINUX) or defined(APPLE)
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -22,20 +25,61 @@ using namespace std;
|
|||||||
#define PATH_SEP '/'
|
#define PATH_SEP '/'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#if defined(APPLE)
|
||||||
#define PATH_SETTINGS "\\\AppData\\Roaming\\"
|
|
||||||
#elif defined(APPLE)
|
|
||||||
#define PATH_SETTINGS "/Library/Application Support/"
|
#define PATH_SETTINGS "/Library/Application Support/"
|
||||||
|
#include <mach/task.h>
|
||||||
|
#include <mach/mach_init.h>
|
||||||
#elif defined(LINUX)
|
#elif defined(LINUX)
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
#define PATH_SETTINGS "/.config/"
|
#define PATH_SETTINGS "/.config/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "SystemToolkit.h"
|
#include "SystemToolkit.h"
|
||||||
|
|
||||||
|
/// The amount of memory currently being used by this process, in bytes.
|
||||||
|
/// it will try to report the resident set in RAM
|
||||||
|
long SystemToolkit::memory_usage()
|
||||||
|
{
|
||||||
|
#if defined(LINUX)
|
||||||
|
// Ugh, getrusage doesn't work well on Linux. Try grabbing info
|
||||||
|
// directly from the /proc pseudo-filesystem. Reading from
|
||||||
|
// /proc/self/statm gives info on your own process, as one line of
|
||||||
|
// numbers that are: virtual mem program size, resident set size,
|
||||||
|
// shared pages, text/code, data/stack, library, dirty pages. The
|
||||||
|
// mem sizes should all be multiplied by the page size.
|
||||||
|
size_t size = 0;
|
||||||
|
FILE *file = fopen("/proc/self/statm", "r");
|
||||||
|
if (file) {
|
||||||
|
unsigned long vm = 0;
|
||||||
|
fscanf (file, "%ul", &vm); // Just need the first num: vm size
|
||||||
|
fclose (file);
|
||||||
|
size = (size_t)vm * getpagesize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
|
||||||
|
#elif defined(APPLE)
|
||||||
|
// Inspired from
|
||||||
|
// http://miknight.blogspot.com/2005/11/resident-set-size-in-mac-os-x.html
|
||||||
|
struct task_basic_info t_info;
|
||||||
|
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
|
||||||
|
task_info(current_task(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
|
||||||
|
return t_info.resident_size;
|
||||||
|
|
||||||
|
#elif defined(WIN32)
|
||||||
|
// According to MSDN...
|
||||||
|
PROCESS_MEMORY_COUNTERS counters;
|
||||||
|
if (GetProcessMemoryInfo (GetCurrentProcess(), &counters, sizeof (counters)))
|
||||||
|
return counters.PagefileUsage;
|
||||||
|
else return 0;
|
||||||
|
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
long SystemToolkit::memory_max_usage() {
|
||||||
|
|
||||||
long SystemToolkit::memory_usage() {
|
|
||||||
struct rusage r_usage;
|
struct rusage r_usage;
|
||||||
getrusage(RUSAGE_SELF,&r_usage);
|
getrusage(RUSAGE_SELF,&r_usage);
|
||||||
return r_usage.ru_maxrss;
|
return r_usage.ru_maxrss;
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ namespace SystemToolkit
|
|||||||
// try to open the file with system
|
// try to open the file with system
|
||||||
void open(const std::string& path);
|
void open(const std::string& path);
|
||||||
|
|
||||||
// (tries to) return maximum resident set size used (in kilobytes)
|
// return memory resident set size used (in bytes)
|
||||||
long memory_usage();
|
long memory_usage();
|
||||||
|
long memory_max_usage();
|
||||||
|
|
||||||
// get a string to display memory size with unit KB, MB, GB, TB
|
// get a string to display memory size with unit KB, MB, GB, TB
|
||||||
std::string byte_to_string(long b);
|
std::string byte_to_string(long b);
|
||||||
|
|||||||
Reference in New Issue
Block a user