Commit ab6545f6 authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

Reland "Reland "[tools/perf] Add webview_cpu_usage metric""

This is a reland of a0061b0e

The updated trace processor for mac has rolled in
https://crrev.com/c/2236111.

Original change's description:
> Reland "[tools/perf] Add webview_cpu_usage metric"
>
> This is a reland of 5c76e821
>
> The test failures that caused the revert have been fixed in
> https://r.android.com/1325791 and rolled into chromium in
> https://crrev.com/c/2236240.
>
> Original change's description:
> > [tools/perf] Add webview_cpu_usage metric
> >
> > This change adds a metric that calculates the amount of time WebView
> > spends on different frequencies.
> >
> > Bug: b/157855323
> > Change-Id: Ibb1fa61cc2ba1479f2b76ef642dc03c64a9a14b5
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231452
> > Reviewed-by: Mikhail Khokhlov <khokhlov@google.com>
> > Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#775713}
>
> Bug: b/157855323
> Change-Id: I45552ebb5b3ca49c05506495e16a7a20e02ade86
> TBR: khokhlov@google.com
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2236055
> Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
> Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#776374}

TBR: oksamyt@chromium.org
Bug: b/157855323
Change-Id: If89eab0236486f3d09e381881cac3743d6942368
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2235719Reviewed-by: default avatarMikhail Khokhlov <khokhlov@google.com>
Commit-Queue: Mikhail Khokhlov <khokhlov@google.com>
Cr-Commit-Position: refs/heads/master@{#776574}
parent 05436934
syntax = "proto2";
package perfetto.protos;
import "protos/perfetto/metrics/metrics.proto";
import "protos/perfetto/metrics/custom_options.proto";
message WebViewCPUUsageMetric {
optional int64 cpu_time_nanos_below_1ghz = 1;
optional int64 cpu_time_nanos_above_1ghz = 2;
};
extend TraceMetrics {
optional WebViewCPUUsageMetric webview_cpu_usage_metric = 458;
}
-- WebView is embedded in the hosting app's main process, which means it shares some threads
-- with the host app's work. In the future, we will approximate WebView-related power usage
-- by selecting user slices that belong to WebView and estimating their power use
-- through the CPU time they consume at different core frequencies.
-- The initial version of this metric calculates the total time (in nanoseconds)
-- WebView slices spend in different frequency ranges.
SELECT RUN_METRIC('android/android_cpu.sql');
DROP VIEW IF EXISTS webview_slice;
CREATE VIEW webview_slice AS
SELECT *
FROM
-- TODO(b/156788923): add better conditions.
slice WHERE category = 'android_webview';
DROP VIEW IF EXISTS top_level_webview_slice;
-- Since we filter out some slices in webview_slice above, we cannot use the "depth" column
-- to select only the top-level webview slices. Instead, we have to join webview_slice with itself,
-- selecting only those events that do not have any children in webview_slice.
CREATE VIEW top_level_webview_slice AS
SELECT *
FROM
webview_slice s1 WHERE
(SELECT COUNT(1)
FROM (
SELECT *
FROM
webview_slice s2
WHERE s1.track_id = s2.track_id
AND s2.ts < s1.ts
AND s2.ts + s2.dur > s1.ts + s1.dur
LIMIT 1)
) == 0;
DROP VIEW IF EXISTS slices_threads;
CREATE VIEW slices_threads AS
SELECT
top_level_webview_slice.ts,
top_level_webview_slice.dur,
thread_track.utid
FROM top_level_webview_slice INNER JOIN thread_track
ON top_level_webview_slice.track_id = thread_track.id;
DROP TABLE IF EXISTS slices_freq;
CREATE VIRTUAL TABLE slices_freq
USING SPAN_JOIN (cpu_freq_sched_per_thread PARTITIONED utid,
slices_threads PARTITIONED utid);
-- Get frequencies by utid and cpu.
SELECT RUN_METRIC('android/android_cpu_raw_metrics_per_core.sql',
'input_table', 'slices_freq',
'output_table', 'webview_raw_metrics_per_core');
-- TODO(b/155980166): use another query to estimate power consumption based on frequencies.
CREATE VIEW webview_cpu_usage_metric_output AS
SELECT WebViewCPUUsageMetric(
'cpu_time_nanos_below_1ghz',
(SELECT IFNULL(CAST(SUM(runtime_ns) AS INT), 0)
FROM
webview_raw_metrics_per_core
WHERE avg_freq_khz < 1000000),
'cpu_time_nanos_above_1ghz',
(SELECT IFNULL(CAST(SUM(runtime_ns) AS INT), 0)
FROM
webview_raw_metrics_per_core
WHERE avg_freq_khz >= 1000000)
);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment