Path: blob/21.2-virgl/src/tool/pps/pps_datasource.h
7099 views
/*1* Copyright © 2019-2021 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 "pps.h"12#include "pps_driver.h"1314namespace pps15{16struct GpuIncrementalState {17bool was_cleared = true;18};1920struct GpuDataSourceTraits : public perfetto::DefaultDataSourceTraits {21using IncrementalStateType = GpuIncrementalState;22};2324class Driver;2526/// @brief This datasource samples performance counters at a specified rate.27/// Once the data is available, it sends a protobuf packet to the perfetto service.28/// At the very beginning, it sends a description of the counters.29/// After that, it sends counter values using the IDs set in the description.30class GpuDataSource : public perfetto::DataSource<GpuDataSource, GpuDataSourceTraits>31{32public:33void OnSetup(const SetupArgs &args) override;34void OnStart(const StartArgs &args) override;35void OnStop(const StopArgs &args) override;3637/// Blocks until the data source starts38static void wait_started();3940/// @brief Perfetto trace callback41static void trace_callback(TraceContext ctx);42static void register_data_source(const std::string &driver_name);4344void trace(TraceContext &ctx);4546private:47State state = State::Stop;4849/// Time between trace callbacks50std::chrono::nanoseconds time_to_sleep = std::chrono::nanoseconds(1000000);5152/// Used to check whether the datasource is quick enough53std::chrono::nanoseconds time_to_trace;5455/// A data source supports one driver at a time, but if you need more56/// than one gpu datasource you can just run another producer57Driver *driver = nullptr;5859/// Timestamp of packet sent with counter descriptors60uint64_t descriptor_timestamp = 0;61};6263} // namespace pps646566