Commit 7e3bde80 authored by Deepanjan Roy's avatar Deepanjan Roy Committed by Commit Bot

Adds run_tbmv3_metric script and first tbmv3 metric

- Adds a directory under tools/perf/core where all the tbmv3 code will be
landed as we're experimenting with them.
- Adds a very basic run_tbmv3_metric script. Currently it consumes the output
  of trace processor and prints it back to the terminal. In subsequent CLs we
  will turn this output into a python histogram and output that instead.
- Adds console_error_metric as an example tbmv3 metric. You can run it using
    ./run_tbmv3_metric.py --trace TRACE_FILE --metric console_error_metric

Bug: chromium:1012687

Change-Id: I668268e707ae633b271256125e8a6d78701906f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846065
Commit-Queue: Deepanjan Roy <dproy@chromium.org>
Reviewed-by: default avatarJuan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705566}
parent fcb99401
perezju@chromium.org
dproy@chromium.org
<!-- Copyright 2019 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.
-->
# TBMv3 [Experimental]
This directory contains files for TBMv3, an experimental new metric authoring
platform based on Perfetto.
# Copyright 2019 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.
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
syntax = "proto2";
option optimize_for = LITE_RUNTIME;
package perfetto.protos;
import "protos/perfetto/metrics/metrics.proto";
message ConsoleErrorMetric {
optional int64 all = 1;
optional int64 js = 2;
optional int64 network = 3;
}
extend TraceMetrics {
optional ConsoleErrorMetric console_error_metric = 450;
}
-- Copyright 2019 Google LLC.
-- SPDX-License-Identifier: Apache-2.0
CREATE VIEW console_error_events AS
SELECT args.string_value as source
from slices
inner join args using(arg_set_id)
where slices.name = "ConsoleMessage::Error"
and slices.category = "blink.console"
and args.flat_key = "debug.source"
UNION ALL
-- Can't find a trace with v8 console errors so this path is untested.
SELECT "JS" AS source
FROM slices
WHERE slices.category = 'v8.console' AND (
slices.name = 'V8ConsoleMessage::Exception' OR
slices.name = 'V8ConsoleMessage::Error' OR
slices.name = 'V8ConsoleMessage::Assert'
);
CREATE VIEW console_error_metric AS
SELECT
(SELECT COUNT(*) FROM console_error_events) as all_errors,
(SELECT COUNT(*) FROM console_error_events where source = "JS") as js,
(SELECT COUNT(*) FROM console_error_events where source = "Network") as network;
CREATE VIEW console_error_metric_output AS
SELECT ConsoleErrorMetric(
'all', all_errors,
'js', js,
'network', network)
FROM console_error_metric
#!/usr/bin/env vpython
# Copyright 2019 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.
import argparse
import json
import os
import subprocess
import sys
from collections import namedtuple
_CHROMIUM_SRC_PATH = os.path.join(
os.path.dirname(__file__), '..', '..', '..', '..')
_DEFAULT_TP_PATH = os.path.abspath(os.path.join(
_CHROMIUM_SRC_PATH, 'out', 'Debug', 'trace_processor_shell'))
_METRICS_PATH = os.path.join(os.path.dirname(__file__), 'metrics')
MetricFiles = namedtuple('MetricFiles', ('sql', 'proto'))
class MetricFileNotFound(Exception):
pass
class TraceProcessorNotFound(Exception):
pass
class TraceProcessorError(Exception):
pass
def _CheckFilesExist(trace_processor_path, metric_files):
if not os.path.exists(trace_processor_path):
raise TraceProcessorNotFound("Could not find trace processor shell at %s"
% trace_processor_path)
# Currently assuming all metric files live in tbmv3/metrics directory. We will
# revise this decision later.
for filetype, path in metric_files._asdict().iteritems():
if not os.path.exists(path):
raise MetricFileNotFound("metric %s file not found at %s"
% (filetype, path))
def Main():
parser = argparse.ArgumentParser(
description='[Experimental] Runs TBMv3 metrics on local traces.')
parser.add_argument('--trace', required=True,
help='Trace file you want to compute metric on')
parser.add_argument('--metric', required=True,
help=('Name of the metric you want to run'))
parser.add_argument('--trace_processor_path', default=_DEFAULT_TP_PATH,
help='Path to trace processor shell. '
'Default: %(default)s')
args = parser.parse_args()
metric_files = MetricFiles(
sql=os.path.join(_METRICS_PATH, args.metric + '.sql'),
proto=os.path.join(_METRICS_PATH, args.metric + '.proto')
)
_CheckFilesExist(args.trace_processor_path, metric_files)
trace_processor_args = [args.trace_processor_path,
args.trace,
'--run-metrics', metric_files.sql,
'--metrics-output=json',
'--extra-metrics', _METRICS_PATH]
try:
json_output = subprocess.check_output(trace_processor_args)
except subprocess.CalledProcessError:
raise TraceProcessorError("Failed to compute metrics. " +
"Check trace processor logs.")
json_result = json.loads(json_output)
print "Metric result:"
print json_result
if __name__ == '__main__':
sys.exit(Main())
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