DABC (Data Acquisition Backbone Core)  2.9.9
statistic.h
Go to the documentation of this file.
1 // $Id: statistic.h 4464 2020-04-15 12:14:20Z 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 #ifndef DABC_statistic
17 #define DABC_statistic
18 
19 #include <cstdio>
20 
21 #include <cstdint>
22 
23 #include <vector>
24 
25 namespace dabc {
26 
33  class CpuStatistic {
34  protected:
35 
36  struct SingleCpu {
37  unsigned long last_user, last_sys, last_idle;
39  };
40 
41  FILE *fStatFp;
42  FILE *fProcStatFp;
43  std::vector<SingleCpu> fCPUs;
44 
45  long unsigned fVmSize;
46  long unsigned fVmPeak;
47  long unsigned fNumThreads;
48 
49  public:
50  CpuStatistic(bool withmem = false);
51  virtual ~CpuStatistic();
52 
53  bool Measure();
54  bool Reset();
55 
56  unsigned NumCPUs() const { return fCPUs.size(); }
57 
58  double CPUutil(unsigned n = 0) const { return fCPUs[n].cpu_util; }
59  double UserUtil(unsigned n = 0) const { return fCPUs[n].user_util; }
60  double SysUtil(unsigned n = 0) const { return fCPUs[n].sys_util; }
61 
62  long unsigned GetVmSize() const { return fVmSize; }
63  long unsigned GetVmPeak() const { return fVmPeak; }
64  long unsigned GetNumThreads() const { return fNumThreads; }
65 
66  static long GetProcVirtMem();
67  };
68 
69  // _____________________________________________________________________________
70 
79  class Ratemeter {
80  public:
81  Ratemeter();
82  virtual ~Ratemeter();
83 
84  void DoMeasure(double interval_sec, long npoints, double firsttm = 0.);
85 
86  void Packet(int size, double tm = 0.);
87  void Reset();
88 
89  double GetRate();
90  double GetTotalTime();
91  int AverPacketSize();
92 
93  int GetNumOper() const { return numoper; }
94 
95  void SaveInFile(const char* fname);
96 
97  static void SaveRatesInFile(const char* fname, Ratemeter** rates, int nrates, bool withsum = false);
98 
99  protected:
102 
103  double fMeasureInterval; // interval between two points
105  double* fPoints;
106  };
107 
108  // ___________________________________________________________________________________
109 
118  class Average {
119  public:
120  Average();
121  virtual ~Average();
122  void AllocateHist(int nbins, double xmin, double xmax);
123  void ShowHist();
124  void Reset();
125  void Fill(double zn);
126  long Number() const { return num; }
127  double Mean() const { return num>0 ? sum1/num : 0.; }
128  double Max() const { return max; }
129  double Min() const { return min; }
130  double Dev() const;
131  void Show(const char* name, bool showextr = false);
132  protected:
133  long num;
134  double sum1;
135  double sum2;
136  double min, max;
137  long* hist; // histogram, same as in root hist[0], undeflow, hist[n+1] - overflow
138  int nhist;
139  double hist_min;
140  double hist_max;
141 
142 
143  };
144 
145 }
146 
147 
148 #endif
Helper class to calculate average value.
Definition: statistic.h:118
virtual ~Average()
Definition: statistic.cxx:311
double Mean() const
Definition: statistic.h:127
double Max() const
Definition: statistic.h:128
long Number() const
Definition: statistic.h:126
double sum2
Definition: statistic.h:135
double Min() const
Definition: statistic.h:129
double max
Definition: statistic.h:136
void ShowHist()
Definition: statistic.cxx:382
double sum1
Definition: statistic.h:134
double hist_max
Definition: statistic.h:140
double Dev() const
Definition: statistic.cxx:368
long * hist
Definition: statistic.h:137
double hist_min
Definition: statistic.h:139
double min
Definition: statistic.h:136
void Show(const char *name, bool showextr=false)
Definition: statistic.cxx:374
void Fill(double zn)
Definition: statistic.cxx:343
void AllocateHist(int nbins, double xmin, double xmax)
Definition: statistic.cxx:316
Helper class to get CPU statistic.
Definition: statistic.h:33
long unsigned GetVmSize() const
Definition: statistic.h:62
double CPUutil(unsigned n=0) const
Definition: statistic.h:58
long unsigned fVmPeak
Definition: statistic.h:46
double UserUtil(unsigned n=0) const
Definition: statistic.h:59
double SysUtil(unsigned n=0) const
Definition: statistic.h:60
long unsigned fVmSize
Definition: statistic.h:45
virtual ~CpuStatistic()
Definition: statistic.cxx:54
long unsigned fNumThreads
Definition: statistic.h:47
std::vector< SingleCpu > fCPUs
Definition: statistic.h:43
CpuStatistic(bool withmem=false)
Definition: statistic.cxx:25
long unsigned GetNumThreads() const
Definition: statistic.h:64
static long GetProcVirtMem()
Definition: statistic.cxx:151
FILE * fProcStatFp
Definition: statistic.h:42
unsigned NumCPUs() const
Definition: statistic.h:56
long unsigned GetVmPeak() const
Definition: statistic.h:63
Helper class to calculate data rate.
Definition: statistic.h:79
int64_t numoper
Definition: statistic.h:101
static void SaveRatesInFile(const char *fname, Ratemeter **rates, int nrates, bool withsum=false)
Definition: statistic.cxx:261
int AverPacketSize()
Definition: statistic.cxx:243
virtual ~Ratemeter()
Definition: statistic.cxx:185
double lastoper
Definition: statistic.h:100
double fMeasureInterval
Definition: statistic.h:103
int GetNumOper() const
Definition: statistic.h:93
double firstoper
Definition: statistic.h:100
void SaveInFile(const char *fname)
Definition: statistic.cxx:293
int64_t totalpacketsize
Definition: statistic.h:101
void DoMeasure(double interval_sec, long npoints, double firsttm=0.)
Definition: statistic.cxx:249
double GetTotalTime()
Definition: statistic.cxx:238
long fMeasurePoints
Definition: statistic.h:104
double GetRate()
Definition: statistic.cxx:229
void Packet(int size, double tm=0.)
Definition: statistic.cxx:190
double * fPoints
Definition: statistic.h:105
Event manipulation API.
Definition: api.h:23