1 #include "TRestBenchMarkProcess.h"
3 #include "TRestManager.h"
4 #include "TRestProcessRunner.h"
6 #include "sys/sysinfo.h"
16 thread* TRestBenchMarkProcess::fMonitorThread =
nullptr;
17 int TRestBenchMarkProcess::fMonitorFlag = 0;
19 float TRestBenchMarkProcess::fMemUsageInMB = 0;
20 float TRestBenchMarkProcess::fReadingInMBs = 0;
21 float TRestBenchMarkProcess::fProcessSpeedInHz = 0;
22 int TRestBenchMarkProcess::fLastEventNumber = 0;
23 ULong64_t TRestBenchMarkProcess::fStartTime = 0;
25 TRestBenchMarkProcess::TRestBenchMarkProcess() { Initialize(); }
30 fCPUNumber = get_nprocs_conf();
31 fMemNumber = get_phys_pages();
35 RESTError <<
"TRestBenchMarkProcess is not available yet on MACOS!!" << RESTendl;
41 void TRestBenchMarkProcess::SysMonitorFunc(
int pid,
double refreshRate) {
42 while (fMonitorFlag == 1) {
44 auto topItems =
Split(topOutput,
" ",
false,
true);
49 fMemUsageInMB /= 1000;
50 fReadingInMBs = fHostmgr->GetProcessRunner()->GetReadingSpeed() / 1024 / 1024;
51 int Neve = fHostmgr->GetProcessRunner()->GetNProcessedEvents();
52 fProcessSpeedInHz = (Neve - fLastEventNumber) * refreshRate;
54 usleep(1e6 / refreshRate);
59 if (fHostmgr ==
nullptr || fHostmgr->GetProcessRunner() ==
nullptr) {
60 RESTError <<
"TRestBenchMarkProcess: the process is not hosted by TRestProcessRunner!" << RESTendl;
65 if (fMonitorThread ==
nullptr) {
68 fMonitorThread =
new thread(&TRestBenchMarkProcess::SysMonitorFunc,
this, fPid, fRefreshRate);
69 fMonitorThread->detach();
72 fStartTime = chrono::high_resolution_clock::now().time_since_epoch().count();
78 ULong64_t time = chrono::high_resolution_clock::now().time_since_epoch().count();
79 SetObservableValue(
"RunningTime", (time - fStartTime) / 1e9);
80 SetObservableValue(
"EventPerSecond", fProcessSpeedInHz);
81 SetObservableValue(
"ReadingSpeedMBs", fReadingInMBs);
82 SetObservableValue(
"CPUPrecentage", fCPUUsageInPct);
83 SetObservableValue(
"MemoryUsedMB", fMemUsageInMB);
89 if (fMonitorThread !=
nullptr) {
91 usleep(1e6 / fRefreshRate * 2);
93 delete fMonitorThread;
94 fMonitorThread =
nullptr;
101 RESTMetadata <<
"REST pid: " << fPid << RESTendl;
102 RESTMetadata <<
"Number of CPUs: " << fCPUNumber << RESTendl;
103 RESTMetadata <<
"Total Memory: " << round((
double)fMemNumber / 1024 / 1024 * 10) / 10 <<
" GB"
105 RESTMetadata <<
"System information refresh rate: " << fRefreshRate <<
" Hz" << RESTendl;
106 RESTMetadata <<
"Monitoring thread: " << fMonitorThread
107 <<
", status: " << (fMonitorFlag == 0 ?
"stopped" :
"running") << RESTendl;
A system performance monitor process for event flow rate, reading speed, cpu stress,...
static float fCPUUsageInPct
//0: return, 1: run
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
void Initialize() override
Making default settings.
void EndProcess() override
To be executed at the end of the run (outside event loop)
A base class for any REST event.
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.
Double_t StringToDouble(std::string in)
Gets a double from a string.
Int_t StringToInteger(std::string in)
Gets an integer from a string.