remove license stuff from files
[libfirm] / include / libfirm / timing.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief    platform neutral timing utilities
9  */
10 #ifndef FIRM_TIMING_H
11 #define FIRM_TIMING_H
12
13 #include <stdlib.h>
14
15 #include "begin.h"
16
17 /**
18  * A timer
19  *
20  * A timer can be started/stopped multiple times and measures the (wallclock)
21  * time spent between start and stop calls.
22  */
23 typedef struct ir_timer_t ir_timer_t;
24
25 /**
26  * Switch to real-time scheduling.
27  * This shall make measurements more precise.
28  * @note Does not work for all operating systems.
29  * @note You could need special user privileges.
30  * @return 0 on success, else UNIX error code.
31  */
32 FIRM_API int ir_timer_enter_high_priority(void);
33
34 /**
35  * Leave the high priority mode.
36  * @see ir_timer_enter_high_priority()
37  * @return 0 on success, else UNIX error code.
38  */
39 FIRM_API int ir_timer_leave_high_priority(void);
40
41 /**
42  * Returns the amount of bytes allocated on the heap.
43  * @return The number of bytes allocated on the heap.
44  */
45 FIRM_API size_t ir_get_heap_used_bytes(void);
46
47 /**
48  * Create a new timer
49  * @return The timer.
50  * @see #ir_timer_t
51  */
52 FIRM_API ir_timer_t *ir_timer_new(void);
53
54 /**
55  * free memory occupied by a timer
56  * @param timer The timer
57  */
58 FIRM_API void ir_timer_free(ir_timer_t *timer);
59
60 /**
61  * Start a timer.
62  * @param timer The timer.
63  */
64 FIRM_API void ir_timer_start(ir_timer_t *timer);
65
66 /**
67  * Reset a timer and start it.
68  * @param timer The timer.
69  */
70 FIRM_API void ir_timer_reset_and_start(ir_timer_t *timer);
71
72 /**
73  * Reset a timer.
74  * @param timer The timer.
75  */
76 FIRM_API void ir_timer_reset(ir_timer_t *timer);
77
78 /**
79  * Stop a timer.
80  * Stopping a stopped timer has no effect.
81  * @param timer The timer.
82  */
83 FIRM_API void ir_timer_stop(ir_timer_t *timer);
84
85 /**
86  * Set currently running timer as parent to @p timer
87  */
88 FIRM_API void ir_timer_init_parent(ir_timer_t *timer);
89
90 /**
91  * Push a timer of the timer stack. This automatically
92  * stop the previous timer on tos and start the new one.
93  *
94  * @param timer   The timer to push on stack.
95  * @return non-zero on succes, zero if the timer is already on the stack.
96  */
97 FIRM_API void ir_timer_push(ir_timer_t *timer);
98
99 /**
100  * Pop the current timer. This automatically stops it and
101  * start the timer that is now on the stack.
102  * @return the popped timer
103  */
104 FIRM_API void ir_timer_pop(ir_timer_t *timer);
105
106 /**
107  * Returns the number of milliseconds, the timer has elapsed.
108  * @param timer The timer.
109  * @return The number of milliseconds the timer is (was) running.
110  */
111 FIRM_API unsigned long ir_timer_elapsed_msec(const ir_timer_t *timer);
112
113 /**
114  * Returns the number of microseconds, the timer has elapsed.
115  * @param timer The timer.
116  * @return The number of milliseconds the timer is (was) running.
117  */
118 FIRM_API unsigned long ir_timer_elapsed_usec(const ir_timer_t *timer);
119
120 /**
121  * Returns the number of seconds, the timer has elapsed.
122  */
123 FIRM_API double ir_timer_elapsed_sec(const ir_timer_t *timer);
124
125 #include "end.h"
126
127 #endif