Resource Tracking for FlightGear: Difference between revisions

Jump to navigation Jump to search
m
No edit summary
Line 275: Line 275:


Here's a first stab at a simple subsystem to monitor FlightGear memory usage on Linux at 5 second intervals, consider it a "proof of concept" prototype now, as this would need to be cleaned up and implemented for Mac/Windows respectively - on Linux it simply works such that it merely fopen()s /proc/pid/smaps and copies two metrics to the property tree:
Here's a first stab at a simple subsystem to monitor FlightGear memory usage on Linux at 5 second intervals, consider it a "proof of concept" prototype now, as this would need to be cleaned up and implemented for Mac/Windows respectively - on Linux it simply works such that it merely fopen()s /proc/pid/smaps and copies two metrics to the property tree:
<syntaxhighlight lang="diff">diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt
<syntaxhighlight lang="diff">
diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt
index 4b6926e..31d3a8f 100644
index 4b6926e..31d3a8f 100644
--- a/src/Main/CMakeLists.txt
--- a/src/Main/CMakeLists.txt
Line 387: Line 388:
diff --git a/src/Main/ram_usage.hxx b/src/Main/ram_usage.hxx
diff --git a/src/Main/ram_usage.hxx b/src/Main/ram_usage.hxx
new file mode 100644
new file mode 100644
index 0000000..63db270
index 0000000..a1540c1
--- /dev/null
--- /dev/null
+++ b/src/Main/ram_usage.hxx
+++ b/src/Main/ram_usage.hxx
@@ -0,0 +1,177 @@
@@ -0,0 +1,175 @@
+#ifndef __RAM_USAGE
+#ifndef __RAM_USAGE
+#define __RAM_USAGE
+#define __RAM_USAGE
Line 439: Line 440:
+    GLint total_mem_kb;
+    GLint total_mem_kb;
+    GLint cur_avail_mem_kb;
+    GLint cur_avail_mem_kb;
+    simgear::PropertyObject<int> *total_vram_kb,*available_vram_kb, *used_vram_kb;
+    simgear::PropertyObject<int> total_vram_kb,available_vram_kb, used_vram_kb;
+    public:
+    public:
+    GPUInfo(): total_mem_kb(-1), cur_avail_mem_kb(-1) {
+    GPUInfo(): total_mem_kb(-1),  
+ total_vram_kb = new simgear::PropertyObject<int>("/stats/vram/total-size-kb");
+ cur_avail_mem_kb(-1),
+ available_vram_kb =  new simgear::PropertyObject<int>("/stats/vram/available-kb");
+ total_vram_kb("/stats/vram/total-size-kb"),
+ used_vram_kb =  new simgear::PropertyObject<int>("/stats/vram/used-kb");
+ available_vram_kb ("/stats/vram/available-kb"),
+ }
+ used_vram_kb ("/stats/vram/used-kb") { }
+    virtual ~GPUInfo() {
+    virtual ~GPUInfo() {
+ delete total_vram_kb;
+ delete available_vram_kb;
+ delete used_vram_kb;
+ };
+ };
+    virtual void updateVRAMStats() {};
+    virtual void updateVRAMStats() {};
Line 462: Line 460:
+    glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX, &total_mem_kb);
+    glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX, &total_mem_kb);
+    SG_LOG(SG_GENERAL, SG_DEBUG, "NVIDIA GPU with total memory: " << total_mem_kb << " kbytes");
+    SG_LOG(SG_GENERAL, SG_DEBUG, "NVIDIA GPU with total memory: " << total_mem_kb << " kbytes");
+    *total_vram_kb = total_mem_kb;  
+    total_vram_kb = total_mem_kb;  
+    }
+    }
+    virtual void updateVRAMStats() {
+    virtual void updateVRAMStats() {
+    glGetIntegerv(GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX, &cur_avail_mem_kb);
+    glGetIntegerv(GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX, &cur_avail_mem_kb);
+
+
+    SG_LOG(SG_GENERAL, SG_ALERT,"NVIDIA VRAM tracking function says:"<<total_mem_kb<<" (total) available:"<<cur_avail_mem_kb);
+    SG_LOG(SG_GENERAL, SG_DEBUG,"NVIDIA VRAM tracking function says:"<<total_mem_kb<<" (total) available:"<<cur_avail_mem_kb);
+    *available_vram_kb = cur_avail_mem_kb;
+    // update property objects
+    *used_vram_kb = *total_vram_kb - *available_vram_kb;
+    available_vram_kb = cur_avail_mem_kb;
+    used_vram_kb = total_vram_kb - available_vram_kb;
+    }
+    }
+  
+  
Line 480: Line 479:
+    virtual void updateVRAMStats() {
+    virtual void updateVRAMStats() {
+    SG_LOG(SG_GENERAL, SG_ALERT,"Sorry:ATI VRAM tracking function not yet implemented (nvidia only)!");
+    SG_LOG(SG_GENERAL, SG_ALERT,"Sorry:ATI VRAM tracking function not yet implemented (nvidia only)!");
+    *used_vram_kb = *total_vram_kb = *available_vram_kb = -1;
+    used_vram_kb = total_vram_kb = available_vram_kb = -1;
+    }
+    }
+  
+  
Line 489: Line 488:
+    virtual void updateVRAMStat() {
+    virtual void updateVRAMStat() {
+    SG_LOG(SG_GENERAL, SG_ALERT,"Sorry:Intel VRAM tracking function not yet implemented (nvidia only)!");
+    SG_LOG(SG_GENERAL, SG_ALERT,"Sorry:Intel VRAM tracking function not yet implemented (nvidia only)!");
+    *used_vram_kb = *total_vram_kb = *available_vram_kb = -1;
+    used_vram_kb = total_vram_kb = available_vram_kb = -1;
+    }
+    }
+  
+  

Navigation menu