Path: blob/21.2-virgl/src/tool/pps/pps_counter.h
7160 views
/*1* Copyright © 2020 Collabora, Ltd.2* Author: Antonio Caggiano <[email protected]>3* Author: Rohan Garg <[email protected]>4* Author: Robert Beckett <[email protected]>5*6* SPDX-License-Identifier: MIT7*/89#pragma once1011#include <functional>12#include <string>13#include <variant>14#include <vector>1516namespace pps17{18struct CounterGroup {19std::string name;2021uint32_t id;2223/// List of counters ID belonging to this group24std::vector<int32_t> counters;2526std::vector<CounterGroup> subgroups;27};2829class Driver;3031class Counter32{33public:34/// @brief A counter value can be of different types depending on what it represents:35/// cycles, cycles-per-instruction, percentages, bytes, and so on.36enum class Units {37Percent,38Byte,39Hertz,40None,41};4243using Value = std::variant<int64_t, double>;4445/// @param c Counter which we want to retrieve a value46/// @param d Driver used to sample performance counters47/// @return The value of the counter48using Getter = Value(const Counter &c, const Driver &d);4950Counter() = default;51virtual ~Counter() = default;5253/// @param id ID of the counter54/// @param name Name of the counter55/// @param group Group ID this counter belongs to56Counter(int32_t id, const std::string &name, int32_t group);5758bool operator==(const Counter &c) const;5960/// @param get New getter function for this counter61void set_getter(const std::function<Getter> &get);6263/// @brief d Driver used to sample performance counters64/// @return Last sampled value for this counter65Value get_value(const Driver &d) const;6667/// Id of the counter68int32_t id = -1;6970/// Name of the counter71std::string name = "";7273/// ID of the group this counter belongs to74int32_t group = -1;7576/// Offset of this counter within GPU counter list77/// For derived counters it is negative and remains unused78int32_t offset = -1;7980/// Whether it is a derived counter or not81bool derived = false;8283/// Returns the value of this counter84std::function<Getter> getter;8586/// The unit of the counter87Units units;88};8990/// @param get New getter function for this counter91inline void Counter::set_getter(const std::function<Getter> &get)92{93getter = get;94}9596/// @brief d Driver used to sample performance counters97/// @return Last sampled value for this counter98inline Counter::Value Counter::get_value(const Driver &d) const99{100return getter(*this, d);101}102103/// @return The underlying u32 value104template<typename T> constexpr uint32_t to_u32(T &&elem)105{106return static_cast<uint32_t>(elem);107}108109} // namespace pps110111112