42#include "BESStopWatch.h"
54#define MODULE TIMING_LOG_KEY
55#define prolog string("BESStopWatch::").append(__func__).append("() - ")
58BESStopWatch *elapsedTimeToReadStart =
nullptr;
59BESStopWatch *elapsedTimeToTransmitStart =
nullptr;
70 string reqId = dhi->
data[REQUEST_ID_KEY];
72 string uuid = dhi->
data[REQUEST_UUID_KEY];
74 uuid =
"BESStopWatch-" + BESUtil::uuid();
75 dhi->
data[REQUEST_UUID_KEY] = uuid;
77 reqId = reqId +
"-" + uuid;
81 reqId = BESLog::TheLog()->get_request_id();
84 reqId = prolog +
"OUCH! The values of dhi->data[\"" REQUEST_ID_KEY
"\" and BESLog::TheLog()->get_request_id() were empty.";
86 return start(name,reqId);
104 d_req_id = (reqID.empty()?
"ReqIdEmpty":reqID);
107 if (!get_time_of_day(d_start_usage)) {
113 std::stringstream msg;
114 if (BESLog::TheLog()->is_verbose()) {
115 msg <<
"start_us" << BESLog::mark << get_start_us() << BESLog::mark;
116 msg << d_req_id << BESLog::mark;
117 msg << d_timer_name << endl;
118 TIMING_LOG(msg.str());
125bool BESStopWatch::get_time_of_day(
struct timeval &time_val) {
127 if (gettimeofday(&time_val,
nullptr) != 0) {
128 const char *c_err = strerror(errno);
129 string errno_msg = c_err !=
nullptr ? c_err :
"unknown error";
130 string msg = prolog +
"ERROR The gettimeofday() function failed. errno_msg: " + errno_msg +
"\n";
131 BESDEBUG(TIMING_LOG_KEY, msg );
150 if (!get_time_of_day(d_stop_usage)) {
155 BESDEBUG(TIMING_LOG_KEY, get_debug_log_line_prefix() +
"[" << d_log_name +
"]"
156 +
"[ELAPSED][" + std::to_string(get_elapsed_us()) +
" us]"
157 +
"[STARTED][" + std::to_string(get_start_us()) +
" us]"
158 +
"[STOPPED][" + std::to_string(get_stop_us()) +
" us]"
159 +
"[" + (d_req_id.empty() ?
"-" : d_req_id) +
"]" +
"[" << d_timer_name +
"]\n");
161 TIMING_LOG(
"elapsed-us" + BESLog::mark + std::to_string(get_elapsed_us()) + BESLog::mark
162 +
"start-us" + BESLog::mark + std::to_string(get_start_us()) + BESLog::mark
163 +
"stop-us" + BESLog::mark + std::to_string(get_stop_us()) + BESLog::mark
164 + (d_req_id.empty() ?
"-" : d_req_id) + BESLog::mark
165 + d_timer_name +
"\n");
174unsigned long int BESStopWatch::get_elapsed_us()
const {
175 return get_stop_us() - get_start_us();
178unsigned long int BESStopWatch::get_start_us()
const {
179 return d_start_usage.tv_sec * 1000 * 1000 + d_start_usage.tv_usec;
182unsigned long int BESStopWatch::get_stop_us()
const {
183 return d_stop_usage.tv_sec * 1000 * 1000 + d_stop_usage.tv_usec;
195 strm << BESIndent::LMarg <<
"BESStopWatch::dump - ("
196 << (
void *)
this <<
")" << endl;
Structure storing information used by the BES to handle the request.
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
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()})