1 /*
2  * Copyright (c) 2013-2019, The University of Oxford
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright notice,
8  *    this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  *    this list of conditions and the following disclaimer in the documentation
11  *    and/or other materials provided with the distribution.
12  * 3. Neither the name of the University of Oxford nor the names of its
13  *    contributors may be used to endorse or promote products derived from this
14  *    software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef OSKAR_TIMER_H_
30 #define OSKAR_TIMER_H_
31 
32 /**
33  * @file oskar_timer.h
34  */
35 
36 #include <oskar_global.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 struct oskar_Timer;
43 #ifndef OSKAR_TIMER_TYPEDEF_
44 #define OSKAR_TIMER_TYPEDEF_
45 typedef struct oskar_Timer oskar_Timer;
46 #endif /* OSKAR_TIMER_TYPEDEF_ */
47 
48 enum OSKAR_TIMER_TYPE
49 {
50     OSKAR_TIMER_NATIVE = 0,
51     OSKAR_TIMER_CUDA = 1,
52     OSKAR_TIMER_CL = 2
53 };
54 
55 /**
56  * @brief Creates a timer.
57  *
58  * @details
59  * Creates a timer. The timer is created in a paused state.
60  *
61  * The \p type parameter may take the values:
62  *
63  * - OSKAR_TIMER_NATIVE (0)
64  * - OSKAR_TIMER_CUDA (1)
65  * - OSKAR_TIMER_CL (2)
66  *
67  * These timers are used to measure performance of, respectively,
68  * native C code, CUDA, or OpenCL kernels.
69  *
70  * @param[in,out] timer Pointer to timer.
71  * @param[in] type Type of timer to create.
72  */
73 OSKAR_EXPORT
74 oskar_Timer* oskar_timer_create(int type);
75 
76 /**
77  * @brief Destroys the timer.
78  *
79  * @details
80  * Destroys the timer.
81  *
82  * @param[in,out] timer Pointer to timer.
83  */
84 OSKAR_EXPORT
85 void oskar_timer_free(oskar_Timer* timer);
86 
87 /**
88  * @brief Returns the total elapsed time, in seconds.
89  *
90  * @details
91  * Returns the number of seconds since the timer was started.
92  *
93  * @param[in,out] timer Pointer to timer.
94  *
95  * @return The number of seconds since the timer was started.
96  */
97 OSKAR_EXPORT
98 double oskar_timer_elapsed(oskar_Timer* timer);
99 
100 /**
101  * @brief Pauses the timer.
102  *
103  * @details
104  * Pauses the timer.
105  *
106  * @param[in,out] timer Pointer to timer.
107  */
108 OSKAR_EXPORT
109 void oskar_timer_pause(oskar_Timer* timer);
110 
111 /**
112  * @brief Resets a timer.
113  *
114  * @details
115  * Resets a timer back to its initial state.
116  * The timer is zeroed and paused.
117  *
118  * @param[in,out] timer Pointer to timer.
119  */
120 OSKAR_EXPORT
121 void oskar_timer_reset(oskar_Timer* timer);
122 
123 /**
124  * @brief Resumes the timer.
125  *
126  * @details
127  * Resumes the timer from a paused state.
128  *
129  * @param[in,out] timer Pointer to timer.
130  */
131 OSKAR_EXPORT
132 void oskar_timer_resume(oskar_Timer* timer);
133 
134 /**
135  * @brief Restarts the timer.
136  *
137  * @details
138  * Restarts the timer.
139  *
140  * @param[in,out] timer Pointer to timer.
141  */
142 OSKAR_EXPORT
143 void oskar_timer_restart(oskar_Timer* timer);
144 
145 /**
146  * @brief Starts and resets the timer.
147  *
148  * @details
149  * Starts and resets the timer, clearing the current elapsed time.
150  *
151  * @param[in,out] timer Pointer to timer.
152  */
153 OSKAR_EXPORT
154 void oskar_timer_start(oskar_Timer* timer);
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* include guard */
161