forked from notaz/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpps_counter.h
110 lines (84 loc) · 2.6 KB
/
pps_counter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright © 2020 Collabora, Ltd.
* Author: Antonio Caggiano <[email protected]>
* Author: Rohan Garg <[email protected]>
* Author: Robert Beckett <[email protected]>
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <functional>
#include <string>
#include <variant>
#include <vector>
namespace pps
{
struct CounterGroup {
std::string name;
uint32_t id;
/// List of counters ID belonging to this group
std::vector<int32_t> counters;
std::vector<CounterGroup> subgroups;
};
class Driver;
class Counter
{
public:
/// @brief A counter value can be of different types depending on what it represents:
/// cycles, cycles-per-instruction, percentages, bytes, and so on.
enum class Units {
Percent,
Byte,
Hertz,
None,
};
using Value = std::variant<int64_t, double>;
/// @param c Counter which we want to retrieve a value
/// @param d Driver used to sample performance counters
/// @return The value of the counter
using Getter = Value(const Counter &c, const Driver &d);
Counter() = default;
virtual ~Counter() = default;
/// @param id ID of the counter
/// @param name Name of the counter
/// @param group Group ID this counter belongs to
Counter(int32_t id, const std::string &name, int32_t group);
bool operator==(const Counter &c) const;
/// @param get New getter function for this counter
void set_getter(const std::function<Getter> &get);
/// @brief d Driver used to sample performance counters
/// @return Last sampled value for this counter
Value get_value(const Driver &d) const;
/// Id of the counter
int32_t id = -1;
/// Name of the counter
std::string name = "";
/// ID of the group this counter belongs to
int32_t group = -1;
/// Offset of this counter within GPU counter list
/// For derived counters it is negative and remains unused
int32_t offset = -1;
/// Whether it is a derived counter or not
bool derived = false;
/// Returns the value of this counter
std::function<Getter> getter;
/// The unit of the counter
Units units;
};
/// @param get New getter function for this counter
inline void Counter::set_getter(const std::function<Getter> &get)
{
getter = get;
}
/// @brief d Driver used to sample performance counters
/// @return Last sampled value for this counter
inline Counter::Value Counter::get_value(const Driver &d) const
{
return getter(*this, d);
}
/// @return The underlying u32 value
template<typename T> constexpr uint32_t to_u32(T &&elem)
{
return static_cast<uint32_t>(elem);
}
} // namespace pps