mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-15 05:00:02 -10:00
This telemetry was trying to measure three things:
* The time spent during style / layout in a tick. This is useful.
* The times SetNeed{Style,Layout} flush have been called. This is not a
particularly useful metric, there's not much to learn or change from
it. Any call is basically free as long as they're consecutive /
there's no flush in between.
* The number of times layout / style has been flushed during a tick.
This is more useful than the above but, similarly, there's not too
much to be learned here. Number of flushes can be completely
orthogonal to how expensive it has been.
It also had a number of flaws:
* It is recorded per-PresShell, so we get multiple pings per tick.
* Similarly, if a sub-frame dies before the tick, we just never report
that time.
Instead, refactor it to make it simpler, and just record the first
metric reliably. This simplifies the code substantially, and I don't
think we're losing much.
The histograms are also expired. We might want to renew this, I'll file
a follow-up to either properly renew this if we plan to look at it, or
remove the code entirely from the tree.
Differential Revision: https://phabricator.services.mozilla.com/D210907
101 lines
3.1 KiB
C++
101 lines
3.1 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "mozilla/layout/LayoutTelemetryTools.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
#include "mozilla/EnumeratedArray.h"
|
|
#include "mozilla/EnumeratedRange.h"
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
namespace mozilla::layout_telemetry {
|
|
|
|
using LayoutSubsystemDurations =
|
|
EnumeratedArray<LayoutSubsystem, double, size_t(LayoutSubsystem::Count)>;
|
|
|
|
struct PerTickData {
|
|
constexpr PerTickData() = default;
|
|
LayoutSubsystemDurations mLayoutSubsystemDurationMs;
|
|
};
|
|
|
|
static PerTickData sData;
|
|
static AutoRecord* sCurrentRecord;
|
|
|
|
// Returns the key name expected by telemetry. Keep to date with
|
|
// toolkits/components/telemetry/Histograms.json.
|
|
static nsLiteralCString SubsystemTelemetryKey(LayoutSubsystem aSubsystem) {
|
|
switch (aSubsystem) {
|
|
default:
|
|
MOZ_CRASH("Unexpected LayoutSubsystem value");
|
|
case LayoutSubsystem::Restyle:
|
|
return "Restyle"_ns;
|
|
case LayoutSubsystem::Reflow:
|
|
return "ReflowOther"_ns;
|
|
case LayoutSubsystem::ReflowFlex:
|
|
return "ReflowFlex"_ns;
|
|
case LayoutSubsystem::ReflowGrid:
|
|
return "ReflowGrid"_ns;
|
|
case LayoutSubsystem::ReflowTable:
|
|
return "ReflowTable"_ns;
|
|
case LayoutSubsystem::ReflowText:
|
|
return "ReflowText"_ns;
|
|
}
|
|
}
|
|
|
|
void PingPerTickTelemetry() {
|
|
auto range =
|
|
MakeEnumeratedRange(LayoutSubsystem::Restyle, LayoutSubsystem::Count);
|
|
for (auto subsystem : range) {
|
|
auto key = SubsystemTelemetryKey(subsystem);
|
|
double& duration = sData.mLayoutSubsystemDurationMs[subsystem];
|
|
if (duration > 0.0) {
|
|
Telemetry::Accumulate(Telemetry::PRESSHELL_LAYOUT_TOTAL_MS_PER_TICK, key,
|
|
static_cast<uint32_t>(duration));
|
|
duration = 0.0;
|
|
}
|
|
}
|
|
}
|
|
|
|
AutoRecord::AutoRecord(LayoutSubsystem aSubsystem)
|
|
: mParentRecord(sCurrentRecord), mSubsystem(aSubsystem) {
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
// If we're re-entering the same subsystem, don't update the current record.
|
|
if (mParentRecord && mParentRecord->mSubsystem == mSubsystem) {
|
|
return;
|
|
}
|
|
|
|
mStartTime = TimeStamp::Now();
|
|
if (mParentRecord) {
|
|
// If we're entering a new subsystem, record the amount of time spent in the
|
|
// parent record before setting the new current record.
|
|
mParentRecord->mDurationMs +=
|
|
(mStartTime - mParentRecord->mStartTime).ToMilliseconds();
|
|
}
|
|
|
|
sCurrentRecord = this;
|
|
}
|
|
|
|
AutoRecord::~AutoRecord() {
|
|
if (sCurrentRecord != this) {
|
|
// If this record is not head of the list, do nothing.
|
|
return;
|
|
}
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
mDurationMs += (now - mStartTime).ToMilliseconds();
|
|
sData.mLayoutSubsystemDurationMs[mSubsystem] += mDurationMs;
|
|
|
|
if (mParentRecord) {
|
|
// Restart the parent recording from this point
|
|
mParentRecord->mStartTime = now;
|
|
}
|
|
|
|
// Unlink this record from the current record list
|
|
sCurrentRecord = mParentRecord;
|
|
}
|
|
|
|
} // namespace mozilla::layout_telemetry
|