1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/resource_coordinator/tab_manager_stats_collector.h"
#include <cstdint>
#include <memory>
#include <unordered_set>
#include <utility>
#include "base/atomic_sequence_num.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_macros.h"
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom.h"
#include "chrome/browser/resource_coordinator/tab_helper.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_source.h"
#include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h"
#include "chrome/browser/resource_coordinator/time.h"
#include "chrome/browser/sessions/session_restore.h"
#include "components/metrics/system_memory_stats_recorder.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/swap_metrics_driver.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
namespace resource_coordinator {
namespace {
using LoadingState = TabLoadTracker::LoadingState;
const char* kSessionTypeName[] = {"SessionRestore", "BackgroundTabOpening"};
constexpr int kSamplingOdds = 10;
// Only report a subset of this metric as the volume is too high.
bool ShouldReportExpectedTaskQueueingDurationToUKM(
size_t background_tab_loading_count,
size_t background_tab_pending_count) {
size_t tab_count =
background_tab_loading_count + background_tab_pending_count;
DCHECK_GE(tab_count, 1u);
// We always collect this metric when we have 2 or more backgrounded loading
// or pending tabs (|tab_count|). And we sample the rest, i.e. when there is
// one tab loading in the background and no tabs pending, which is the less
// interesting majority. In this way, we cap the volume while keeping all
// interesting data.
if (tab_count > 1)
return true;
if (base::RandUint64() % kSamplingOdds == 0)
return true;
return false;
}
ukm::SourceId GetUkmSourceId(content::WebContents* contents) {
resource_coordinator::ResourceCoordinatorTabHelper* observer =
resource_coordinator::ResourceCoordinatorTabHelper::FromWebContents(
contents);
if (!observer)
return ukm::kInvalidSourceId;
return observer->ukm_source_id();
}
} // namespace
void TabManagerStatsCollector::BackgroundTabCountStats::Reset() {
tab_count = 0u;
tab_paused_count = 0u;
tab_load_auto_started_count = 0u;
tab_load_user_initiated_count = 0u;
}
class TabManagerStatsCollector::SwapMetricsDelegate
: public content::SwapMetricsDriver::Delegate {
public:
explicit SwapMetricsDelegate(
TabManagerStatsCollector* tab_manager_stats_collector,
SessionType type)
: tab_manager_stats_collector_(tab_manager_stats_collector),
session_type_(type) {}
~SwapMetricsDelegate() override = default;
void OnSwapInCount(uint64_t count, base::TimeDelta interval) override {
tab_manager_stats_collector_->RecordSwapMetrics(
session_type_, "SwapInPerSecond", count, interval);
}
void OnSwapOutCount(uint64_t count, base::TimeDelta interval) override {
tab_manager_stats_collector_->RecordSwapMetrics(
session_type_, "SwapOutPerSecond", count, interval);
}
void OnDecompressedPageCount(uint64_t count,
base::TimeDelta interval) override {
tab_manager_stats_collector_->RecordSwapMetrics(
session_type_, "DecompressedPagesPerSecond", count, interval);
}
void OnCompressedPageCount(uint64_t count,
base::TimeDelta interval) override {
tab_manager_stats_collector_->RecordSwapMetrics(
session_type_, "CompressedPagesPerSecond", count, interval);
}
void OnUpdateMetricsFailed() override {
tab_manager_stats_collector_->OnUpdateSwapMetricsFailed();
}
private:
TabManagerStatsCollector* tab_manager_stats_collector_;
const SessionType session_type_;
};
TabManagerStatsCollector::TabManagerStatsCollector() : weak_factory_(this) {
SessionRestore::AddObserver(this);
// Post an after startup task that starts the periodic sampling of freezing
// and discarding stats.
content::BrowserThread::PostAfterStartupTask(
FROM_HERE, base::SequencedTaskRunnerHandle::Get(),
base::BindOnce(&TabManagerStatsCollector::StartPeriodicSampling,
weak_factory_.GetWeakPtr()));
}
TabManagerStatsCollector::~TabManagerStatsCollector() {
SessionRestore::RemoveObserver(this);
}
void TabManagerStatsCollector::RecordWillDiscardUrgently(int num_alive_tabs) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::TimeTicks discard_time = NowTicks();
UMA_HISTOGRAM_COUNTS_100("Discarding.Urgent.NumAliveTabs", num_alive_tabs);
if (last_urgent_discard_time_.is_null()) {
UMA_HISTOGRAM_CUSTOM_TIMES(
"Discarding.Urgent.TimeSinceStartup", discard_time - start_time_,
base::TimeDelta::FromSeconds(1), base::TimeDelta::FromDays(1), 50);
} else {
UMA_HISTOGRAM_CUSTOM_TIMES("Discarding.Urgent.TimeSinceLastUrgent",
discard_time - last_urgent_discard_time_,
base::TimeDelta::FromMilliseconds(100),
base::TimeDelta::FromDays(1), 50);
}
// TODO(fdoray): Remove this #if when RecordMemoryStats is implemented for all
// platforms.
#if defined(OS_WIN) || defined(OS_CHROMEOS)
// Record system memory usage at the time of the discard.
metrics::RecordMemoryStats(metrics::RECORD_MEMORY_STATS_TAB_DISCARDED);
#endif
last_urgent_discard_time_ = discard_time;
}
void TabManagerStatsCollector::RecordSwitchToTab(
content::WebContents* old_contents,
content::WebContents* new_contents) {
if (!is_session_restore_loading_tabs_ &&
!is_in_background_tab_opening_session_) {
return;
}
if (IsInOverlappedSession())
return;
auto* new_data = TabManager::WebContentsData::FromWebContents(new_contents);
DCHECK(new_data);
if (is_session_restore_loading_tabs_) {
UMA_HISTOGRAM_ENUMERATION(
kHistogramSessionRestoreSwitchToTab,
static_cast<int32_t>(new_data->tab_loading_state()),
static_cast<int32_t>(LoadingState::kMaxValue) + 1);
}
if (is_in_background_tab_opening_session_) {
UMA_HISTOGRAM_ENUMERATION(
kHistogramBackgroundTabOpeningSwitchToTab,
static_cast<int32_t>(new_data->tab_loading_state()),
static_cast<int32_t>(LoadingState::kMaxValue) + 1);
}
if (old_contents)
foreground_contents_switched_to_times_.erase(old_contents);
DCHECK(
!base::ContainsKey(foreground_contents_switched_to_times_, new_contents));
if (new_data->tab_loading_state() != LoadingState::LOADED) {
foreground_contents_switched_to_times_.insert(
std::make_pair(new_contents, NowTicks()));
}
}
void TabManagerStatsCollector::RecordExpectedTaskQueueingDuration(
content::WebContents* contents,
base::TimeDelta queueing_time) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(fdoray): Consider not recording this for occluded tabs.
if (contents->GetVisibility() == content::Visibility::HIDDEN)
return;
if (IsInOverlappedSession())
return;
ukm::SourceId ukm_source_id = GetUkmSourceId(contents);
if (is_session_restore_loading_tabs_) {
UMA_HISTOGRAM_TIMES(
kHistogramSessionRestoreForegroundTabExpectedTaskQueueingDuration,
queueing_time);
size_t restored_tab_count =
g_browser_process->GetTabManager()->restored_tab_count();
if (ukm_source_id != ukm::kInvalidSourceId && restored_tab_count > 1) {
ukm::builders::
TabManager_SessionRestore_ForegroundTab_ExpectedTaskQueueingDurationInfo(
ukm_source_id)
.SetExpectedTaskQueueingDuration(queueing_time.InMilliseconds())
.SetSequenceId(sequence_++)
.SetSessionRestoreSessionId(session_id_)
.SetSessionRestoreTabCount(restored_tab_count)
.SetSystemTabCount(
g_browser_process->GetTabManager()->GetTabCount())
.Record(ukm::UkmRecorder::Get());
}
}
if (is_in_background_tab_opening_session_) {
UMA_HISTOGRAM_TIMES(
kHistogramBackgroundTabOpeningForegroundTabExpectedTaskQueueingDuration,
queueing_time);
size_t background_tab_loading_count =
g_browser_process->GetTabManager()->GetBackgroundTabLoadingCount();
size_t background_tab_pending_count =
g_browser_process->GetTabManager()->GetBackgroundTabPendingCount();
if (ukm_source_id != ukm::kInvalidSourceId &&
ShouldReportExpectedTaskQueueingDurationToUKM(
background_tab_loading_count, background_tab_pending_count)) {
ukm::builders::
TabManager_BackgroundTabOpening_ForegroundTab_ExpectedTaskQueueingDurationInfo(
ukm_source_id)
.SetBackgroundTabLoadingCount(background_tab_loading_count)
.SetBackgroundTabOpeningSessionId(session_id_)
.SetBackgroundTabPendingCount(background_tab_pending_count)
.SetExpectedTaskQueueingDuration(queueing_time.InMilliseconds())
.SetSequenceId(sequence_++)
.SetSystemTabCount(
g_browser_process->GetTabManager()->GetTabCount())
.Record(ukm::UkmRecorder::Get());
}
}
}
void TabManagerStatsCollector::RecordBackgroundTabCount() {
DCHECK(is_in_background_tab_opening_session_);
if (!is_overlapping_background_tab_opening_) {
UMA_HISTOGRAM_COUNTS_100(kHistogramBackgroundTabOpeningTabCount,
background_tab_count_stats_.tab_count);
UMA_HISTOGRAM_COUNTS_100(kHistogramBackgroundTabOpeningTabPausedCount,
background_tab_count_stats_.tab_paused_count);
UMA_HISTOGRAM_COUNTS_100(
kHistogramBackgroundTabOpeningTabLoadAutoStartedCount,
background_tab_count_stats_.tab_load_auto_started_count);
UMA_HISTOGRAM_COUNTS_100(
kHistogramBackgroundTabOpeningTabLoadUserInitiatedCount,
background_tab_count_stats_.tab_load_user_initiated_count);
}
}
void TabManagerStatsCollector::OnSessionRestoreStartedLoadingTabs() {
DCHECK(!is_session_restore_loading_tabs_);
UpdateSessionAndSequence();
CreateAndInitSwapMetricsDriverIfNeeded(SessionType::kSessionRestore);
is_session_restore_loading_tabs_ = true;
ClearStatsWhenInOverlappedSession();
}
void TabManagerStatsCollector::OnSessionRestoreFinishedLoadingTabs() {
DCHECK(is_session_restore_loading_tabs_);
UMA_HISTOGRAM_BOOLEAN(kHistogramSessionOverlapSessionRestore,
is_overlapping_session_restore_ ? true : false);
if (swap_metrics_driver_)
swap_metrics_driver_->UpdateMetrics();
is_session_restore_loading_tabs_ = false;
is_overlapping_session_restore_ = false;
}
void TabManagerStatsCollector::OnBackgroundTabOpeningSessionStarted() {
DCHECK(!is_in_background_tab_opening_session_);
UpdateSessionAndSequence();
background_tab_count_stats_.Reset();
CreateAndInitSwapMetricsDriverIfNeeded(SessionType::kBackgroundTabOpening);
is_in_background_tab_opening_session_ = true;
ClearStatsWhenInOverlappedSession();
}
void TabManagerStatsCollector::OnBackgroundTabOpeningSessionEnded() {
DCHECK(is_in_background_tab_opening_session_);
UMA_HISTOGRAM_BOOLEAN(kHistogramSessionOverlapBackgroundTabOpening,
is_overlapping_background_tab_opening_ ? true : false);
if (swap_metrics_driver_)
swap_metrics_driver_->UpdateMetrics();
RecordBackgroundTabCount();
is_in_background_tab_opening_session_ = false;
is_overlapping_background_tab_opening_ = false;
}
void TabManagerStatsCollector::CreateAndInitSwapMetricsDriverIfNeeded(
SessionType type) {
if (IsInOverlappedSession()) {
swap_metrics_driver_ = nullptr;
return;
}
// Always create a new instance in case there is a SessionType change because
// this is shared between SessionRestore and BackgroundTabOpening.
swap_metrics_driver_ = content::SwapMetricsDriver::Create(
base::WrapUnique<content::SwapMetricsDriver::Delegate>(
new SwapMetricsDelegate(this, type)),
base::TimeDelta::FromSeconds(0));
// The driver could still be null on a platform with no swap driver support.
if (swap_metrics_driver_)
swap_metrics_driver_->InitializeMetrics();
}
void TabManagerStatsCollector::RecordSwapMetrics(SessionType type,
const std::string& metric_name,
uint64_t count,
base::TimeDelta interval) {
base::HistogramBase* histogram = base::Histogram::FactoryGet(
"TabManager.Experimental." + std::string(kSessionTypeName[type]) + "." +
metric_name,
1, // minimum
10000, // maximum
50, // bucket_count
base::HistogramBase::kUmaTargetedHistogramFlag);
histogram->Add(static_cast<double>(count) / interval.InSecondsF());
}
void TabManagerStatsCollector::OnUpdateSwapMetricsFailed() {
swap_metrics_driver_ = nullptr;
}
void TabManagerStatsCollector::OnDidStartMainFrameNavigation(
content::WebContents* contents) {
foreground_contents_switched_to_times_.erase(contents);
}
void TabManagerStatsCollector::OnWillLoadNextBackgroundTab(bool timeout) {
UMA_HISTOGRAM_BOOLEAN(kHistogramBackgroundTabOpeningTabLoadTimeout, timeout);
}
void TabManagerStatsCollector::OnTabIsLoaded(content::WebContents* contents) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!base::ContainsKey(foreground_contents_switched_to_times_, contents))
return;
base::TimeDelta switch_load_time =
NowTicks() - foreground_contents_switched_to_times_[contents];
ukm::SourceId ukm_source_id = GetUkmSourceId(contents);
if (is_session_restore_loading_tabs_ && !IsInOverlappedSession()) {
UMA_HISTOGRAM_MEDIUM_TIMES(kHistogramSessionRestoreTabSwitchLoadTime,
switch_load_time);
if (ukm_source_id != ukm::kInvalidSourceId) {
ukm::builders::
TabManager_Experimental_SessionRestore_TabSwitchLoadStopped(
ukm_source_id)
.SetSequenceId(sequence_++)
.SetSessionRestoreSessionId(session_id_)
.SetSessionRestoreTabCount(
g_browser_process->GetTabManager()->restored_tab_count())
.SetSystemTabCount(
g_browser_process->GetTabManager()->GetTabCount())
.SetTabSwitchLoadTime(switch_load_time.InMilliseconds())
.Record(ukm::UkmRecorder::Get());
}
}
if (is_in_background_tab_opening_session_ && !IsInOverlappedSession()) {
UMA_HISTOGRAM_MEDIUM_TIMES(kHistogramBackgroundTabOpeningTabSwitchLoadTime,
switch_load_time);
if (ukm_source_id != ukm::kInvalidSourceId) {
ukm::builders::
TabManager_Experimental_BackgroundTabOpening_TabSwitchLoadStopped(
ukm_source_id)
.SetBackgroundTabLoadingCount(
g_browser_process->GetTabManager()
->GetBackgroundTabLoadingCount())
.SetBackgroundTabOpeningSessionId(session_id_)
.SetBackgroundTabPendingCount(
g_browser_process->GetTabManager()
->GetBackgroundTabPendingCount())
.SetSequenceId(sequence_++)
.SetSystemTabCount(
g_browser_process->GetTabManager()->GetTabCount())
.SetTabSwitchLoadTime(switch_load_time.InMilliseconds())
.Record(ukm::UkmRecorder::Get());
}
}
foreground_contents_switched_to_times_.erase(contents);
}
void TabManagerStatsCollector::OnWebContentsDestroyed(
content::WebContents* contents) {
foreground_contents_switched_to_times_.erase(contents);
}
bool TabManagerStatsCollector::IsInOverlappedSession() {
return is_session_restore_loading_tabs_ &&
is_in_background_tab_opening_session_;
}
void TabManagerStatsCollector::ClearStatsWhenInOverlappedSession() {
if (!IsInOverlappedSession())
return;
swap_metrics_driver_ = nullptr;
foreground_contents_switched_to_times_.clear();
background_tab_count_stats_.Reset();
is_overlapping_session_restore_ = true;
is_overlapping_background_tab_opening_ = true;
}
void TabManagerStatsCollector::UpdateSessionAndSequence() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// This function is used by both SessionRestore and BackgroundTabOpening. This
// is fine because we do not report any metric when those two overlap.
++session_id_;
sequence_ = 0;
}
void TabManagerStatsCollector::StartPeriodicSampling() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Post a first task with a random delay less than the sampling interval.
base::TimeDelta delay = base::TimeDelta::FromSeconds(
base::RandInt(0, kLowFrequencySamplingInterval.InSeconds()));
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&TabManagerStatsCollector::PerformPeriodicSample,
weak_factory_.GetWeakPtr()),
delay);
}
void TabManagerStatsCollector::PerformPeriodicSample() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
sample_start_time_ = NowTicks();
// Iterate over the tabs and get their data. The TabManager owns us and
// outlives us, so will always exist.
LifecycleUnitVector lifecycle_units =
g_browser_process->GetTabManager()->GetSortedLifecycleUnits();
for (auto* lifecycle_unit : lifecycle_units) {
DecisionDetails freeze_decision;
lifecycle_unit->CanFreeze(&freeze_decision);
RecordDecisionDetails(lifecycle_unit, freeze_decision,
LifecycleUnitState::FROZEN);
DecisionDetails discard_decision;
lifecycle_unit->CanDiscard(LifecycleUnitDiscardReason::PROACTIVE,
&discard_decision);
RecordDecisionDetails(lifecycle_unit, discard_decision,
LifecycleUnitState::DISCARDED);
}
// Determine when the next sample should run based on when this cycle
// started.
base::TimeDelta delay =
(sample_start_time_ + kLowFrequencySamplingInterval) - NowTicks();
// In the very unlikely case that the system is so busy that another sample
// should already have been taken, then skip a cycle and wait a full sampling
// period. This provides rudimentary rate limiting that prevents these samples
// from taking up too much time.
if (delay <= base::TimeDelta())
delay = kLowFrequencySamplingInterval;
// Schedule the next sample.
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&TabManagerStatsCollector::PerformPeriodicSample,
weak_factory_.GetWeakPtr()),
delay);
}
// static
void TabManagerStatsCollector::RecordDecisionDetails(
LifecycleUnit* lifecycle_unit,
const DecisionDetails& decision_details,
LifecycleUnitState target_state) {
ukm::SourceId ukm_source_id = lifecycle_unit->GetUkmSourceId();
if (ukm_source_id == ukm::kInvalidSourceId)
return;
// Don't log anything for invalid decision details (trivial reasons: crashed
// tabs, navigations not yet committed, etc).
if (decision_details.reasons().empty())
return;
ukm::builders::TabManager_LifecycleStateChange builder(ukm_source_id);
builder.SetOldLifecycleState(
static_cast<int64_t>(lifecycle_unit->GetState()));
builder.SetNewLifecycleState(static_cast<int64_t>(target_state));
// No LifecycleStateChangeReason is set right now, indicating that this is a
// theoretical state change rather than an actual one. This differentiates
// sampled lifecycle transitions from actual ones.
// We only currently report transitions for tabs, so this lookup should never
// fail. It will start failing once we add ARC processes as LifecycleUnits.
// TODO(chrisha): This should be time since the navigation was committed (the
// load started), but that information is currently only persisted inside the
// CU-graph. Using time since navigation finished is a cheap approximation for
// the time being.
auto* tab = lifecycle_unit->AsTabLifecycleUnitExternal();
auto* contents = tab->GetWebContents();
auto* nav_entry = contents->GetController().GetLastCommittedEntry();
if (nav_entry) {
auto timestamp = nav_entry->GetTimestamp();
if (!timestamp.is_null()) {
auto elapsed = base::Time::Now() - timestamp;
builder.SetTimeSinceNavigationMs(elapsed.InMilliseconds());
}
}
// Set visibility related data.
// |time_since_visible| is:
// - Zero if the LifecycleUnit is currently visible.
// - Time since creation if the LifecycleUnit was never visible.
// - Time since visible if the LifecycleUnit was visible in the past.
auto visibility = lifecycle_unit->GetVisibility();
base::TimeDelta time_since_visible; // Zero.
if (visibility != content::Visibility::VISIBLE)
time_since_visible = NowTicks() - lifecycle_unit->GetWallTimeWhenHidden();
builder.SetTimeSinceVisibilityStateChangeMs(
time_since_visible.InMilliseconds());
builder.SetVisibilityState(static_cast<int64_t>(visibility));
// This populates all of the relevant Success/Failure fields, as well as
// Outcome.
decision_details.Populate(&builder);
builder.Record(ukm::UkmRecorder::Get());
}
// static
const char TabManagerStatsCollector::
kHistogramSessionRestoreForegroundTabExpectedTaskQueueingDuration[] =
"TabManager.SessionRestore.ForegroundTab.ExpectedTaskQueueingDuration";
// static
const char TabManagerStatsCollector::
kHistogramBackgroundTabOpeningForegroundTabExpectedTaskQueueingDuration[] =
"TabManager.BackgroundTabOpening.ForegroundTab."
"ExpectedTaskQueueingDuration";
// static
const char TabManagerStatsCollector::kHistogramSessionRestoreSwitchToTab[] =
"TabManager.SessionRestore.SwitchToTab";
// static
const char
TabManagerStatsCollector::kHistogramBackgroundTabOpeningSwitchToTab[] =
"TabManager.BackgroundTabOpening.SwitchToTab";
// static
const char
TabManagerStatsCollector::kHistogramSessionRestoreTabSwitchLoadTime[] =
"TabManager.Experimental.SessionRestore.TabSwitchLoadTime."
"UntilTabIsLoaded";
// static
const char TabManagerStatsCollector::
kHistogramBackgroundTabOpeningTabSwitchLoadTime[] =
"TabManager.Experimental.BackgroundTabOpening.TabSwitchLoadTime."
"UntilTabIsLoaded";
// static
const char TabManagerStatsCollector::kHistogramBackgroundTabOpeningTabCount[] =
"TabManager.BackgroundTabOpening.TabCount";
// static
const char
TabManagerStatsCollector::kHistogramBackgroundTabOpeningTabPausedCount[] =
"TabManager.BackgroundTabOpening.TabPausedCount";
// static
const char TabManagerStatsCollector::
kHistogramBackgroundTabOpeningTabLoadAutoStartedCount[] =
"TabManager.BackgroundTabOpening.TabLoadAutoStartedCount";
// static
const char TabManagerStatsCollector::
kHistogramBackgroundTabOpeningTabLoadUserInitiatedCount[] =
"TabManager.BackgroundTabOpening.TabLoadUserInitiatedCount";
// static
const char
TabManagerStatsCollector::kHistogramBackgroundTabOpeningTabLoadTimeout[] =
"TabManager.BackgroundTabOpening.TabLoadTimeout";
// static
const char TabManagerStatsCollector::kHistogramSessionOverlapSessionRestore[] =
"TabManager.SessionOverlap.SessionRestore";
// static
const char
TabManagerStatsCollector::kHistogramSessionOverlapBackgroundTabOpening[] =
"TabManager.SessionOverlap.BackgroundTabOpening";
// static
constexpr base::TimeDelta TabManagerStatsCollector::kLowFrequencySamplingInterval;
} // namespace resource_coordinator
|