14 using std::stringstream;
19 KTLOGGER(proflog,
"KTThroughputProfiler");
25 fOutputFileFlag(false),
26 fOutputFilename(
"throughput.json"),
69 KTINFO(proflog,
"Profiling started");
85 KTINFO(proflog,
"Profiling stopped");
88 double totalSeconds =
TimeToSec(diffTime);
89 KTPROG(proflog,
"Throughput time: " << diffTime.tv_sec <<
" sec and " << diffTime.tv_nsec <<
" nsec (" << totalSeconds <<
" sec)");
121 double KTThroughputProfiler::sTimebase = 0.0;
122 uint64_t KTThroughputProfiler::sTimestart = 0;
127 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time 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();
136 double diff = (mach_absolute_time() - sTimestart) * sTimebase;
137 time->tv_sec = diff * MACNANO;
138 time->tv_nsec = diff - (time->tv_sec * MACGIGA);
141 return clock_gettime(CLOCK_PROCESS_CPUTIME_ID, time);
148 return (
double)time.tv_sec + (double)time.tv_nsec / (
double)
NSEC_PER_SEC;
153 if ((end.tv_nsec - start.tv_nsec < 0))
155 diff->tv_sec = end.tv_sec - start.tv_sec - 1;
156 diff->tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
160 diff->tv_sec = end.tv_sec - start.tv_sec;
161 diff->tv_nsec = end.tv_nsec - start.tv_nsec;
void SetOutputFilename(const std::string &fname)
void RegisterSlot(std::string name, XTarget *target, XReturn(XTarget::*funcPtr)())
virtual ~KTThroughputProfiler()
KT_REGISTER_PROCESSOR(KTDataQueueProcessor, "data-queue")
timespec Diff(timespec start, timespec end) const
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
void Data(KTDataPtr data)
void SetOutputFileFlag(bool flag)
std::string fOutputFilename
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")