34#ifndef I_BESStopWatch_h
35#define I_BESStopWatch_h 1
38#include <sys/resource.h>
44#include <BESDataHandlerInterface.h>
45#include <BESDataNames.h>
50#define COMMAND_TIMING 1
52static const std::string TIMING_LOG_KEY =
"timing";
53static const std::string MISSING_LOG_PARAM;
62#define BES_STOPWATCH_START(module, message) \
63BESStopWatch besTimer; \
64if (BESISDEBUG((module)) || BESISDEBUG(TIMING_LOG_KEY) || BESLog::TheLog()->is_verbose()) \
65 besTimer.start((message))
67#define BES_STOPWATCH_START_DHI(module, message, DHI) \
68BESStopWatch besTimer; \
69if (BESISDEBUG((module)) || BESISDEBUG(TIMING_LOG_KEY) || BESLog::TheLog()->is_verbose()) \
70besTimer.start((message), DHI)
73#define BES_STOPWATCH_START(module, msg)
74#define BES_STOPWATCH_START_DHI(module, msg, DHI)
81#define BES_MODULE_TIMING(message) BESStopWatch commandTimer; \
82 commandTimer.start(string("Module timing: ") + (message))
85#define BES_COMMAND_TIMING(message, DHI) BESStopWatch commandTimer; \
86 commandTimer.start(string("Command timing: ") + (message) + (DHI->data[LOG_INFO]), DHI)
89#define BES_MODULE_TIMING(message)
90#define BES_COMMAND_TIMING(message, DHI)
96extern BESStopWatch *elapsedTimeToReadStart;
97extern BESStopWatch *elapsedTimeToTransmitStart;
102 std::string d_timer_name;
103 std::string d_req_id;
104 std::string d_log_name = TIMING_LOG_KEY;
105 bool d_started =
false;
107 struct timeval d_start_usage{};
108 struct timeval d_stop_usage{};
110 unsigned long int get_elapsed_us()
const;
111 unsigned long int get_start_us()
const;
112 unsigned long int get_stop_us()
const;
113 static bool get_time_of_day(
struct timeval &time_val);
127 explicit BESStopWatch(
const std::string &logName) : d_log_name(logName) { }
147 virtual bool start(
const std::string &name,
const std::string &reqID = {BESLog::TheLog()->get_request_id()});
158 virtual bool start(
const std::string &name, BESDataHandlerInterface *dhi);
160 void dump(std::ostream &strm)
const override;
top level BES object to house generic methods
BESStopWatch()=default
Makes a new BESStopWatch with a logName of TIMING_LOG_KEY.
void dump(std::ostream &strm) const override
dumps information about this object
virtual bool start(const std::string &name, const std::string &reqID={BESLog::TheLog() ->get_request_id()})
BESStopWatch(const std::string &logName)