-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathminiprofiler.h
56 lines (47 loc) · 1.66 KB
/
miniprofiler.h
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
50
51
52
53
54
55
56
// Copyright 2012, Olav Stetter
//
// This file is part of TE-Causality.
//
// TE-Causality is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TE-Causality is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TE-Causality. If not, see <http://www.gnu.org/licenses/>.
// This is a very simple (and probably not very accurate) time
// measurement object to see which tasks of a given program are taking
// how much time to compute.
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <sstream>
#include <time.h>
#include <vector>
#define __MINIPROFILER_H
struct MiniProfilerTask {
std::string name;
clock_t elapsed_clock_ticks;
bool currently_active;
clock_t clock_tick_of_activation;
};
class MiniProfiler {
protected:
std::vector<MiniProfilerTask> tasks;
int search(const std::string& t_name) const;
float get_current_time(int task_index) const; // in seconds
public:
MiniProfiler();
~MiniProfiler();
int number_of_registered_tasks() const;
void register_task(const std::string& t_name);
void resuming_task(const std::string& t_name);
void stopping_task(const std::string& t_name);
float get_current_time(const std::string& t_name) const; // in seconds
std::string summary();
};