[wing] Add wing_get_process_memory



commit 4d61d10e454e26f6d35890e686fc00f5b7f30e5c
Author: Ignacio Casal Quinteiro <qignacio amazon com>
Date:   Wed Mar 29 11:05:49 2017 +0200

    Add wing_get_process_memory

 wing/wingutils.c |   21 +++++++++++++++++++++
 wing/wingutils.h |    4 ++++
 2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/wing/wingutils.c b/wing/wingutils.c
index 4d5e994..6b84933 100644
--- a/wing/wingutils.c
+++ b/wing/wingutils.c
@@ -18,6 +18,7 @@
 #include "wingutils.h"
 
 #include <windows.h>
+#include <Psapi.h>
 
 gboolean
 wing_is_wow_64 (void)
@@ -112,3 +113,23 @@ wing_get_monotonic_time (void)
 
   return g_get_monotonic_time ();
 }
+
+gboolean
+wing_get_process_memory (gsize *total_virtual_memory,
+                         gsize *total_physical_memory)
+{
+  gboolean res;
+  /* see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684879(v=vs.85).aspx */
+  PROCESS_MEMORY_COUNTERS_EX pmc;
+
+  res = GetProcessMemoryInfo (GetCurrentProcess (), (PPROCESS_MEMORY_COUNTERS) &pmc, sizeof (pmc));
+  if (res)
+    {
+      /* note: the memory shown by the task manager is usually the private working set,
+       * we are using the working set size instead */
+      *total_virtual_memory = pmc.WorkingSetSize + pmc.PagefileUsage;
+      *total_physical_memory = pmc.WorkingSetSize;
+    }
+
+  return res;
+}
diff --git a/wing/wingutils.h b/wing/wingutils.h
index 23220b0..42d54b0 100644
--- a/wing/wingutils.h
+++ b/wing/wingutils.h
@@ -36,6 +36,10 @@ gboolean     wing_get_version_number   (gint *major,
 WING_AVAILABLE_IN_ALL
 gint64       wing_get_monotonic_time   (void);
 
+WING_AVAILABLE_IN_ALL
+gboolean     wing_get_process_memory   (gsize *total_virtual_memory,
+                                        gsize *total_physical_memory);
+
 G_END_DECLS
 
 #endif /* WING_UTILS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]