1#include "TRestBenchMarkProcess.h"
3#include "TRestManager.h"
4#include "TRestProcessRunner.h"
6#include "sys/sysinfo.h"
16thread* TRestBenchMarkProcess::fMonitorThread =
nullptr;
17int TRestBenchMarkProcess::fMonitorFlag = 0;
19float TRestBenchMarkProcess::fMemUsageInMB = 0;
20float TRestBenchMarkProcess::fReadingInMBs = 0;
21float TRestBenchMarkProcess::fProcessSpeedInHz = 0;
22int TRestBenchMarkProcess::fLastEventNumber = 0;
23ULong64_t TRestBenchMarkProcess::fStartTime = 0;
25TRestBenchMarkProcess::TRestBenchMarkProcess() {
Initialize(); }
30 fCPUNumber = get_nprocs_conf();
31 fMemNumber = get_phys_pages();
35 RESTError <<
"TRestBenchMarkProcess is not available yet on MACOS!!" <<
RESTendl;
41void 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);
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();
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)
void BeginPrintProcess()
[name, cut range]
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
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.