xref: /aosp_15_r20/external/mesa3d/src/tool/pps/pps.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2020 Collabora, Ltd.
3  * Author: Antonio Caggiano <[email protected]>
4  *
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #pragma once
9 
10 #include <perfetto.h>
11 
12 #define PPS_LOG PERFETTO_LOG
13 #define PPS_LOG_IMPORTANT PERFETTO_ILOG
14 #define PPS_LOG_ERROR PERFETTO_ELOG
15 #define PPS_LOG_FATAL PERFETTO_FATAL
16 
17 namespace pps
18 {
19 enum class State {
20    Stop,  // initial state, or stopped by the tracing service
21    Start, // running, sampling data
22 };
23 
24 /// @brief Checks whether a return value is valid
25 /// @param res Result from a syscall
26 /// @param msg Message to prepend to strerror
27 /// @return True if ok, false otherwise
28 bool check(int res, const char *msg);
29 
30 void make_thread_rt();
31 
32 /// @param num Numerator
33 /// @param den Denominator
34 /// @return A ratio between two floating point numbers, or 0 if the denominator is 0
ratio(double num,double den)35 constexpr double ratio(double num, double den)
36 {
37    return den > 0.0 ? num / den : 0.0;
38 }
39 
40 } // namespace pps
41