forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
111 lines (98 loc) · 2.31 KB
/
timer.h
File metadata and controls
111 lines (98 loc) · 2.31 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef TIMER_H
#define TIMER_H
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
namespace ModuleBase
{
/**
* @brief Tracing computation time
* @authors Fangwei, Mohan, Peize Lin
*
*/
class timer
{
public:
struct Timer_One
{
double cpu_start;
double cpu_second = 0.0;
size_t calls = 0;
size_t order = n_now++;
bool start_flag = true;
};
static std::map<std::string, std::map<std::string, Timer_One>> timer_pool;
/**
* @brief Use twice at a time: the first time, set start_flag to false;
* the second time, calculate the time duration
*
* @param class_name_in The class name for timing
* @param name_in The compuational process for timing
*/
static void tick(const std::string &class_name_in, const std::string &name_in);
/**
* @brief Start total time calculation
*
*/
static void start(void);
/**
* @brief Finish total time calculation and
* print computational processes with duration > 0.1 s
*
* @param ofs The output file for print out timings
* @param print_flag Print timings or not
*/
static void finish(std::ofstream &ofs, const bool print_flag = 1);
/**
* @brief Enable time computation
*
*/
static void enable(void)
{
disabled = false;
}
/**
* @brief Disable time computation
*
*/
static void disable(void)
{
disabled = true;
}
/**
* @brief Print all computational processes with during > 0.1 s
*
* @param ofs The output file for print out timings
*/
static void print_all(std::ofstream &ofs);
/**
* @brief Stop total time calculation, print total time until now,
* and then start total time calculation again
*
* @return long double
*/
static long double print_until_now(void);
private:
/**
* @brief Member variable: if disabled , timer can't work
*
*/
static bool disabled;
/**
* @brief Member variable: the index of clocks
*
*/
static size_t n_now;
/**
* @brief Member function: calculate time
*
* @return double
*/
static double cpu_time(void);
};
} // namespace ModuleBase
#endif