Resource Tracking for FlightGear: Difference between revisions

Jump to navigation Jump to search
m
m (correction: GL_NVX_gpu_memory_info)
Line 341: Line 341:
     ////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////
     // Add the performance monitoring system.
     // Add the performance monitoring system.
diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx
index d41e00d..c6120f3 100644
--- a/src/Main/globals.cxx
+++ b/src/Main/globals.cxx
@@ -504,6 +504,7 @@ FGGlobals::add_subsystem (const char * name,
                          double min_time_sec)
{
    subsystem_mgr->add(name, subsystem, type, min_time_sec);
+    //snapshot()
}
SGSoundMgr *
diff --git a/src/Main/ram_usage.cxx b/src/Main/ram_usage.cxx
diff --git a/src/Main/ram_usage.cxx b/src/Main/ram_usage.cxx
new file mode 100644
new file mode 100644
index 0000000..a84ea7c
index 0000000..9c809c4
--- /dev/null
--- /dev/null
+++ b/src/Main/ram_usage.cxx
+++ b/src/Main/ram_usage.cxx
Line 350: Line 362:
+
+
+MemoryUsageStats::MemoryUsageStats() {
+MemoryUsageStats::MemoryUsageStats() {
+ _mem = new LinuxMemoryInterface(); //FIXME: should be implemented for Win/Mac & Linux
+ _mem = new LinuxMemoryInterface(); //FIXME: should be implemented for Win/Mac & Linux (use SIGAR)
+}
+}
+
+
Line 360: Line 372:
+MemoryUsageStats::update(double dt) {
+MemoryUsageStats::update(double dt) {
+  _mem->update();
+  _mem->update();
+  int vram = _mem->getVRAMUsageInKB(); // vram stuff
+  int vram = _mem->getVRAMUsageInKB(); // vram tracking stuff
double swap = _mem->getSwapSize();
int swap = _mem->getSwapSize();
double total = _mem->getTotalSize();
int total = _mem->getTotalSize();
+  SG_LOG(SG_GENERAL, SG_DEBUG, "Updating Memory Stats:" << total << " kb");
+  SG_LOG(SG_GENERAL, SG_DEBUG, "Updating Memory Stats:" << total << " kb");
+  fgSetInt("/memory-usage/swap-usage-kb",  swap );
+  fgSetInt("/memory-usage/swap-usage-kb",  swap );
+  fgSetInt("/memory-usage/total-usage-kb", total );
+  fgSetInt("/memory-usage/total-usage-kb", total );
+  fgSetInt("/memory-usage/vram-usage-kb", vram );
+  fgSetInt("/memory-usage/vram-available-kb", vram );
+   
+   
+}
+}
Line 374: Line 386:
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..cef9cc2
index 0000000..1f492e2
--- /dev/null
--- /dev/null
+++ b/src/Main/ram_usage.hxx
+++ b/src/Main/ram_usage.hxx
@@ -0,0 +1,142 @@
@@ -0,0 +1,178 @@
+#ifndef __RAM_USAGE
+#ifndef __RAM_USAGE
+#define __RAM_USAGE
+#define __RAM_USAGE
Line 389: Line 401:
+#include<GL/glu.h>
+#include<GL/glu.h>
+
+
+
+// http://wiki.flightgear.org/Howto:Use_Property_Tree_Objects
+#include <simgear/props/propertyObject.hxx>
+
+
+#include <simgear/timing/timestamp.hxx>
+#include <simgear/timing/timestamp.hxx>
Line 400: Line 415:
+
+
+using std::map;
+using std::map;
+
+
+// https://github.com/OpenGLInsights/OpenGLInsightsCode/blob/master/Chapter%2038%20Monitoring%20Graphics%20Memory%20Usage/Ch38AMD/Ch38AMD/Ch38AMDDlg.cpp
+#ifndef GL_VBO_FREE_MEMORY_ATI
+
+ #define GL_VBO_FREE_MEMORY_ATI 0x87FB
+ #define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC
+ #define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD
+
+#endif
+
+
+// http://www.geeks3d.com/20100531/programming-tips-how-to-know-the-graphics-memory-size-and-usage-in-opengl/
+// http://www.geeks3d.com/20100531/programming-tips-how-to-know-the-graphics-memory-size-and-usage-in-opengl/
Line 411: Line 436:
+    private:
+    private:
+    protected:
+    protected:
+    GLint total_mem_kb;
+    GLint cur_avail_mem_kb;
+    simgear::PropertyObject<int> *total_vram_kb,*available_vram_kb, *used_vram_kb;
+    public:
+    public:
+    virtual ~GPUInfo() {};
+    GPUInfo(): total_mem_kb(-1), cur_avail_mem_kb(-1) {
+ total_vram_kb = new simgear::PropertyObject<int>("/stas/vram/total-size-kb");
+ available_vram_kb =  new simgear::PropertyObject<int>("/stats/vram/available-kb");
+ used_vram_kb =  new simgear::PropertyObject<int>("/stats/vram/used-kb");
+ }
+    virtual ~GPUInfo() {
+ delete total_vram_kb;
+ delete available_vram_kb;
+ delete used_vram_kb;
+ };
+    virtual int getVRAMUsageInKB() = 0;
+    virtual int getVRAMUsageInKB() = 0;
+    };
+    };
Line 420: Line 457:
+    class NVIDIA_GPU: public GPUInfo {
+    class NVIDIA_GPU: public GPUInfo {
+    public:
+    public:
+    NVIDIA_GPU() {
+    // determine total memory and store it (this wont change at runtime, so only do it once)
+    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");
+    *total_vram_kb = total_mem_kb;
+    }
+    virtual int getVRAMUsageInKB() {
+    virtual int getVRAMUsageInKB() {
+    GLint total_mem_kb = 0;
+    glGetIntegerv(GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX, &cur_avail_mem_kb);
+    glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX,
+              &total_mem_kb);
+
+    GLint cur_avail_mem_kb = 0;
+    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) and used:"<<cur_avail_mem_kb);
+    SG_LOG(SG_GENERAL, SG_ALERT,"NVIDIA VRAM tracking function says:"<<total_mem_kb<<" (total) available:"<<cur_avail_mem_kb);
+    *available_vram_kb = cur_avail_mem_kb;
+    *used_vram_kb = *total_vram_kb - *available_vram_kb;
+    return cur_avail_mem_kb;
+    return cur_avail_mem_kb;
+    }
+    }
Line 437: Line 476:
+    class ATI_GPU: public GPUInfo {
+    class ATI_GPU: public GPUInfo {
+    public:
+    public:
+    // ATI_GPU()
+    // https://github.com/OpenGLInsights/OpenGLInsightsCode/blob/master/Chapter%2038%20Monitoring%20Graphics%20Memory%20Usage/Ch38AMD/Ch38AMD/Ch38AMDDlg.cpp#L280
+    virtual int getVRAMUsageInKB() {
+    virtual int getVRAMUsageInKB() {
+    SG_LOG(SG_GENERAL, SG_ALERT,"ATI VRAM tracking function not yet implemented !");
+    SG_LOG(SG_GENERAL, SG_ALERT,"Sorry:ATI VRAM tracking function not yet implemented (nvidia only)!");
+    return 200;
+    return -1;
+    }
+    }
+  
+  
Line 447: Line 488:
+    public:
+    public:
+    virtual int getVRAMUsageInKB() {
+    virtual int getVRAMUsageInKB() {
+    SG_LOG(SG_GENERAL, SG_ALERT,"Intel VRAM tracking function not yet implemented !");
+    SG_LOG(SG_GENERAL, SG_ALERT,"Sorry:Intel VRAM tracking function not yet implemented (nvidia only)!");
+    return 500;
+    return -1;
+    }
+    }
+  
+  
Line 462: Line 503:
+ };
+ };
+ MemoryInterface() {
+ MemoryInterface() {
+ // get the string
+    std::string fallback = "NVIDIA"; //default value
+    std::string fallback = "NVIDIA"; //default value
+  
+  
Line 474: Line 514:
+    std::size_t found = glvendor.find("NVIDIA");
+    std::size_t found = glvendor.find("NVIDIA");
+      if (found!=std::string::npos) {
+      if (found!=std::string::npos) {
+      SG_LOG(SG_GENERAL, SG_ALERT, "Supported GPU found: NVIDIA");
+      _gpu = new NVIDIA_GPU;
+      _gpu = new NVIDIA_GPU;
+    }
+    }
+
+   else if (glvendor.find("INTEL") != std::string::npos) {
+ // else if ATI/AMD ...
+    _gpu = new INTEL_GPU;
+    // else if INTEL ...
+ }
+    else if (glvendor.find("ATI") != std::string::npos) {
+    _gpu = new ATI_GPU;
+ }
+    else {
+    else {
+    SG_LOG(SG_GENERAL, SG_ALERT, "Unsupported GPU vendor:" << glvendor);
+    SG_LOG(SG_GENERAL, SG_ALERT, "VRAM Tracking: Unsupported GPU vendor:" << glvendor);
+    }
+    }
+
+
+
+   if(_gpu)
+      SG_LOG(SG_GENERAL, SG_ALERT, "VRAM Tracking: Supported GPU found:"<< glvendor);
+}
+}
+ typedef map<const char*, double> RamMap;
+ typedef map<const char*, double> RamMap;
Line 490: Line 533:
+ virtual void update() = 0;
+ virtual void update() = 0;
+
+
+ int getVRAMUsageInKB() const {return _gpu->getVRAMUsageInKB();}
+ int getVRAMUsageInKB() const {
+if (_gpu)
+return _gpu->getVRAMUsageInKB();
+
+return -1; // VRAM tracking not supported, so return -1
+}
+
+
+ double getTotalSize() const {return _total_size;}
+ double getTotalSize() const {return _total_size;}
Line 503: Line 551:
+ GPUInfo* _gpu;
+ GPUInfo* _gpu;
+
+
+ double _total_size;
+ int _total_size;
+ double _swap_size;
+ int _swap_size;
+};
+};
+
+
Line 522: Line 570:
diff --git a/src/Main/ram_usage_linux.cxx b/src/Main/ram_usage_linux.cxx
diff --git a/src/Main/ram_usage_linux.cxx b/src/Main/ram_usage_linux.cxx
new file mode 100644
new file mode 100644
index 0000000..bb214a8
index 0000000..ffc48ce
--- /dev/null
--- /dev/null
+++ b/src/Main/ram_usage_linux.cxx
+++ b/src/Main/ram_usage_linux.cxx
Line 559: Line 607:
+ if (!file) throw("MemoryTracker: ProcFile not open");
+ if (!file) throw("MemoryTracker: ProcFile not open");
+
+
+  // reset our counters
+  _total_size = 0;
+  _total_size = 0;
+  _swap_size = 0;  
+  _swap_size = 0;  
+
+
+  char line[1024];
+  while (fgets(line, sizeof line, file))
+  while (fgets(line, sizeof line, file))
+    {
+    {
Line 577: Line 625:
diff --git a/src/Main/ram_usage_linux.hxx b/src/Main/ram_usage_linux.hxx
diff --git a/src/Main/ram_usage_linux.hxx b/src/Main/ram_usage_linux.hxx
new file mode 100644
new file mode 100644
index 0000000..59b7134
index 0000000..a6d2033
--- /dev/null
--- /dev/null
+++ b/src/Main/ram_usage_linux.hxx
+++ b/src/Main/ram_usage_linux.hxx
@@ -0,0 +1,22 @@
@@ -0,0 +1,23 @@
+#ifndef __RAM_USAGE_LINUX
+#ifndef __RAM_USAGE_LINUX
+#define __RAM_USAGE_LINUX
+#define __RAM_USAGE_LINUX
Line 596: Line 644:
+ virtual void update();
+ virtual void update();
+private:
+private:
+ char line[1024];
+ void OpenProcFile();
+ void OpenProcFile();
+ const char* filename;
+ const char* filename;
Line 602: Line 651:
+
+
+
+
+#endif</syntaxhighlight>
+#endif
 
</syntaxhighlight>


[[Category:Core development projects]]
[[Category:Core development projects]]

Navigation menu