-
Notifications
You must be signed in to change notification settings - Fork 8
/
trace.cpp
37 lines (31 loc) · 914 Bytes
/
trace.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "trace.h"
#include <chrono>
#include <iomanip>
#include <iostream>
class TimeTraceImpl
{
public:
TimeTraceImpl(const char* func) : func(func) { start = std::chrono::steady_clock::now(); }
~TimeTraceImpl()
{
end = std::chrono::steady_clock::now();
uint64_t elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
std::cerr << "Time for " << func << " " << std::fixed << std::setprecision(3) << elapsed / 1000.0
<< " ms" << std::endl;
}
private:
std::chrono::time_point<std::chrono::steady_clock> start, end;
const char* func;
};
void TimeTrace::createImpl(const char* func)
{
impl = new TimeTraceImpl(func);
}
void TimeTrace::destroyImpl()
{
delete impl;
}
void trace(const char* file, int line, const char* func)
{
std::cerr << file << ":" << line << "::" << func << std::endl;
}