Commit 31236796 authored by Martin Schultz's avatar Martin Schultz

refs #2421

* Added Utils namespace 
* refactor helper functions from obj plugin
* meminfo uses utils function

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20880 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e4a66d4a
......@@ -45,34 +45,9 @@
#include "MemInfo.hh"
#include <ACG/GL/gl.hh>
#include <QtGlobal>
#include <OpenFlipper/Utils/Memory/RAMInfo.hh>
// Main Memory information
#ifdef WIN32
#elif defined ARCH_DARWIN
#else
#include <sys/sysinfo.h>
//Info class returned by sysinfo
//struct sysinfo {
// long uptime; /* Sekunden seit dem letzten Systemstart */
// unsigned long loads[3]; /* 1, 5 und 15 minütige Systemlast */
// unsigned long totalram; /* nutzbare Hauptspeichergröße */
// unsigned long freeram; /* verfügbare Speichergröße */
// unsigned long sharedram; /* Größe des gemeinsamen Speichers */
// unsigned long bufferram; /* von Puffern benutzter Speicher */
// unsigned long totalswap; /* Größe des Auslagerungsspeichers */
// unsigned long freeswap; /* verfügbarer Auslagerungsspeicher */
// unsigned short procs; /* Aktuelle Prozesszahl */
// unsigned long totalhigh; /* Gesamtgröße des oberen Speicherbereichs */
// unsigned long freehigh; /* verfügbarer oberer Speicherbereich */
// unsigned int mem_unit; /* Größe der Speichereinheit in Byte */
// char _f[20-2*sizeof(long)-sizeof(int)]; /* Auffüllung auf 64 bytes */
//};
#endif
#if PROCPS_ENABLED
#include "procps/sysinfo.h"
#endif
// GPU Memory information
#define GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
......@@ -116,12 +91,12 @@ void MemInfoPlugin::pluginsInitialized() {
// emit log(LOGINFO,"Main Memory monitoring supported, installing main memory monitor into status bar");
mainMemBar_= new QProgressBar();
mainMemBar_->setFixedWidth(260);
mainMemBar_->setFormat( "Mem %p% %v/%m MB" );
emit addWidgetToStatusbar(mainMemBar_);
connect(updateTimer_,SIGNAL(timeout()),this,SLOT(cpuMemoryInfoUpdate()));
mainMemBar_->setFixedWidth(260);
mainMemBar_->setFormat( "Mem %p% %v/%m MB" );
emit addWidgetToStatusbar(mainMemBar_);
connect(updateTimer_,SIGNAL(timeout()),this,SLOT(cpuMemoryInfoUpdate()));
updateTimer_->start(4000);
......@@ -153,57 +128,25 @@ void MemInfoPlugin::nvidiaMemoryInfoUpdate() {
// get currently available memory on gpu
GLint cur_avail_mem_kb = 0;
glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &cur_avail_mem_kb);
gpuMemBar_->setRange( 0 , total_mem_kb/1024 );
gpuMemBar_->setValue( (total_mem_kb-cur_avail_mem_kb)/1024);
setProgressBarStyleSheet(gpuMemBar_);
}
}
void MemInfoPlugin::cpuMemoryInfoUpdate() {
if (mainMemBar_) {
unsigned long totalRamMB = 0;
unsigned long freeRamMB = 0;
unsigned long bufferRamMB = 0;
// Main Memory information
#ifdef WIN32 //Windows
// Define memory structure
MEMORYSTATUSEX ms;
// Set the size ( required according to spec ... why???? )
ms.dwLength = sizeof (ms);
// Get the info
GlobalMemoryStatusEx(&ms);
totalRamMB = ms.ullTotalPhys/1024/1024;
freeRamMB = ms.ullAvailPhys/1024/1024;
#elif defined ARCH_DARWIN // Apple
#elif PROCPS_ENABLED
meminfo();
totalRamMB = kb_main_total / 1024;
freeRamMB = kb_main_free / 1024;
bufferRamMB = (kb_main_buffers + kb_main_cached) / 1024;
#else // Linux
gpuMemBar_->setRange( 0 , total_mem_kb/1024 );
gpuMemBar_->setValue( (total_mem_kb-cur_avail_mem_kb)/1024);
setProgressBarStyleSheet(gpuMemBar_);
}
}
struct sysinfo sys_info;
sysinfo(&sys_info);
void MemInfoPlugin::cpuMemoryInfoUpdate() {
if (mainMemBar_) {
Utils::Memory::MemoryVacancy vac;
Utils::Memory::MemoryInfoUpdate(vac);
// Unit in bytes ; /1024 -> KB ; /1024 MB
totalRamMB = sys_info.totalram / 1024 / 1024 * sys_info.mem_unit;
freeRamMB = sys_info.freeram / 1024 / 1024 * sys_info.mem_unit;
bufferRamMB = sys_info.bufferram / 1024 / 1024 * sys_info.mem_unit; // Buffers get freed, if we don't have enough free ram
#endif
mainMemBar_->setRange( 0 , totalRamMB );
mainMemBar_->setValue( totalRamMB-freeRamMB-bufferRamMB);
setProgressBarStyleSheet(mainMemBar_);
}
}
mainMemBar_->setRange( 0 , vac.totalRamMB );
mainMemBar_->setValue( vac.totalRamMB-vac.freeRamMB-vac.bufferRamMB);
setProgressBarStyleSheet(mainMemBar_);
}
}
void MemInfoPlugin::setProgressBarStyleSheet(QProgressBar* _bar)
......@@ -221,7 +164,7 @@ void MemInfoPlugin::setProgressBarStyleSheet(QProgressBar* _bar)
const quint32 color = (red<<16)+(green<<8)+blue;
_bar->setStyleSheet(QString(" QProgressBar { border: 2px solid grey; border-radius: 2px; text-align: center; } QProgressBar::chunk {background-color: #%1; width: 1px;}").arg(color,6,16,QChar('0')));
}
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( meminfoplugin , MemInfoPlugin );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment