Nymph  v1.5.2
Flow-Based Data Processing Framework
KTThroughputProfiler.cc
Go to the documentation of this file.
1 /*
2  * KTThroughputProfiler.cc
3  *
4  * Created on: Nov 30, 2012
5  * Author: nsoblath
6  */
7 
9 
10 #include <sstream>
11 
12 
13 using std::string;
14 using std::stringstream;
15 using std::vector;
16 
17 namespace Nymph
18 {
19  KTLOGGER(proflog, "KTThroughputProfiler");
20 
21  KT_REGISTER_PROCESSOR(KTThroughputProfiler, "throughput-profiler");
22 
23  KTThroughputProfiler::KTThroughputProfiler(const std::string& name) :
24  KTProcessor(name),
25  fOutputFileFlag(false),
26  fOutputFilename("throughput.json"),
27  fTimeStart(),
28  fTimeEnd(),
29  fNDataProcessed(0)
30  {
34  };
35 
37  {
38  };
39 
40  bool KTThroughputProfiler::Configure(const scarab::param_node& node)
41  {
42  SetOutputFileFlag(node.get_value< bool >("output-file-flag", fOutputFileFlag));
43  SetOutputFilename(node.get_value("output-filename-base", fOutputFilename));
44 
45  return true;
46  }
47 
49  {
51  KTDEBUG(proflog, "Start time: " << fTimeStart.tv_sec << " sec and " << fTimeStart.tv_nsec << " nsec");
52  return;
53  }
54 
56  {
58  KTDEBUG(proflog, "End time: " << fTimeEnd.tv_sec << " sec and " << fTimeEnd.tv_nsec << " nsec");
59  return;
60  }
61 
63  {
64  return Diff(fTimeStart, fTimeEnd);
65  }
66 
68  {
69  KTINFO(proflog, "Profiling started");
70  fNDataProcessed = 0;
71  Start();
72  return;
73  }
74 
76  {
77  (void)data;
79  return;
80  }
81 
83  {
84  Stop();
85  KTINFO(proflog, "Profiling stopped");
86  timespec diffTime = Elapsed();
87  KTPROG(proflog, fNDataProcessed << " slices processed");
88  double totalSeconds = TimeToSec(diffTime);
89  KTPROG(proflog, "Throughput time: " << diffTime.tv_sec << " sec and " << diffTime.tv_nsec << " nsec (" << totalSeconds << " sec)");
90 
91  // Data production rate in bytes per second
92  //double dataProductionRate = double(fEggHeader.GetNChannels()) * fEggHeader.GetAcquisitionRate() * double(fEggHeader.GetDataTypeSize());
93 
94  // Data throughput rate in bytes per second
95  //double dataThroughputRate = 0.;
96  //if (totalSeconds != 0)
97  // dataThroughputRate = double(fEggHeader.GetSliceSize() * fEggHeader.GetNChannels() * fNDataProcessed * fEggHeader.GetDataTypeSize()) / totalSeconds;
98 
99  //KTINFO(proflog, "Data production rate: " << dataProductionRate << " bytes per second");
100  //KTINFO(proflog, "Data throughput rate: " << dataThroughputRate << " bytes per second");
101  //KTPROG(proflog, "Analysis time factor: " << dataProductionRate / dataThroughputRate);
102 
103  return;
104  }
105 
107  {
108  timespec ts;
109  GetTimeCurrent(&ts);
110  return ts;
111  }
112 
113  timespec KTThroughputProfiler::Diff(timespec start, timespec end) const
114  {
115  timespec diff;
116  TimeDiff(start, end, &diff);
117  return diff;
118  }
119 
120 #ifdef __MACH__
121  double KTThroughputProfiler::sTimebase = 0.0;
122  uint64_t KTThroughputProfiler::sTimestart = 0;
123 #endif
124 
125  int KTThroughputProfiler::GetTimeCurrent(struct timespec* time)
126  {
127  #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
128  if (! sTimestart)
129  {
130  mach_timebase_info_data_t tb = { .numer = 0, .denom = 1 };
131  mach_timebase_info(&tb);
132  sTimebase = tb.numer;
133  sTimebase /= tb.denom;
134  sTimestart = mach_absolute_time();
135  }
136  double diff = (mach_absolute_time() - sTimestart) * sTimebase;
137  time->tv_sec = diff * MACNANO;
138  time->tv_nsec = diff - (time->tv_sec * MACGIGA);
139  return 0;
140  #else
141  return clock_gettime(CLOCK_PROCESS_CPUTIME_ID, time);
142  #endif
143 
144  }
145 
146  double KTThroughputProfiler::TimeToSec(struct timespec time)
147  {
148  return (double)time.tv_sec + (double)time.tv_nsec / (double)NSEC_PER_SEC;
149  }
150 
151  void KTThroughputProfiler::TimeDiff(struct timespec start, struct timespec end, struct timespec* diff)
152  {
153  if ((end.tv_nsec - start.tv_nsec < 0))
154  {
155  diff->tv_sec = end.tv_sec - start.tv_sec - 1;
156  diff->tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
157  }
158  else
159  {
160  diff->tv_sec = end.tv_sec - start.tv_sec;
161  diff->tv_nsec = end.tv_nsec - start.tv_nsec;
162  }
163  return;
164  }
165 
166 } /* namespace Nymph */
void SetOutputFilename(const std::string &fname)
#define KTINFO(...)
Definition: KTLogger.hh:344
void RegisterSlot(std::string name, XTarget *target, XReturn(XTarget::*funcPtr)())
Definition: KTProcessor.hh:96
KT_REGISTER_PROCESSOR(KTDataQueueProcessor, "data-queue")
timespec Diff(timespec start, timespec end) const
#define KTDEBUG(...)
Definition: KTLogger.hh:343
KTLOGGER(applog, "KTApplication")
void StartProfiling(KTDataPtr data)
static void TimeDiff(struct timespec start, struct timespec end, struct timespec *diff)
static double TimeToSec(struct timespec time)
boost::shared_ptr< KTData > KTDataPtr
Definition: KTData.hh:67
#define KTPROG(...)
Definition: KTLogger.hh:345
bool Configure(const scarab::param_node &node)
Should perform parameter store and command-line configurations.
static int GetTimeCurrent(struct timespec *time)
KTThroughputProfiler(const std::string &name="throughput-profiler")
#define NSEC_PER_SEC