cgv
Loading...
Searching...
No Matches
profiler.h
1#ifndef PROFILER_H
2#define PROFILER_H
3
4#include <map>
5#include <vector>
6#include <ctime>
7#include <cgv/utils/stopwatch.h>
8#include <iostream>
9#include <string>
10
11
12namespace cgv {
13 namespace utils{
14
43 template< typename T = std::string>
45 {
46
47 std::map<T,double> counter_times;
48 std::map<T,int> counter_calls;
49
50 public:
51 void prepare_counter(const T &handle)
52 {
53 counter_times[handle]=0.0;
54 counter_calls[handle]=0;
55
56 }
57
58 inline double *get_time_accu(const T handle)
59 {
60 counter_calls[handle]++;
61 return &(counter_times[handle]);
62 }
63
64 void zero_counters()
65 {
66 for(std::map<T,double>::iterator it = counter_times.begin();
67 it != counter_times.end();it++)
68 {
69 it->second=0;
70 counter_calls[it->first]=0;
71 }
72 }
73
74
75 friend std::ostream& operator<< (std::ostream& out, Profiler p)
76 {
77 for(std::map<T,double>::iterator it = p.counter_times.begin();
78 it != p.counter_times.end();it++)
79 {
80 out << it->first << ": "<< p.counter_calls[it->first] << " calls, "<<it->second << " sec, "
81 << it->second/p.counter_calls[it->first] << " sec/call (mean)"<< std::endl;
82 }
83
84 return out;
85 }
86
87 };
88
89 }
90
91}
92
93
94#endif// PROFILER_H
A profiler class for managing different stopwatches.
Definition profiler.h:45
the cgv namespace
Definition print.h:11