/*1* Copyright © 2020 Collabora, Ltd.2* Author: Antonio Caggiano <[email protected]>3* Author: Robert Beckett <[email protected]>4* Author: Corentin Noël <[email protected]>5*6* SPDX-License-Identifier: MIT7*/89#pragma once1011#include <memory>12#include <string>13#include <unordered_map>14#include <vector>1516#include "pps_counter.h"17#include "pps_device.h"1819namespace pps20{21/// @brief Abstract Driver class22class Driver23{24public:25/// @return A map of supported DRM device names and their relative pps driver26static const std::unordered_map<std::string, std::unique_ptr<Driver>> &get_supported_drivers();2728/// @return A list of supported DRM device names29static const std::vector<std::string> supported_device_names();3031/// @return A driver supporting a specific DRM device32static Driver *get_driver(DrmDevice &&drm_device);3334/// @return The name of a default selected PPS driver35static std::string default_driver_name();3637/// @return The name of a driver based on the request, otherwise the default driver name38static std::string find_driver_name(const char *requested_name);3940Driver() = default;41virtual ~Driver() = default;4243// Forbid copy44Driver(const Driver &) = delete;45Driver &operator=(const Driver &) = delete;4647/// @return The minimum sampling period for the current device48virtual uint64_t get_min_sampling_period_ns() = 0;4950/// @brief Enable a counter by its ID51virtual void enable_counter(uint32_t counter_id) = 0;5253virtual void enable_all_counters() = 0;5455/// @brief Initialize performance counters data such as groups and counters56/// @return Whether it was successful or not57virtual bool init_perfcnt() = 0;5859/// @brief Enables performance counters, meaning that from now on they can be sampled60virtual void enable_perfcnt(uint64_t sampling_period_ns) = 0;6162/// @brief Disables performance counters on the device63virtual void disable_perfcnt() = 0;6465/// @brief Asking the GPU to dump performance counters could have different meanings66/// depending on the concrete driver. Some could just ask the GPU to dump counters to a67/// user space buffer, while some others will need to read data from a stream which was68/// written asynchronously.69/// @return Whether it was able to dump, false otherwise70virtual bool dump_perfcnt() = 0;7172/// @brief After dumping performance counters, with this function you can iterate73/// through the samples collected.74/// @return The CPU timestamp associated to current sample, or 0 if there are no more samples75virtual uint64_t next() = 0;7677DrmDevice drm_device;7879/// List of counter groups80std::vector<CounterGroup> groups;8182/// List of counters exposed by the GPU83std::vector<Counter> counters;8485/// List of counters that are actually enabled86std::vector<Counter> enabled_counters;8788protected:89// Prevent object slicing by allowing move only from subclasses90Driver(Driver &&) = default;91Driver &operator=(Driver &&) = default;92};9394} // namespace pps959697