#include "services/tracing/perfetto/consumer_host.h"
#include <cstring>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/trace_event/trace_log.h"
#include "base/values.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/wait.h"
#include "services/tracing/perfetto/perfetto_service.h"
#include "services/tracing/perfetto/privacy_filtering_check.h"
#include "services/tracing/public/cpp/perfetto/perfetto_session.h"
#include "services/tracing/public/cpp/trace_event_args_allowlist.h"
#include "third_party/perfetto/include/perfetto/ext/trace_processor/export_json.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/observable_events.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/slice.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_packet.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_stats.h"
#include "third_party/perfetto/include/perfetto/trace_processor/basic_types.h"
#include "third_party/perfetto/include/perfetto/trace_processor/trace_processor_storage.h"
#include "third_party/perfetto/include/perfetto/tracing/core/trace_config.h"
#include "third_party/perfetto/protos/perfetto/config/trace_config.pb.h"
namespace tracing {
namespace {
const int32_t kEnableTracingTimeoutSeconds = …;
class JsonStringOutputWriter
: public perfetto::trace_processor::json::OutputWriter { … };
}
class ConsumerHost::StreamWriter { … };
ConsumerHost::TracingSession::TracingSession(
ConsumerHost* host,
mojo::PendingReceiver<mojom::TracingSessionHost> tracing_session_host,
mojo::PendingRemote<mojom::TracingSessionClient> tracing_session_client,
const perfetto::TraceConfig& trace_config,
perfetto::base::ScopedFile output_file,
mojom::TracingClientPriority priority)
: … { … }
ConsumerHost::TracingSession::~TracingSession() { … }
void ConsumerHost::TracingSession::OnPerfettoEvents(
const perfetto::ObservableEvents& events) { … }
void ConsumerHost::TracingSession::OnActiveServicePidAdded(
base::ProcessId pid) { … }
void ConsumerHost::TracingSession::OnActiveServicePidRemoved(
base::ProcessId pid) { … }
void ConsumerHost::TracingSession::OnActiveServicePidsInitialized() { … }
void ConsumerHost::TracingSession::RequestDisableTracing(
base::OnceClosure on_disabled_callback) { … }
void ConsumerHost::TracingSession::OnEnableTracingTimeout() { … }
void ConsumerHost::TracingSession::MaybeSendEnableTracingAck() { … }
bool ConsumerHost::TracingSession::IsExpectedPid(base::ProcessId pid) const { … }
void ConsumerHost::TracingSession::ChangeTraceConfig(
const perfetto::TraceConfig& trace_config) { … }
void ConsumerHost::TracingSession::DisableTracing() { … }
void ConsumerHost::TracingSession::OnTracingDisabled(const std::string& error) { … }
void ConsumerHost::TracingSession::OnConsumerClientDisconnected() { … }
void ConsumerHost::TracingSession::ReadBuffers(
mojo::ScopedDataPipeProducerHandle stream,
ReadBuffersCallback callback) { … }
void ConsumerHost::TracingSession::RequestBufferUsage(
RequestBufferUsageCallback callback) { … }
void ConsumerHost::TracingSession::DisableTracingAndEmitJson(
const std::string& agent_label_filter,
mojo::ScopedDataPipeProducerHandle stream,
bool privacy_filtering_enabled,
DisableTracingAndEmitJsonCallback callback) { … }
void ConsumerHost::TracingSession::ExportJson() { … }
void ConsumerHost::TracingSession::OnJSONTraceData(std::string json,
bool has_more) { … }
void ConsumerHost::TracingSession::OnTraceData(
std::vector<perfetto::TracePacket> packets,
bool has_more) { … }
void ConsumerHost::TracingSession::OnTraceStats(
bool success,
const perfetto::TraceStats& stats) { … }
void ConsumerHost::TracingSession::Flush(
uint32_t timeout,
base::OnceCallback<void(bool)> callback) { … }
void ConsumerHost::BindConsumerReceiver(
PerfettoService* service,
mojo::PendingReceiver<mojom::ConsumerHost> receiver) { … }
ConsumerHost::ConsumerHost(PerfettoService* service) : … { … }
ConsumerHost::~ConsumerHost() { … }
void ConsumerHost::EnableTracing(
mojo::PendingReceiver<mojom::TracingSessionHost> tracing_session_host,
mojo::PendingRemote<mojom::TracingSessionClient> tracing_session_client,
const perfetto::TraceConfig& trace_config,
base::File output_file) { … }
void ConsumerHost::OnConnect() { … }
void ConsumerHost::OnDisconnect() { … }
void ConsumerHost::OnTracingDisabled(const std::string& error) { … }
void ConsumerHost::OnTraceData(std::vector<perfetto::TracePacket> packets,
bool has_more) { … }
void ConsumerHost::OnObservableEvents(
const perfetto::ObservableEvents& events) { … }
void ConsumerHost::OnTraceStats(bool success,
const perfetto::TraceStats& stats) { … }
void ConsumerHost::OnSessionCloned(const OnSessionClonedArgs&) { … }
void ConsumerHost::DestructTracingSession() { … }
}