#include "base/task/sequence_manager/thread_controller.h"
#include <atomic>
#include <string_view>
#include "base/check.h"
#include "base/feature_list.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
namespace base {
namespace sequence_manager {
namespace internal {
namespace {
BASE_FEATURE(…);
std::atomic<bool> g_thread_controller_sets_profiler_metadata{ … };
constexpr TimeDelta kNonTrivialActiveIntervalLength = …;
constexpr TimeDelta kMediumActiveIntervalLength = …;
std::string MakeSuffix(std::string_view time_suffix,
std::string_view thread_name) { … }
}
ThreadController::ThreadController(const TickClock* time_source)
: … { … }
ThreadController::~ThreadController() = default;
void ThreadController::SetTickClock(const TickClock* clock) { … }
ThreadController::RunLevelTracker::RunLevelTracker(
const ThreadController& outer)
: … { … }
ThreadController::RunLevelTracker::~RunLevelTracker() { … }
void ThreadController::InitializeFeatures(
features::EmitThreadControllerProfilerMetadata emit_profiler_metadata) { … }
bool ThreadController::RunLevelTracker::RunLevel::ShouldRecordSampleMetadata() { … }
std::string_view ThreadController::RunLevelTracker::RunLevel::GetThreadName() { … }
std::string
ThreadController::RunLevelTracker::RunLevel::GetSuffixForCatchAllHistogram() { … }
std::string ThreadController::RunLevelTracker::RunLevel::GetSuffixForHistogram(
TimeDelta duration) { … }
void ThreadController::EnableMessagePumpTimeKeeperMetrics(
const char* thread_name,
bool wall_time_based_metrics_enabled_for_testing) { … }
void ThreadController::RunLevelTracker::EnableTimeKeeperMetrics(
const char* thread_name,
bool wall_time_based_metrics_enabled_for_testing) { … }
void ThreadController::RunLevelTracker::TimeKeeper::EnableRecording(
const char* thread_name,
bool wall_time_based_metrics_enabled_for_testing) { … }
void ThreadController::RunLevelTracker::OnRunLoopStarted(State initial_state,
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::OnRunLoopEnded() { … }
void ThreadController::RunLevelTracker::OnWorkStarted(LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::OnApplicationTaskSelected(
TimeTicks queue_time,
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::OnWorkEnded(LazyNow& lazy_now,
int run_level_depth) { … }
void ThreadController::RunLevelTracker::OnIdle(LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::RecordScheduleWork() { … }
void ThreadController::RunLevelTracker::SetTraceObserverForTesting(
TraceObserverForTesting* trace_observer_for_testing) { … }
ThreadController::RunLevelTracker::TraceObserverForTesting*
ThreadController::RunLevelTracker::trace_observer_for_testing_ = …;
ThreadController::RunLevelTracker::RunLevel::RunLevel(State initial_state,
bool is_nested,
TimeKeeper& time_keeper,
LazyNow& lazy_now)
: … { … }
ThreadController::RunLevelTracker::RunLevel::~RunLevel() { … }
ThreadController::RunLevelTracker::RunLevel::RunLevel(RunLevel&& other) =
default;
void ThreadController::RunLevelTracker::RunLevel::LogPercentageMetric(
const char* name,
int percentage) { … }
void ThreadController::RunLevelTracker::RunLevel::LogPercentageMetric(
const char* name,
int percentage,
base::TimeDelta interval_duration) { … }
void ThreadController::RunLevelTracker::RunLevel::LogIntervalMetric(
const char* name,
base::TimeDelta value,
base::TimeDelta interval_duration) { … }
void ThreadController::RunLevelTracker::RunLevel::LogOnActiveMetrics(
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::RunLevel::LogOnIdleMetrics(
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::RunLevel::UpdateState(
State new_state,
LazyNow& lazy_now) { … }
ThreadController::RunLevelTracker::TimeKeeper::TimeKeeper(
const RunLevelTracker& outer)
: … { … }
void ThreadController::RunLevelTracker::TimeKeeper::RecordWakeUp(
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::TimeKeeper::OnApplicationTaskSelected(
TimeTicks queue_time,
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::TimeKeeper::RecordEndOfPhase(
Phase phase,
LazyNow& lazy_now) { … }
void ThreadController::RunLevelTracker::TimeKeeper::MaybeEmitIncomingWakeupFlow(
perfetto::EventContext& ctx) { … }
bool ThreadController::RunLevelTracker::TimeKeeper::ShouldRecordNow(
ShouldRecordReqs reqs) { … }
void ThreadController::RunLevelTracker::TimeKeeper::RecordTimeInPhase(
Phase phase,
TimeTicks phase_begin,
TimeTicks phase_end) { … }
const char* ThreadController::RunLevelTracker::TimeKeeper::PhaseToEventName(
Phase phase) { … }
}
}
}