Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
CPUMeter.C File Reference

Detailed Description

Simple macro showing capabilities of the TGSpeedo widget.

#include "TSystem.h"
#include "TGFrame.h"
#include "TGWindow.h"
#include "TGSpeedo.h"
#include "TVirtualX.h"
class TGShapedMain : public TGMainFrame {
protected:
const TGPicture *fBgnd; // picture used as mask
TGSpeedo *fSpeedo; // analog meter
TTimer *fTimer; // update timer
Int_t fActInfo; // actual information value
public:
TGShapedMain(const TGWindow *p, int w, int h);
virtual ~TGShapedMain();
void CloseWindow();
TGSpeedo *GetSpeedo() const { return fSpeedo; }
Int_t GetActInfo() const { return fActInfo; }
void ToggleInfos();
};
// globals
//______________________________________________________________________________
TGShapedMain::TGShapedMain(const TGWindow *p, int w, int h) : TGMainFrame(p, w, h)
{
// Constructor.
fActInfo = 1;
fSpeedo = new TGSpeedo(this, 0.0, 100.0, "CPU", "[%]");
fSpeedo->Connect("OdoClicked()", "TGShapedMain", this, "ToggleInfos()");
fSpeedo->Connect("LedClicked()", "TGShapedMain", this, "CloseWindow()");
Connect("CloseWindow()", "TGShapedMain", this, "CloseWindow()");
AddFrame(fSpeedo, new TGLayoutHints(kLHintsCenterX | kLHintsCenterX));
fSpeedo->SetDisplayText("Used RAM", "[MB]");
fTimer = new TTimer(100);
fTimer->SetCommand("Update()");
fBgnd = fSpeedo->GetPicture();
if (fBgnd) {
gVirtualX->ShapeCombineMask(GetId(), 0, 0, fBgnd->GetMask());
SetBackgroundPixmap(fBgnd->GetPicture());
SetWMSizeHints(fBgnd->GetWidth(), fBgnd->GetHeight(), fBgnd->GetWidth(), fBgnd->GetHeight(), 1, 1);
}
MapWindow();
// To avoid closing the window while TGSpeedo is drawing
DontCallClose();
// To avoid closing the window while TGSpeedo is drawing
Resize(GetDefaultSize());
// Set fixed size
SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), GetDefaultWidth(), GetDefaultHeight(), 1, 1);
SetWindowName("ROOT CPU Load Meter");
fTimer->TurnOn();
}
//______________________________________________________________________________
void TGShapedMain::ToggleInfos()
{
// Toggle information displayed in Analog Meter
if (fActInfo < 2)
else
fActInfo = 0;
if (fActInfo == 0)
fSpeedo->SetDisplayText("Total RAM", "[MB]");
else if (fActInfo == 1)
fSpeedo->SetDisplayText("Used RAM", "[MB]");
else if (fActInfo == 2)
fSpeedo->SetDisplayText("Free RAM", "[MB]");
}
//______________________________________________________________________________
TGShapedMain::~TGShapedMain()
{
// Destructor.
delete fTimer;
delete fSpeedo;
}
//______________________________________________________________________________
void TGShapedMain::CloseWindow()
{
// Close Window.
if (fTimer)
fTimer->TurnOff();
DestroyWindow();
}
void Update()
{
// Get CPU information
// actual CPU load
act_load = cpuInfo.fTotal;
// Get Memory information
// choose which value to display
if (gMainWindow->GetActInfo() == 0)
memUsage = memInfo.fMemTotal;
else if (gMainWindow->GetActInfo() == 1)
memUsage = memInfo.fMemUsed;
else if (gMainWindow->GetActInfo() == 2)
memUsage = memInfo.fMemFree;
// small threshold to avoid "trembling" needle
if (fabs(act_load - prev_load) > 0.9) {
gSpeedo->SetScaleValue(act_load, 10);
}
// update only if value has changed
gSpeedo->SetOdoValue(memUsage);
}
}
//______________________________________________________________________________
void CPUMeter()
{
// Main application.
gMainWindow = new TGShapedMain(gClient->GetRoot(), 500, 200);
gSpeedo = gMainWindow->GetSpeedo();
// set threshold values
gSpeedo->SetThresholds(12.5, 50.0, 87.5);
// set threshold colors
// enable threshold
gSpeedo->EnableThreshold();
gSpeedo->SetScaleValue(0.0, 5);
// enable peak marker
gSpeedo->EnablePeakMark();
}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
#define ClassDef(name, id)
Definition Rtypes.h:342
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
@ kLHintsCenterX
Definition TGLayout.h:25
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gVirtualX
Definition TVirtualX.h:337
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:399
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
TGSpeedo is a widget looking like a speedometer, with a needle, a counter and a small odometer window...
Definition TGSpeedo.h:22
@ kOrange
Definition TGSpeedo.h:25
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
Definition TSystem.cxx:2490
virtual int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
Definition TSystem.cxx:2480
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Author
Bertrand Bellenot

Definition in file CPUMeter.C.