#include "services/tracing/public/cpp/perfetto/track_event_thread_local_event_sink.h"
#include <algorithm>
#include <atomic>
#include <string_view>
#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/hash/hash.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/log_message.h"
#include "base/trace_event/trace_buffer.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_log.h"
#include "base/trace_event/traced_value.h"
#include "base/tracing/trace_time.h"
#include "base/tracing/tracing_tls.h"
#include "build/build_config.h"
#include "services/tracing/public/cpp/perfetto/perfetto_traced_process.h"
#include "services/tracing/public/cpp/perfetto/producer_client.h"
#include "services/tracing/public/cpp/perfetto/trace_event_data_source.h"
#include "services/tracing/public/cpp/perfetto/trace_string_lookup.h"
#include "services/tracing/public/cpp/perfetto/traced_value_proto_writer.h"
#include "third_party/perfetto/include/perfetto/tracing/internal/track_event_interned_fields.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"
#include "third_party/perfetto/include/perfetto/tracing/track_event_interned_data_index.h"
#include "third_party/perfetto/protos/perfetto/trace/clock_snapshot.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/trace_packet_defaults.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/debug_annotation.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/log_message.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/process_descriptor.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/source_location.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/task_execution.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/thread_descriptor.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/track_descriptor.pbzero.h"
TraceLog;
ChromeThreadDescriptor;
ClockSnapshot;
CounterDescriptor;
DebugAnnotation;
InternedData;
ThreadDescriptor;
TracePacket;
TracePacketDefaults;
TrackDescriptor;
TrackEvent;
TrackEventDefaults;
namespace tracing {
namespace {
const char* const kPrivacyFiltered = …;
constexpr uint32_t kClockIdAbsolute = …;
constexpr uint32_t kClockIdIncremental = …;
constexpr uint64_t kThreadTimeTrackUuidBit = …;
constexpr uint64_t kAbsoluteThreadTimeTrackUuidBit = …;
void AddConvertableToTraceFormat(
base::trace_event::ConvertableToTraceFormat* value,
perfetto::protos::pbzero::DebugAnnotation* annotation) { … }
void WriteDebugAnnotationValue(base::trace_event::TraceEvent* trace_event,
size_t arg_index,
DebugAnnotation* annotation) { … }
class LazyLegacyEventInitializer { … };
}
constexpr size_t TrackEventThreadLocalEventSink::kMaxCompleteEventDepth;
std::atomic<uint32_t>
TrackEventThreadLocalEventSink::incremental_state_reset_id_{ … };
TrackEventThreadLocalEventSink::TrackEventThreadLocalEventSink(
std::unique_ptr<perfetto::TraceWriter> trace_writer,
uint32_t session_id,
bool disable_interning,
bool proto_writer_filtering_enabled)
: … { … }
TrackEventThreadLocalEventSink::~TrackEventThreadLocalEventSink() { … }
void TrackEventThreadLocalEventSink::ClearIncrementalState() { … }
perfetto::TraceWriter::TracePacketHandle
TrackEventThreadLocalEventSink::NewTracePacket(PacketType packet_type) { … }
void TrackEventThreadLocalEventSink::AddLegacyTraceEvent(
base::trace_event::TraceEvent* trace_event,
base::trace_event::TraceEventHandle* handle) { … }
base::trace_event::TrackEventHandle
TrackEventThreadLocalEventSink::AddTypedTraceEvent(
base::trace_event::TraceEvent* trace_event) { … }
void TrackEventThreadLocalEventSink::WriteInternedDataIntoTracePacket(
TracePacket* packet) { … }
void TrackEventThreadLocalEventSink::OnTrackEventCompleted() { … }
base::trace_event::TracePacketHandle
TrackEventThreadLocalEventSink::AddTracePacket() { … }
void TrackEventThreadLocalEventSink::AddEmptyPacket() { … }
void TrackEventThreadLocalEventSink::OnTracePacketCompleted() { … }
void TrackEventThreadLocalEventSink::UpdateIncrementalStateIfNeeded(
base::trace_event::TraceEvent* trace_event) { … }
TrackEvent* TrackEventThreadLocalEventSink::PrepareTrackEvent(
base::trace_event::TraceEvent* trace_event,
base::trace_event::TraceEventHandle* handle,
protozero::MessageHandle<TracePacket>* trace_packet) { … }
void TrackEventThreadLocalEventSink::UpdateDuration(
const unsigned char* category_group_enabled,
const char* name,
base::trace_event::TraceEventHandle handle,
int thread_id,
bool explicit_timestamps,
const base::TimeTicks& now,
const base::ThreadTicks& thread_now) { … }
void TrackEventThreadLocalEventSink::Flush() { … }
void TrackEventThreadLocalEventSink::OnThreadNameChanged(const char* name) { … }
void TrackEventThreadLocalEventSink::EmitThreadTrackDescriptor(
base::trace_event::TraceEvent* trace_event,
base::TimeTicks timestamp,
const char* maybe_new_name) { … }
void TrackEventThreadLocalEventSink::EmitCounterTrackDescriptor(
base::TimeTicks timestamp,
uint64_t thread_track_uuid,
uint64_t counter_track_uuid_bit,
CounterDescriptor::BuiltinCounterType counter_type,
uint64_t unit_multiplier) { … }
void TrackEventThreadLocalEventSink::DoResetIncrementalState(
base::trace_event::TraceEvent* trace_event,
bool explicit_timestamp) { … }
void TrackEventThreadLocalEventSink::SetPacketTimestamp(
protozero::MessageHandle<TracePacket>* trace_packet,
base::TimeTicks timestamp,
bool force_absolute_timestamp) { … }
}