Freeciv21
Develop your civilization from humble roots to a global empire
timing.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // Qt
14 #include <QLoggingCategory>
15 
16 // Timing logging is has to be filtered out to compare logs when needed.
17 Q_DECLARE_LOGGING_CATEGORY(timers_category)
18 
20  TIMER_CPU, // time spent by the CPU
21  TIMER_USER // time as seen by the user ("wall clock")
22 };
23 
24 enum timer_use {
25  TIMER_ACTIVE, // use this timer
26  TIMER_IGNORE // ignore this timer
27 };
28 /*
29  * TIMER_IGNORE is to leave a timer in the code, but not actually
30  * use it, and not make any time-related system calls for it.
31  * It is also used internally to turn off timers if the system
32  * calls indicate that timing is not available.
33  * Also note TIMER_DEBUG below.
34  */
35 
36 #ifdef FREECIV_DEBUG
37 #define TIMER_DEBUG TIMER_ACTIVE
38 #else
39 #define TIMER_DEBUG TIMER_IGNORE
40 #endif
41 
42 class civtimer;
43 
46  enum timer_use use);
47 
48 void timer_destroy(civtimer *t);
49 bool timer_in_use(civtimer *t);
50 
51 void timer_clear(civtimer *t);
52 void timer_start(civtimer *t);
53 void timer_stop(civtimer *t);
54 
55 double timer_read_seconds(civtimer *t);
enum timer_timetype type
Definition: timing.cpp:28
enum timer_use use
Definition: timing.cpp:29
void timer_destroy(civtimer *t)
Deletes timer.
Definition: timing.cpp:66
double timer_read_seconds(civtimer *t)
Read value from timer.
Definition: timing.cpp:137
civtimer * timer_new(enum timer_timetype type, enum timer_use use)
Allocate a new timer with specified "type" and "use".
Definition: timing.cpp:43
void timer_start(civtimer *t)
Start timing, adding to previous accumulated time if timer has not been cleared.
Definition: timing.cpp:95
timer_use
Definition: timing.h:24
@ TIMER_ACTIVE
Definition: timing.h:25
@ TIMER_IGNORE
Definition: timing.h:26
void timer_clear(civtimer *t)
Reset accumulated time to zero, and stop timer if going.
Definition: timing.cpp:83
civtimer * timer_renew(civtimer *t, enum timer_timetype type, enum timer_use use)
Allocate a new timer, or reuse t, with specified "type" and "use".
Definition: timing.cpp:51
bool timer_in_use(civtimer *t)
Return whether timer is in use.
Definition: timing.cpp:76
timer_timetype
Definition: timing.h:19
@ TIMER_CPU
Definition: timing.h:20
@ TIMER_USER
Definition: timing.h:21
void timer_stop(civtimer *t)
Stop timing, and accumulate time so far.
Definition: timing.cpp:116