2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief platform neutral timing utilities
20 * A timer can be started/stopped multiple times and measures the (wallclock)
21 * time spent between start and stop calls.
23 typedef struct ir_timer_t ir_timer_t;
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.
32 FIRM_API int ir_timer_enter_high_priority(void);
35 * Leave the high priority mode.
36 * @see ir_timer_enter_high_priority()
37 * @return 0 on success, else UNIX error code.
39 FIRM_API int ir_timer_leave_high_priority(void);
42 * Returns the amount of bytes allocated on the heap.
43 * @return The number of bytes allocated on the heap.
45 FIRM_API size_t ir_get_heap_used_bytes(void);
52 FIRM_API ir_timer_t *ir_timer_new(void);
55 * free memory occupied by a timer
56 * @param timer The timer
58 FIRM_API void ir_timer_free(ir_timer_t *timer);
62 * @param timer The timer.
64 FIRM_API void ir_timer_start(ir_timer_t *timer);
67 * Reset a timer and start it.
68 * @param timer The timer.
70 FIRM_API void ir_timer_reset_and_start(ir_timer_t *timer);
74 * @param timer The timer.
76 FIRM_API void ir_timer_reset(ir_timer_t *timer);
80 * Stopping a stopped timer has no effect.
81 * @param timer The timer.
83 FIRM_API void ir_timer_stop(ir_timer_t *timer);
86 * Set currently running timer as parent to @p timer
88 FIRM_API void ir_timer_init_parent(ir_timer_t *timer);
91 * Push a timer of the timer stack. This automatically
92 * stop the previous timer on tos and start the new one.
94 * @param timer The timer to push on stack.
95 * @return non-zero on succes, zero if the timer is already on the stack.
97 FIRM_API void ir_timer_push(ir_timer_t *timer);
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
104 FIRM_API void ir_timer_pop(ir_timer_t *timer);
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.
111 FIRM_API unsigned long ir_timer_elapsed_msec(const ir_timer_t *timer);
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.
118 FIRM_API unsigned long ir_timer_elapsed_usec(const ir_timer_t *timer);
121 * Returns the number of seconds, the timer has elapsed.
123 FIRM_API double ir_timer_elapsed_sec(const ir_timer_t *timer);