Software APIs
profile.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_PROFILE_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_PROFILE_H_
7 
8 #include <stdint.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif // __cplusplus
13 
14 /**
15  * Start a cycle-count timing profile.
16  *
17  * Basic usage:
18  * uint64_t t_start = profile_start();
19  * // Do some stuff
20  * uint32_t cycles = profile_end(t_start);
21  * LOG_INFO("Some stuff took %d cycles.", cycles);
22  *
23  * You can run multiple profiles at once by simply calling `profile_start`
24  * repeatedly.
25  *
26  * @return Ibex cycle count at start time.
27  */
28 uint64_t profile_start(void);
29 
30 /**
31  * End a cycle-count timing profile.
32  *
33  * In typical usage, `t_start` is something that was previously returned from
34  * `profile_start()`.
35  *
36  * @param t_start Cycle count at profile start time.
37  * @return Number of cycles between t_start and current Ibex cycle count.
38  */
39 uint32_t profile_end(uint64_t t_start);
40 
41 /**
42  * End a cycle-count timing profile and print a message with timing data.
43  *
44  * In typical usage, `t_start` is something that was previously returned from
45  * `profile_start()`.
46  *
47  * @param t_start Cycle count at profile start time.
48  * @param name Name of the profile, for printing.
49  * @return Number of cycles between t_start and current Ibex cycle count.
50  */
51 uint32_t profile_end_and_print(uint64_t t_start, char *name);
52 
53 #ifdef __cplusplus
54 } // extern "C"
55 #endif // __cplusplus
56 
57 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_PROFILE_H_