#include "base/task/common/task_annotator.h"
#include <stdint.h>
#include <algorithm>
#include <array>
#include <string_view>
#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/debug/alias.h"
#include "base/hash/md5.h"
#include "base/logging.h"
#include "base/metrics/metrics_hashes.h"
#include "base/ranges/algorithm.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
#include "base/tracing_buildflags.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
#if BUILDFLAG(ENABLE_BASE_TRACING)
#include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_mojo_event_info.pbzero.h"
#endif
namespace base {
namespace {
TaskAnnotator::ObserverForTesting* g_task_annotator_observer = …;
ABSL_CONST_INIT thread_local PendingTask* current_pending_task = …;
ABSL_CONST_INIT thread_local TaskAnnotator::ScopedSetIpcHash*
current_scoped_ipc_hash = …;
ABSL_CONST_INIT thread_local TaskAnnotator::LongTaskTracker*
current_long_task_tracker = …;
TaskAnnotator::ScopedSetIpcHash* GetCurrentScopedIpcHash() { … }
TaskAnnotator::LongTaskTracker* GetCurrentLongTaskTracker() { … }
#if BUILDFLAG(ENABLE_BASE_TRACING)
perfetto::protos::pbzero::ChromeTaskAnnotator::DelayPolicy ToProtoEnum(
subtle::DelayPolicy type) { … }
#endif
}
const PendingTask* TaskAnnotator::CurrentTaskForThread() { … }
void TaskAnnotator::OnIPCReceived(const char* interface_name,
uint32_t (*method_info)(),
bool is_response) { … }
void TaskAnnotator::MarkCurrentTaskAsInterestingForTracing() { … }
TaskAnnotator::TaskAnnotator() = default;
TaskAnnotator::~TaskAnnotator() = default;
void TaskAnnotator::WillQueueTask(perfetto::StaticString trace_event_name,
TaskMetadata* pending_task) { … }
void TaskAnnotator::RunTaskImpl(PendingTask& pending_task) { … }
uint64_t TaskAnnotator::GetTaskTraceID(const TaskMetadata& task) const { … }
void TaskAnnotator::RegisterObserverForTesting(ObserverForTesting* observer) { … }
void TaskAnnotator::ClearObserverForTesting() { … }
#if BUILDFLAG(ENABLE_BASE_TRACING)
void TaskAnnotator::EmitTaskLocation(perfetto::EventContext& ctx,
const PendingTask& task) { … }
void TaskAnnotator::MaybeEmitIncomingTaskFlow(perfetto::EventContext& ctx,
const PendingTask& task) const { … }
void TaskAnnotator::MaybeEmitDelayAndPolicy(perfetto::EventContext& ctx,
const PendingTask& task) { … }
void TaskAnnotator::MaybeEmitIPCHash(perfetto::EventContext& ctx,
const PendingTask& task) const { … }
#endif
TaskAnnotator::ScopedSetIpcHash::ScopedSetIpcHash(uint32_t ipc_hash)
: … { … }
TaskAnnotator::ScopedSetIpcHash::ScopedSetIpcHash(
const char* ipc_interface_name)
: … { … }
TaskAnnotator::ScopedSetIpcHash::ScopedSetIpcHash(
uint32_t ipc_hash,
const char* ipc_interface_name)
: … { … }
uint32_t TaskAnnotator::ScopedSetIpcHash::MD5HashMetricName(
std::string_view name) { … }
TaskAnnotator::ScopedSetIpcHash::~ScopedSetIpcHash() { … }
TaskAnnotator::LongTaskTracker::LongTaskTracker(const TickClock* tick_clock,
PendingTask& pending_task,
TaskAnnotator* task_annotator)
: … { … }
TaskAnnotator::LongTaskTracker::~LongTaskTracker() { … }
void TaskAnnotator::LongTaskTracker::SetIpcDetails(const char* interface_name,
uint32_t (*method_info)(),
bool is_response) { … }
void TaskAnnotator::LongTaskTracker::EmitReceivedIPCDetails(
perfetto::EventContext& ctx) { … }
void TaskAnnotator::LongTaskTracker::MaybeTraceInterestingTaskDetails() { … }
}