DABC (Data Acquisition Backbone Core)  2.9.9
Profiler.cxx
Go to the documentation of this file.
1 // $Id: Profiler.cxx 4110 2018-10-02 07:23:43Z 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/Profiler.h"
17 
19 {
20 
21  clock_t now = GetClock();
22 
23  clock_t diff = fLast ? now - fLast : 0;
24 
25  if (diff) {
26  for (auto &&entry : fEntries) {
27  entry.fRatio = 1.*entry.fSum/diff;
28  entry.fSum = 0;
29  }
30  }
31 
32  fLast = now;
33 }
34 
35 
37 {
38  std::string res;
39 
40  double total{0.};
41  int cnt{0};
42 
43  for (auto &&entry : fEntries) {
44  if (entry.fRatio > 0) {
45  if (!res.empty()) res.append(" ");
46  total += entry.fRatio;
47  if (entry.fName.empty())
48  res.append(std::to_string(cnt));
49  else
50  res.append(entry.fName);
51  res.append(":");
52  res.append(std::to_string((int)(entry.fRatio*1000)));
53  }
54  cnt++;
55  }
56 
57  if (total){
58  res.append(" total:");
59  res.append(std::to_string((int)(total*1000)));
60  }
61 
62  return res;
63 }
clock_t GetClock()
Definition: Profiler.h:37
clock_t fLast
Definition: Profiler.h:39
unsigned long long clock_t
Definition: Profiler.h:33
std::vector< Entry > fEntries
Definition: Profiler.h:47
std::string Format()
Definition: Profiler.cxx:36
void MakeStatistic()
Definition: Profiler.cxx:18