Nymph  v1.5.2
Flow-Based Data Processing Framework
KTThroughputProfiler.hh
Go to the documentation of this file.
1 /*
2  * KTKTThroughputProfiler.hh
3  *
4  * Created on: Nov 30, 2012
5  * Author: nsoblath
6  *
7  * Portability for Mac OS X:
8  * Author: Jens Gustedt
9  * URL: http://stackoverflow.com/a/5167506
10  */
11 
12 #ifndef KTTHROUGHPUTPROFILER_HH_
13 #define KTTHROUGHPUTPROFILER_HH_
14 
15 #include "KTProcessor.hh"
16 
17 #include "KTData.hh"
18 
19 #include <string>
20 #include <sys/time.h>
21 #include <time.h>
22 
23 #ifndef NSEC_PER_SEC
24 #define NSEC_PER_SEC 1000000000
25 #endif
26 
27 #ifndef SEC_PER_NSEC
28 #define SEC_PER_NSEC 1.e-9
29 #endif
30 
31 #ifdef __MACH__
32 #include <mach/mach_time.h>
33 
34 #ifndef MACNANO
35 #define MACNANO (+1.0E-9)
36 #define MACGIGA UINT64_C(1000000000)
37 #endif // MACNANO
38 #endif // __MACH__
39 
40 namespace Nymph
41 {
78  {
79 
80  public:
81  KTThroughputProfiler(const std::string& name = "throughput-profiler");
82  virtual ~KTThroughputProfiler();
83 
84  bool Configure(const scarab::param_node& node);
85 
86  void Start();
87  void Stop();
88 
89  void StartProfiling(KTDataPtr data);
90 
91  void Data(KTDataPtr data);
92 
93  void Finish();
94 
95  timespec Elapsed();
96 
97  bool GetOutputFileFlag() const;
98  void SetOutputFileFlag(bool flag);
99 
100  const std::string& GetOutputFilename() const;
101  void SetOutputFilename(const std::string& fname);
102 
103  private:
104  timespec CurrentTime();
105  timespec Diff(timespec start, timespec end) const;
106 
108  std::string fOutputFilename;
109 
110  timespec fTimeStart;
111  timespec fTimeEnd;
112 
113  unsigned fNDataProcessed;
114 
115  static int GetTimeCurrent(struct timespec* time);
116  static double TimeToSec(struct timespec time);
117  static void TimeDiff(struct timespec start, struct timespec end, struct timespec* diff);
118 #ifdef __MACH__
119  static double sTimebase;
120  static uint64_t sTimestart;
121 #endif
122 
123 
124  };
125 
127  {
128  return fOutputFileFlag;
129  }
130 
132  {
133  fOutputFileFlag = flag;
134  return;
135  }
136 
137  inline const std::string& KTThroughputProfiler::GetOutputFilename() const
138  {
139  return fOutputFilename;
140  }
141 
142  inline void KTThroughputProfiler::SetOutputFilename(const std::string& fname)
143  {
144  fOutputFilename = fname;
145  return;
146  }
147 
148 } /* namespace Nymph */
149 #endif /* KTTHROUGHPUTPROFILER_HH_ */
void SetOutputFilename(const std::string &fname)
Measures the speed of data processing.
Contains KTProcessor.
timespec Diff(timespec start, timespec end) const
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
bool Configure(const scarab::param_node &node)
Should perform parameter store and command-line configurations.
static int GetTimeCurrent(struct timespec *time)
const std::string & GetOutputFilename() const
KTThroughputProfiler(const std::string &name="throughput-profiler")