1 /*
2  * Copyright (c) 2024 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __BENCHMARK_SCHEDQ_UTILS_H
8 #define __BENCHMARK_SCHEDQ_UTILS_H
9 /*
10  * @brief This file contains macros used in the scheduler queue benchmarking.
11  */
12 
13 #include <zephyr/timing/timing.h>
14 #include <zephyr/sys/printk.h>
15 #include <stdio.h>
16 
17 #ifdef CSV_FORMAT_OUTPUT
18 #define FORMAT_STR   "%-74s,%s,%s\n"
19 #define CYCLE_FORMAT "%8u"
20 #define NSEC_FORMAT  "%8u"
21 #else
22 #define FORMAT_STR   "%-74s:%s , %s\n"
23 #define CYCLE_FORMAT "%8u cycles"
24 #define NSEC_FORMAT  "%8u ns"
25 #endif
26 
27 /**
28  * @brief Display a line of statistics
29  *
30  * This macro displays the following:
31  *  1. Test description summary
32  *  2. Number of cycles
33  *  3. Number of nanoseconds
34  */
35 #define PRINT_F(summary, cycles, nsec)                            \
36 	do {                                                      \
37 		char cycle_str[32];                               \
38 		char nsec_str[32];                                \
39 								  \
40 		snprintk(cycle_str, 30, CYCLE_FORMAT, cycles);    \
41 		snprintk(nsec_str, 30, NSEC_FORMAT, nsec);        \
42 		printk(FORMAT_STR, summary, cycle_str, nsec_str); \
43 	} while (0)
44 
45 #define PRINT_STATS(summary, value)                   \
46 	PRINT_F(summary, value,                       \
47 		(uint32_t)timing_cycles_to_ns(value))
48 
49 #define PRINT_STATS_AVG(summary, value, counter)                    \
50 	PRINT_F(summary, value / counter,                           \
51 		(uint32_t)timing_cycles_to_ns_avg(value, counter))
52 
53 
54 #endif
55