webperimental: killstack decides stack protects.
[freeciv.git] / utility / timing.h
bloba6ada5a22de62db82b04944ddc86aed65cf78c68
1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 /* Measuring times; original author: David Pfitzner <dwp@mso.anu.edu.au> */
16 #ifndef FC__TIMING_H
17 #define FC__TIMING_H
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
23 #include "support.h" /* bool type */
25 /* Undefine this if you don't want timing measurements to appear in logs.
26 This is useful if you want to compare logs of two freeciv runs and
27 want to see only differences in control flow, and not diffs full of
28 different timing results.
30 #define LOG_TIMERS
32 /* Timing logging happens so often only in debug builds that it makes
33 sense to have macro defined for it once here and to have all the
34 checks against that single macro instead of two separate. */
35 #if defined(LOG_TIMERS) && defined(FREECIV_DEBUG)
36 #define DEBUG_TIMERS
37 #endif
39 enum timer_timetype {
40 TIMER_CPU, /* time spent by the CPU */
41 TIMER_USER /* time as seen by the user ("wall clock") */
44 enum timer_use {
45 TIMER_ACTIVE, /* use this timer */
46 TIMER_IGNORE /* ignore this timer */
49 * TIMER_IGNORE is to leave a timer in the code, but not actually
50 * use it, and not make any time-related system calls for it.
51 * It is also used internally to turn off timers if the system
52 * calls indicate that timing is not available.
53 * Also note TIMER_DEBUG below.
56 #ifdef FREECIV_DEBUG
57 #define TIMER_DEBUG TIMER_ACTIVE
58 #else
59 #define TIMER_DEBUG TIMER_IGNORE
60 #endif
62 struct timer; /* opaque type; see comments in timing.c */
64 #define SPECLIST_TAG timer
65 #define SPECLIST_TYPE struct timer
66 #include "speclist.h"
67 #define timer_list_iterate(ARG_list, NAME_item) \
68 TYPED_LIST_ITERATE(struct timer, (ARG_list), NAME_item)
69 #define timer_list_iterate_end LIST_ITERATE_END
72 struct timer *timer_new(enum timer_timetype type, enum timer_use use);
73 struct timer *timer_renew(struct timer *t, enum timer_timetype type,
74 enum timer_use use);
76 void timer_destroy(struct timer *t);
77 bool timer_in_use(struct timer *t);
79 void timer_clear(struct timer *t);
80 void timer_start(struct timer *t);
81 void timer_stop(struct timer *t);
83 double timer_read_seconds(struct timer *t);
85 void timer_usleep_since_start(struct timer *t, long usec);
87 #ifdef __cplusplus
89 #endif /* __cplusplus */
91 #endif /* FC__TIMER_H */