DABC (Data Acquisition Backbone Core)  2.9.9
CpuInfoModule.cxx
Go to the documentation of this file.
1 // $Id: CpuInfoModule.cxx 3862 2018-05-11 10:06:18Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #include "dabc/CpuInfoModule.h"
17 
18 dabc::CpuInfoModule::CpuInfoModule(const std::string &name, dabc::Command cmd, int kind) :
19  dabc::ModuleAsync(name, cmd),
20  fStat(true),
21  fKind(kind)
22 {
23  double period = Cfg("Period",cmd).AsDouble(2);
24  if (fKind<0) fKind = Cfg("Kind",cmd).AsInt(1 + 2);
25 
26  CreateTimer("Timer", period);
27 
28  if (fStat.NumCPUs() > 0) {
29  CreatePar("CPUutil").SetLimits(0, 100.).SetUnits("%");
30  if (fKind & 1)
31  Par("CPUutil").SetAverage(true, period);
32  }
33  if (fStat.NumCPUs() > 2) {
34  for (unsigned n=0; n < fStat.NumCPUs() - 1; n++) {
35  Parameter par = CreatePar(dabc::format("CPU%u", n)).SetLimits(0, 100.).SetUnits("%");
36  if (fKind & 4) par.SetAverage(true, period);
37  }
38  }
39 
40  CreatePar("VmSize").SetLimits(0, 16000.).SetUnits("KB");
41  Par("VmSize").SetAverage(true, period);
42 
43 // CreatePar("VmPeak").SetInt(0);
44 // CreatePar("NumThreads").SetInt(0);
45 }
46 
48 {
49  if (!fStat.Measure()) {
50  EOUT("Cannot measure CPU statistic");
51  return;
52  }
53 
54  if (fStat.NumCPUs()==0) return;
55 
56  Par("CPUutil").SetValue(fStat.CPUutil(0)*100.);
57 
58  if ((fStat.NumCPUs() > 2) && (fKind & 6))
59  for (unsigned n=0; n < fStat.NumCPUs() - 1; n++)
60  Par(dabc::format("CPU%u", n)).SetValue(fStat.CPUutil(n+1)*100.);
61 
62  Par("VmSize").SetValue((int)fStat.GetVmSize());
63 // Par("VmPeak").SetInt(fStat.GetVmPeak());
64 // Par("NumThreads").SetInt(fStat.GetNumThreads());
65 }
Represents command with its arguments.
Definition: Command.h:99
CpuStatistic fStat
Definition: CpuInfoModule.h:36
int fKind
value of "Kind" configuration parameter, mask for 0 - just show cpu info as double parameter 1 - show...
Definition: CpuInfoModule.h:44
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
CpuInfoModule(const std::string &name, dabc::Command cmd=nullptr, int kind=-1)
unsigned NumCPUs() const
Definition: statistic.h:56
Base class for user-derived code, implementing event-processing.
Definition: ModuleAsync.h:32
virtual Parameter CreatePar(const std::string &name, const std::string &kind="")
Definition: Module.cxx:129
unsigned CreateTimer(const std::string &name, double period_sec=-1., bool synchron=false)
Definition: Module.cxx:109
Parameter class
Definition: Parameter.h:163
Parameter & SetAverage(bool synchron=false, double interval=1.0)
Converts parameter in statistic variable.
Definition: Parameter.cxx:434
Parameter & SetLimits(double low, double up)
Definition: Parameter.h:270
Parameter & SetUnits(const std::string &unit)
Set units field of parameter.
Definition: Parameter.h:256
int64_t AsInt(int64_t dflt=0) const
Definition: Record.cxx:501
double AsDouble(double dflt=0.) const
Definition: Record.cxx:549
Parameter Par(const std::string &name) const
Returns reference on worker parameter object.
Definition: Worker.cxx:516
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
Definition: Worker.cxx:521
#define EOUT(args ...)
Definition: logging.h:150
Event manipulation API.
Definition: api.h:23
std::string format(const char *fmt,...)
Definition: string.cxx:49