Skip to content

Commit

Permalink
Reland "Added Gpu.MultipleSwapsDelta metric"
Browse files Browse the repository at this point in the history
This is a reland of 75ed805
Trace categories are set as constexpr to fix the compile issue.

Original change's description:
> Added Gpu.MultipleSwapsDelta metric
>
> If there are multiple swaps in the interval of two begin frames, the
> delta between them would be reported in the Gpu.MultipleSwapsDelta.
> Because of inaccurate swap timestamps on some platforms the current
> reporting only includes the deltas that are smaller than 2/3 of interval
> so that swaps than nearly pass the deadline would not be counted in.
>
>
> Bug: chromium:1265437
> Change-Id: I521c434a7d6ce6ffb91889a6cf5d990b7881feef
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3278443
> Reviewed-by: Jonathan Ross <jonross@chromium.org>
> Commit-Queue: Behdad Bakhshinategh <behdadb@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#946227}

Bug: chromium:1265437
Change-Id: Ia0219eae83a593a71ed20b5d03fa16e62e29eece
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3307314
Auto-Submit: Behdad Bakhshinategh <behdadb@chromium.org>
Commit-Queue: Jonathan Ross <jonross@chromium.org>
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Cr-Commit-Position: refs/heads/main@{#947061}
  • Loading branch information
behdad authored and Chromium LUCI CQ committed Dec 1, 2021
1 parent 170b109 commit 16e9090
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cc/metrics/compositor_frame_reporting_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
#include <utility>

#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_id_helper.h"
#include "cc/metrics/compositor_frame_reporter.h"
#include "cc/metrics/dropped_frame_counter.h"
#include "cc/metrics/latency_ukm_reporter.h"
#include "components/viz/common/frame_timing_details.h"
#include "components/viz/common/quads/compositor_frame_metadata.h"
#include "services/tracing/public/cpp/perfetto/macros.h"

namespace cc {
namespace {
using SmoothThread = CompositorFrameReporter::SmoothThread;
using StageType = CompositorFrameReporter::StageType;
using FrameTerminationStatus = CompositorFrameReporter::FrameTerminationStatus;

constexpr char kTraceCategory[] = "cc,benchmark";
} // namespace

CompositorFrameReportingController::CompositorFrameReportingController(
Expand Down Expand Up @@ -76,6 +80,8 @@ void CompositorFrameReportingController::ProcessSkippedFramesIfNecessary(
void CompositorFrameReportingController::WillBeginImplFrame(
const viz::BeginFrameArgs& args) {
ProcessSkippedFramesIfNecessary(args);
ReportMultipleSwaps(args.frame_time, last_interval_);
last_interval_ = args.interval;

base::TimeTicks begin_time = Now();
if (reporters_[PipelineStage::kBeginImplFrame]) {
Expand Down Expand Up @@ -354,6 +360,46 @@ void CompositorFrameReportingController::
}
}

void CompositorFrameReportingController::TrackSwapTiming(
const viz::FrameTimingDetails& details) {
if (details.swap_timings.swap_start != base::TimeTicks()) {
if (latest_swap_times_.empty() ||
latest_swap_times_.back() < details.swap_timings.swap_start)
latest_swap_times_.push(details.swap_timings.swap_start);
}

// Making sure the queue would not keep growing in size.
DCHECK_LE(latest_swap_times_.size(), 10u);
}

void CompositorFrameReportingController::ReportMultipleSwaps(
base::TimeTicks begin_frame_time,
base::TimeDelta interval) {
while (!latest_swap_times_.empty() &&
latest_swap_times_.front() <= begin_frame_time - interval) {
latest_swap_times_.pop();
}

if (latest_swap_times_.empty())
return;

if (latest_swap_times_.size() > 1) {
base::TimeDelta swap_delta =
latest_swap_times_.back() - latest_swap_times_.front();

if (swap_delta < interval) {
UMA_HISTOGRAM_PERCENTAGE("GPU.MultipleSwapsDelta",
swap_delta * 100.0 / interval);

const auto trace_track =
perfetto::Track(base::trace_event::GetNextGlobalTraceId());
TRACE_EVENT_BEGIN(kTraceCategory, "MultipleSwaps", trace_track,
latest_swap_times_.front());
TRACE_EVENT_END(kTraceCategory, trace_track, latest_swap_times_.back());
}
}
}

void CompositorFrameReportingController::OnFinishImplFrame(
const viz::BeginFrameId& id) {
for (auto& reporter : reporters_) {
Expand All @@ -368,6 +414,10 @@ void CompositorFrameReportingController::DidPresentCompositorFrame(
uint32_t frame_token,
const viz::FrameTimingDetails& details) {
bool feedback_failed = details.presentation_feedback.failed();

if (!feedback_failed)
TrackSwapTiming(details);

for (auto submitted_frame = submitted_compositor_frames_.begin();
submitted_frame != submitted_compositor_frames_.end() &&
!viz::FrameTokenGT(submitted_frame->frame_token, frame_token);) {
Expand Down
11 changes: 11 additions & 0 deletions cc/metrics/compositor_frame_reporting_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <map>
#include <memory>
#include <queue>
#include <vector>

#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -152,6 +153,9 @@ class CC_EXPORT CompositorFrameReportingController {
// that reporter is in, its ownership might be pass or not.
void SetPartialUpdateDeciderWhenWaitingOnMain(
std::unique_ptr<CompositorFrameReporter>& reporter);
void TrackSwapTiming(const viz::FrameTimingDetails& details);
void ReportMultipleSwaps(base::TimeTicks begin_frame_time,
base::TimeDelta interval);

const bool should_report_metrics_;
const int layer_tree_host_id_;
Expand Down Expand Up @@ -200,6 +204,13 @@ class CC_EXPORT CompositorFrameReportingController {
// these metrics and report them.
std::map<viz::BeginFrameId, EventMetrics::List>
events_metrics_from_dropped_frames_;

// Tracking the swap times in a queue to measure delta of multiple swaps in
// each vsync.
std::queue<base::TimeTicks> latest_swap_times_;

// interval of last begin frame args.
base::TimeDelta last_interval_;
};
} // namespace cc

Expand Down
10 changes: 10 additions & 0 deletions tools/metrics/histograms/metadata/gpu/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,16 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="GPU.MultipleSwapsDelta" units="%" expires_after="2022-11-15">
<owner>behdadb@chromium.org</owner>
<owner>chrome-gpu-metrics@google.com</owner>
<summary>
Time delta between swaps, when there are multiple successful swaps in the
same vsync. The delta is reported as a percentage of vsync interval. This
can be recorded every time we present a frame.
</summary>
</histogram>

<histogram name="GPU.OopRaster.GlyphCacheMiss"
enum="OopRasterGlyphCacheMissType" expires_after="M110">
<owner>khushalsagar@chromium.org</owner>
Expand Down

0 comments on commit 16e9090

Please sign in to comment.