#include "content/browser/scheduler/responsiveness/calculator.h"
#include <algorithm>
#include <set>
#include <utility>
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
namespace content {
namespace responsiveness {
namespace {
constexpr auto kMeasurementPeriod = …;
constexpr auto kCongestionThreshold = …;
constexpr auto kSuspendInterval = …;
constexpr char kLatencyEventCategory[] = …;
constexpr char kCongestedIntervalEvent[] = …;
constexpr char kCongestedIntervalsMeasurementEvent[] = …;
void AddCongestedSlices(std::set<int>* congested_slices,
const Calculator::Congestion& congestion,
base::TimeTicks start_time,
base::TimeTicks end_time) { … }
}
Calculator::Congestion::Congestion(base::TimeTicks start_time,
base::TimeTicks end_time)
: … { … }
Calculator::Calculator(
std::unique_ptr<ResponsivenessCalculatorDelegate> delegate)
: … { … }
#endif
Calculator::~Calculator() { … }
void Calculator::TaskOrEventFinishedOnUIThread(
base::TimeTicks queue_time,
base::TimeTicks execution_start_time,
base::TimeTicks execution_finish_time) { … }
void Calculator::TaskOrEventFinishedOnIOThread(
base::TimeTicks queue_time,
base::TimeTicks execution_start_time,
base::TimeTicks execution_finish_time) { … }
void Calculator::OnFirstIdle() { … }
void Calculator::EmitResponsiveness(CongestionType congestion_type,
size_t num_congested_slices,
StartupStage startup_stage) { … }
void Calculator::EmitResponsivenessTraceEvents(
CongestionType congestion_type,
base::TimeTicks start_time,
base::TimeTicks end_time,
const std::set<int>& congested_slices) { … }
void Calculator::EmitCongestedIntervalsMeasurementTraceEvent(
base::TimeTicks start_time,
base::TimeTicks end_time,
size_t amount_of_slices) { … }
void Calculator::EmitCongestedIntervalTraceEvent(base::TimeTicks start_time,
base::TimeTicks end_time) { … }
base::TimeTicks Calculator::GetLastCalculationTime() { … }
void Calculator::CalculateResponsivenessIfNecessary(
base::TimeTicks current_time) { … }
void Calculator::CalculateResponsiveness(
CongestionType congestion_type,
std::vector<CongestionList> congestions_from_multiple_threads,
base::TimeTicks start_time,
base::TimeTicks end_time) { … }
Calculator::CongestionList& Calculator::GetExecutionCongestionOnUIThread() { … }
Calculator::CongestionList& Calculator::GetCongestionOnUIThread() { … }
#if BUILDFLAG(IS_ANDROID)
void Calculator::OnApplicationStateChanged(
base::android::ApplicationState state) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
switch (state) {
case base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES:
case base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES:
is_application_visible_ = true;
break;
case base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES:
case base::android::APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES:
is_application_visible_ = false;
break;
case base::android::APPLICATION_STATE_UNKNOWN:
break;
}
}
#endif
Calculator::CongestionList Calculator::TakeCongestionsOlderThanTime(
CongestionList* congestions,
base::TimeTicks end_time) { … }
}
}