#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/ui_devtools/tracing_agent.h"
#include <algorithm>
#include <memory>
#include <unordered_set>
#include <vector>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/process/process.h"
#include "base/timer/timer.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "components/ui_devtools/connector_delegate.h"
#include "components/ui_devtools/devtools_base_agent.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "services/tracing/public/cpp/perfetto/perfetto_config.h"
#include "services/tracing/public/cpp/tracing_features.h"
#include "services/tracing/public/mojom/constants.mojom.h"
#include "services/tracing/public/mojom/perfetto_service.mojom.h"
#include "third_party/inspector_protocol/crdtp/json.h"
namespace ui_devtools {
Response;
namespace {
const double kMinimumReportingInterval = …;
static bool g_any_agent_tracing = …;
base::trace_event::TraceConfig::ProcessFilterConfig CreateProcessFilterConfig(
base::ProcessId gpu_pid) { … }
}
class TracingAgent::DevToolsTraceEndpointProxy
: public base::RefCountedThreadSafe<DevToolsTraceEndpointProxy> { … };
class TracingAgent::PerfettoTracingSession
: public tracing::mojom::TracingSessionClient,
public mojo::DataPipeDrainer::Client { … };
TracingAgent::TracingAgent(std::unique_ptr<ConnectorDelegate> connector)
: … { … }
TracingAgent::~TracingAgent() = default;
namespace {
class TracingNotification : public crdtp::Serializable { … };
}
void TracingAgent::OnTraceDataCollected(
std::unique_ptr<std::string> trace_fragment) { … }
void TracingAgent::OnTraceComplete() { … }
void TracingAgent::start(
protocol::Maybe<std::string> categories,
protocol::Maybe<std::string> options,
protocol::Maybe<double> buffer_usage_reporting_interval,
std::unique_ptr<StartCallback> callback) { … }
Response TracingAgent::end() { … }
void TracingAgent::StartTracing(std::unique_ptr<StartCallback> callback) { … }
void TracingAgent::OnRecordingEnabled(std::unique_ptr<StartCallback> callback) { … }
void TracingAgent::EditTraceDataForFrontend() { … }
void TracingAgent::SetupTimer(double usage_reporting_interval) { … }
void TracingAgent::OnBufferUsage(float percent_full,
size_t approximate_event_count) { … }
void TracingAgent::UpdateBufferUsage() { … }
void TracingAgent::StopTracing(
const scoped_refptr<DevToolsTraceEndpointProxy>& endpoint,
const std::string& agent_label) { … }
std::string TracingAgent::UpdateTraceDataBuffer(
const std::string& trace_fragment) { … }
}