Rework the trip history window layout.
[openttd-joker.git] / src / pathfinder / pf_performance_timer.hpp
blob6e34ba60a304fc9fa5a1c3af3d74e7a10ac10743
1 /* $Id: pf_performance_timer.hpp 23640 2011-12-20 17:57:56Z truebrain $ */
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 */
10 /** @file pf_performance_timer.hpp Performance timer for pathfinders. */
12 #ifndef PF_PERFORMANCE_TIMER_HPP
13 #define PF_PERFORMANCE_TIMER_HPP
15 #include "../debug.h"
17 struct CPerformanceTimer
19 int64 m_start;
20 int64 m_acc;
22 CPerformanceTimer() : m_start(0), m_acc(0) {}
24 inline void Start()
26 m_start = QueryTime();
29 inline void Stop()
31 m_acc += QueryTime() - m_start;
34 inline int Get(int64 coef)
36 return (int)(m_acc * coef / QueryFrequency());
39 inline int64 QueryTime()
41 return ottd_rdtsc();
44 inline int64 QueryFrequency()
46 return ((int64)2200 * 1000000);
50 struct CPerfStartReal
52 CPerformanceTimer *m_pperf;
54 inline CPerfStartReal(CPerformanceTimer* perf) : m_pperf(perf)
56 if (m_pperf != NULL) m_pperf->Start();
59 inline ~CPerfStartReal()
61 Stop();
64 inline void Stop()
66 if (m_pperf != NULL) {
67 m_pperf->Stop();
68 m_pperf = NULL;
73 struct CPerfStartFake
75 inline CPerfStartFake(CPerformanceTimer* perf) {}
76 inline ~CPerfStartFake() {}
77 inline void Stop() {}
80 typedef CPerfStartFake CPerfStart;
82 #endif /* PF_PERFORMANCE_TIMER_HPP */