chromium/services/tracing/public/cpp/perfetto/trace_event_data_source.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/tracing/public/cpp/perfetto/trace_event_data_source.h"

#include <atomic>
#include <map>
#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/stack_allocated.h"
#include "base/no_destructor.h"
#include "base/process/current_process.h"
#include "base/sequence_checker.h"
#include "base/strings/pattern.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/common/scoped_defer_task_posting.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_config.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_log.h"
#include "base/tracing/trace_time.h"
#include "base/tracing/tracing_tls.h"
#include "build/build_config.h"
#include "components/tracing/common/tracing_switches.h"
#include "services/tracing/public/cpp/perfetto/custom_event_recorder.h"
#include "services/tracing/public/cpp/perfetto/macros.h"
#include "services/tracing/public/cpp/perfetto/perfetto_producer.h"
#include "services/tracing/public/cpp/perfetto/perfetto_traced_process.h"
#include "services/tracing/public/cpp/perfetto/system_producer.h"
#include "services/tracing/public/cpp/perfetto/trace_string_lookup.h"
#include "services/tracing/public/cpp/perfetto/track_event_thread_local_event_sink.h"
#include "services/tracing/public/cpp/perfetto/track_name_recorder.h"
#include "services/tracing/public/cpp/trace_event_args_allowlist.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "services/tracing/public/mojom/constants.mojom.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_arbiter.h"
#include "third_party/perfetto/include/perfetto/ext/tracing/core/trace_writer.h"
#include "third_party/perfetto/include/perfetto/protozero/message.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"
#include "third_party/perfetto/protos/perfetto/trace/chrome/chrome_metadata.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/chrome/chrome_trace_event.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/process_descriptor.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/track_descriptor.pbzero.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif

TraceLog;
TraceEvent;
TraceConfig;
TracePacketHandle;
TraceRecordMode;
ChromeMetadataPacket;
ChromeProcessDescriptor;
ProcessDescriptor;
TrackDescriptor;

namespace tracing {
namespace {

TraceEventMetadataSource* g_trace_event_metadata_source_for_testing =;

static_assert;

// Helper class used to ensure no tasks are posted while
// TraceEventDataSource::lock_ is held.
class SCOPED_LOCKABLE AutoLockWithDeferredTaskPosting {};

}  // namespace

ChromeEventBundle;
ChromeEventBundleHandle;

// static
TraceEventMetadataSource* TraceEventMetadataSource::GetInstance() {}

TraceEventMetadataSource::TraceEventMetadataSource()
    :{}

TraceEventMetadataSource::~TraceEventMetadataSource() = default;

void TraceEventMetadataSource::AddGeneratorFunction(
    JsonMetadataGeneratorFunction generator) {}

void TraceEventMetadataSource::AddGeneratorFunction(
    MetadataGeneratorFunction generator) {}

void TraceEventMetadataSource::AddGeneratorFunction(
    PacketGeneratorFunction generator) {}

void TraceEventMetadataSource::WriteMetadataPacket(
    perfetto::protos::pbzero::ChromeMetadataPacket* metadata_proto,
    bool privacy_filtering_enabled) {}

std::optional<base::Value::Dict>
TraceEventMetadataSource::GenerateTraceConfigMetadataDict() {}

void TraceEventMetadataSource::GenerateMetadataFromGenerator(
    const TraceEventMetadataSource::MetadataGeneratorFunction& generator) {}

void TraceEventMetadataSource::GenerateMetadataPacket(
    const TraceEventMetadataSource::PacketGeneratorFunction& generator) {}

void TraceEventMetadataSource::GenerateJsonMetadataFromGenerator(
    const TraceEventMetadataSource::JsonMetadataGeneratorFunction& generator,
    ChromeEventBundle* event_bundle) {}

void TraceEventMetadataSource::GenerateMetadata(
    std::unique_ptr<
        std::vector<TraceEventMetadataSource::JsonMetadataGeneratorFunction>>
        json_generators,
    std::unique_ptr<
        std::vector<TraceEventMetadataSource::MetadataGeneratorFunction>>
        proto_generators,
    std::unique_ptr<
        std::vector<TraceEventMetadataSource::PacketGeneratorFunction>>
        packet_generators) {}

void TraceEventMetadataSource::StartTracingImpl(
    PerfettoProducer* producer,
    const perfetto::DataSourceConfig& data_source_config) {}

void TraceEventMetadataSource::StopTracingImpl(
    base::OnceClosure stop_complete_callback) {}

void TraceEventMetadataSource::Flush(
    base::RepeatingClosure flush_complete_callback) {}

base::SequencedTaskRunner* TraceEventMetadataSource::GetTaskRunner() {}

void TraceEventMetadataSource::ResetForTesting() {}

namespace {

base::ThreadLocalStorage::Slot* ThreadLocalEventSinkSlot() {}

TraceEventDataSource* g_trace_event_data_source_for_testing =;

}  // namespace

// static
TraceEventDataSource* TraceEventDataSource::GetInstance() {}

// static
void TraceEventDataSource::ResetForTesting() {}

TraceEventDataSource::TraceEventDataSource()
    :{}

TraceEventDataSource::~TraceEventDataSource() = default;

void TraceEventDataSource::RegisterStartupHooks() {}

void TraceEventDataSource::RegisterWithTraceLog() {}

void TraceEventDataSource::OnStopTracingDone() {}

// static
TrackEventThreadLocalEventSink* TraceEventDataSource::GetOrPrepareEventSink(bool create_if_needed) {}

bool TraceEventDataSource::IsEnabled() {}

void TraceEventDataSource::SetupStartupTracing(
    PerfettoProducer* producer,
    const base::trace_event::TraceConfig& trace_config,
    bool privacy_filtering_enabled) {}

void TraceEventDataSource::AbortStartupTracing() {}

uint32_t
TraceEventDataSource::IncrementSessionIdOrClearStartupFlagWhileLocked() {}

void TraceEventDataSource::SetStartupTracingFlagsWhileLocked() {}

bool TraceEventDataSource::IsStartupTracingActive() const {}

void TraceEventDataSource::OnFlushFinished(
    const scoped_refptr<base::RefCountedString>&,
    bool has_more_events) {}

void TraceEventDataSource::StartTracingImpl(
    PerfettoProducer* producer,
    const perfetto::DataSourceConfig& data_source_config) {}

void TraceEventDataSource::StartTracingInternal(
    PerfettoProducer* producer,
    const perfetto::DataSourceConfig& data_source_config) {}

void TraceEventDataSource::StopTracingImpl(
    base::OnceClosure stop_complete_callback) {}

void TraceEventDataSource::Flush(
    base::RepeatingClosure flush_complete_callback) {}

void TraceEventDataSource::ClearIncrementalState() {}

std::unique_ptr<perfetto::TraceWriter>
TraceEventDataSource::CreateTraceWriterLocked() {}

TrackEventThreadLocalEventSink*
TraceEventDataSource::CreateThreadLocalEventSink() {}

// static
void TraceEventDataSource::OnAddLegacyTraceEvent(
    TraceEvent* trace_event,
    bool thread_will_flush,
    base::trace_event::TraceEventHandle* handle) {}

// static
base::trace_event::TrackEventHandle TraceEventDataSource::OnAddTypedTraceEvent(
    base::trace_event::TraceEvent* trace_event) {}

// static
void TraceEventDataSource::OnUpdateDuration(
    const unsigned char* category_group_enabled,
    const char* name,
    base::trace_event::TraceEventHandle handle,
    base::PlatformThreadId thread_id,
    bool explicit_timestamps,
    const base::TimeTicks& now,
    const base::ThreadTicks& thread_now) {}

// static
base::trace_event::TracePacketHandle TraceEventDataSource::OnAddTracePacket() {}

// static
void TraceEventDataSource::OnAddEmptyPacket() {}

// static
void TraceEventDataSource::FlushCurrentThread() {}

void TraceEventDataSource::ReturnTraceWriter(
    std::unique_ptr<perfetto::TraceWriter> trace_writer) {}

void TraceEventDataSource::EmitRecurringUpdates() {}

void TraceEventDataSource::EmitTrackDescriptor() {}

bool TraceEventDataSource::IsPrivacyFilteringEnabled() {}

}  // namespace tracing

PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS_WITH_ATTRS(
    COMPONENT_EXPORT(TRACING_CPP),
    tracing::TraceEventMetadataSource::DataSourceProxy);