OpenTTD: src/pathfinder/pf_performance_timer.hpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

pf_performance_timer.hpp
Go to the documentation of this file.
1 /* $Id: pf_performance_timer.hpp 23640 2011-12-20 17:57:56Z truebrain $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD 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, version 2.
6 * OpenTTD 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.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef PF_PERFORMANCE_TIMER_HPP
13 #define PF_PERFORMANCE_TIMER_HPP
14
15 #include "../debug.h"
16
17 struct CPerformanceTimer
18 {
19 int64 m_start;
20 int64 m_acc;
21
22 CPerformanceTimer() : m_start(0), m_acc(0) {}
23
24 inline void Start()
25 {
26 m_start = QueryTime();
27 }
28
29 inline void Stop()
30 {
31 m_acc += QueryTime() - m_start;
32 }
33
34 inline int Get(int64 coef)
35 {
36 return (int)(m_acc * coef / QueryFrequency());
37 }
38
39 inline int64 QueryTime()
40 {
41 return ottd_rdtsc();
42 }
43
44 inline int64 QueryFrequency()
45 {
46 return ((int64)2200 * 1000000);
47 }
48 };
49
50 struct CPerfStartReal
51 {
52 CPerformanceTimer *m_pperf;
53
54 inline CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
55 {
56 if (m_pperf != NULL) m_pperf->Start();
57 }
58
59 inline ~CPerfStartReal()
60 {
61 Stop();
62 }
63
64 inline void Stop()
65 {
66 if (m_pperf != NULL) {
67 m_pperf->Stop();
68 m_pperf = NULL;
69 }
70 }
71 };
72
73 struct CPerfStartFake
74 {
75 inline CPerfStartFake(CPerformanceTimer& perf) {}
76 inline ~CPerfStartFake() {}
77 inline void Stop() {}
78 };
79
80 typedef CPerfStartFake CPerfStart;
81
82 #endif /* PF_PERFORMANCE_TIMER_HPP */