xref: /third_party/mesa3d/src/tool/pps/pps.h (revision bf215546)
1/*
2 * Copyright © 2020 Collabora, Ltd.
3 * Author: Antonio Caggiano <antonio.caggiano@collabora.com>
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
17namespace pps
18{
19enum 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
28bool check(int res, const char *msg);
29
30/// @param num Numerator
31/// @param den Denominator
32/// @return A ratio between two floating point numbers, or 0 if the denominator is 0
33constexpr double ratio(double num, double den)
34{
35   return den > 0.0 ? num / den : 0.0;
36}
37
38} // namespace pps
39