Freeciv-3.2: /fast/freeciv/nightly/S3_2/utility/timing.h Source File

Freeciv-3.2

Loading...
Searching...
No Matches
timing.h
Go to the documentation of this file.
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.
7
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***********************************************************************/
13
14/* Measuring times; original author: David Pfitzner <dwp@mso.anu.edu.au> */
15
16#ifndef FC__TIMING_H
17#define FC__TIMING_H
18
19#ifdef __cplusplus
20extern "C" {
21#endif /* __cplusplus */
22
23/* utility */
24#include "support.h" /* bool type */
25
26/* Undefine this if you don't want timing measurements to appear in logs.
27 This is useful if you want to compare logs of two freeciv runs and
28 want to see only differences in control flow, and not diffs full of
29 different timing results.
30*/
31#define LOG_TIMERS
32
33/* Timing logging happens so often only in debug builds that it makes
34 sense to have macro defined for it once here and to have all the
35 checks against that single macro instead of two separate. */
36#if defined(LOG_TIMERS) && defined(FREECIV_DEBUG)
37#define DEBUG_TIMERS
38#endif
39
40 enum timer_timetype {
41 TIMER_CPU, /* Time spent by the CPU */
42 TIMER_USER /* Time as seen by the user ("wall clock") */
43};
44
45 enum timer_use {
46 TIMER_ACTIVE, /* Use this timer */
47 TIMER_IGNORE /* Ignore this timer */
48};
49
50/*
51 * TIMER_IGNORE is to leave a timer in the code, but not actually
52 * use it, and not make any time-related system calls for it.
53 * It is also used internally to turn off timers if the system
54 * calls indicate that timing is not available.
55 * Also note TIMER_DEBUG below.
56 */
57
58#ifdef FREECIV_DEBUG
59#define TIMER_DEBUG TIMER_ACTIVE
60#else
61#define TIMER_DEBUG TIMER_IGNORE
62#endif
63
64struct timer; /* Opaque type; see comments in timing.c */
65
66#define SPECLIST_TAG timer
67#define SPECLIST_TYPE struct timer
68#include "speclist.h"
69#define timer_list_iterate(ARG_list, NAME_item) \
70 TYPED_LIST_ITERATE(struct timer, (ARG_list), NAME_item)
71#define timer_list_iterate_end LIST_ITERATE_END
72
73
74struct timer *timer_new(enum timer_timetype type, enum timer_use use,
75 const char *name);
76struct timer *timer_renew(struct timer *t, enum timer_timetype type,
77 enum timer_use use, const char *name);
78
79void timer_destroy(struct timer *t);
80bool timer_in_use(struct timer *t);
81
82void timer_clear(struct timer *t);
83void timer_start(struct timer *t);
84void timer_stop(struct timer *t);
85
86double timer_read_seconds(struct timer *t);
87
88void timer_usleep_since_start(struct timer *t, long usec);
89
90#ifdef __cplusplus
91}
92#endif /* __cplusplus */
93
94#endif /* FC__TIMER_H */
type
GType type
Definition repodlgs.c:1313
name
const char * name
Definition inputfile.c:127
speclist.h
timer
Definition timing.c:81
timer::t
time_t t
Definition timing.c:104
timer::usec
long usec
Definition timing.c:93
timer::use
enum timer_use use
Definition timing.c:84
support.h
timer_usleep_since_start
void timer_usleep_since_start(struct timer *t, long usec)
Definition timing.c:405
timer_clear
void timer_clear(struct timer *t)
Definition timing.c:252
timer_in_use
bool timer_in_use(struct timer *t)
Definition timing.c:242
timer_destroy
void timer_destroy(struct timer *t)
Definition timing.c:208
timer_start
void timer_start(struct timer *t)
Definition timing.c:264
timer_stop
void timer_stop(struct timer *t)
Definition timing.c:308
timer_use
timer_use
Definition timing.h:45
TIMER_ACTIVE
@ TIMER_ACTIVE
Definition timing.h:46
TIMER_IGNORE
@ TIMER_IGNORE
Definition timing.h:47
timer_new
struct timer * timer_new(enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:160
timer_read_seconds
double timer_read_seconds(struct timer *t)
Definition timing.c:384
timer_renew
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use, const char *name)
Definition timing.c:180
timer_timetype
timer_timetype
Definition timing.h:40
TIMER_CPU
@ TIMER_CPU
Definition timing.h:41
TIMER_USER
@ TIMER_USER
Definition timing.h:42