Commit 3f8e505d authored by Jan Möbius's avatar Jan Möbius

New memory info plugin added



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17831 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
include (plugin)
openflipper_plugin ()
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 17080 $ *
* $LastChangedBy: moeller $ *
* $Date: 2013-07-19 12:58:31 +0200 (Fr, 19. Jul 2013) $ *
* *
\*===========================================================================*/
#include "MemInfo.hh"
#include <ACG/GL/gl.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
#define GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
void MemInfoPlugin::initializePlugin()
{
}
void MemInfoPlugin::pluginsInitialized() {
// Check extension for NVIDIA memory information
QString glExtensions = QString((const char*)glGetString(GL_EXTENSIONS));
updateTimer_ = new QTimer();
updateTimer_->setSingleShot(false);
// NVIDIA cards
if ( glExtensions.contains("GL_NVX_gpu_memory_info") ) {
//emit log(LOGINFO,"NVIDIA card Memory info supported, installing gpu memory monitor into status bar");
gpuMemBar_= new QProgressBar();
gpuMemBar_->setFixedWidth(260);
gpuMemBar_->setFormat( "GPU Mem %p% %v/%m MB" );
emit addWidgetToStatusbar(gpuMemBar_);
connect(updateTimer_,SIGNAL(timeout()),this,SLOT(nvidiaMemoryInfoUpdate()));
updateTimer_->start(4000);
nvidiaMemoryInfoUpdate();
}
// Main Memory information
#ifdef WIN32 //Windows
#elif defined ARCH_DARWIN // Apple
#else // Linux
//emit log(LOGINFO,"Linux 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()));
updateTimer_->start(4000);
cpuMemoryInfoUpdate();
#endif
}
MemInfoPlugin::~MemInfoPlugin() {
delete(updateTimer_);
}
void MemInfoPlugin::nvidiaMemoryInfoUpdate() {
if (gpuMemBar_) {
// get total memory on gpu
GLint total_mem_kb = 0;
glGetIntegerv(GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &total_mem_kb);
// 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);
}
}
void MemInfoPlugin::cpuMemoryInfoUpdate() {
if (mainMemBar_) {
struct sysinfo sys_info;
sysinfo(&sys_info);
// Unit in bytes ; /1024 -> KB ; /1024 MB
unsigned long totalRamMB = sys_info.totalram / 1024 /1024 * sys_info.mem_unit;
// Unit in bytes ; /1024 -> KB ; /1024 MB
unsigned long freeRamMB = sys_info.freeram / 1024 / 1024 * sys_info.mem_unit;
mainMemBar_->setRange( 0 , totalRamMB );
mainMemBar_->setValue( totalRamMB-freeRamMB);
}
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( meminfoplugin , MemInfoPlugin );
#endif
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 17080 $ *
* $LastChangedBy: moeller $ *
* $Date: 2013-07-19 12:58:31 +0200 (Fr, 19. Jul 2013) $ *
* *
\*===========================================================================*/
#pragma once
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
class MemInfoPlugin: public QObject, BaseInterface, LoggingInterface, StatusbarInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(StatusbarInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MemInfo")
#endif
signals:
// LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
// StatusbarInterface
void addWidgetToStatusbar(QWidget* _widget);
public:
~MemInfoPlugin();
// BaseInterface
QString name() { return (QString("MemInfo")); } ;
QString description() { return (QString("Plugin used to display current GPU/CPU Memory Status")); } ;
private slots:
/// BaseInterface
void initializePlugin();
void pluginsInitialized();
/// Update statusbar with NVIDIA memory infos
void nvidiaMemoryInfoUpdate();
/// Update statusbar with main memory infos
void cpuMemoryInfoUpdate();
private:
/// Status bar for GPU memory
QProgressBar* gpuMemBar_;
/// Status bar for Main memory
QProgressBar* mainMemBar_;
/// Timer that triggers an update of the bars
QTimer* updateTimer_;
public slots:
QString version() { return QString("1.0"); };
};
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