-
Notifications
You must be signed in to change notification settings - Fork 16
/
debugger.cpp
49 lines (35 loc) · 1 KB
/
debugger.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
38
39
40
41
42
43
44
45
46
47
48
49
#include <string>
#include <sstream>
#include <iostream>
#include <chrono>
#include "debugger.hpp"
using namespace std;
//set to inactive on creation
bool debugger::active = false;
//lazy static singleton
debugger& debugger::instance() {
static debugger instance;
return instance;
}
//start timing & print
void debugger::start(string msg) {
if(!active) return;
t_start = chrono::high_resolution_clock::now();
print(msg + " starting");
}
//end timing & print
void debugger::end(string msg) {
if(!active) return;
t_end = chrono::high_resolution_clock::now();
int secs = chrono::duration_cast<chrono::seconds>(t_end - t_start).count();
int millisecs = chrono::duration_cast<chrono::milliseconds>(t_end - t_start).count();
stringstream ss;
ss << msg << " took: " << secs << ":" << millisecs;
string str = ss.str();
print(str);
}
//simple cout wrapper (for now)
void debugger::print(string msg) {
if(!active) return;
cout << "DEBUG: " << msg << endl;
}