mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 12:06:08 +00:00
instruments: Add Perfetto instrument
Add an instrument that uses devlib's PerfettoCollector to collect a Perfetto trace during the execution of a workload. The instrument takes a path to a Perfetto config file which specifies how Perfetto should be configured for the tracing. Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
This commit is contained in:
parent
775b24f7a3
commit
8d4fe9556b
101
wa/instruments/perfetto.py
Normal file
101
wa/instruments/perfetto.py
Normal file
@ -0,0 +1,101 @@
|
||||
# Copyright 2023 ARM Limited
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
from devlib import PerfettoCollector
|
||||
|
||||
from wa import Instrument, Parameter
|
||||
from wa.framework.instrument import very_slow, is_installed
|
||||
from wa.framework.exception import InstrumentError
|
||||
|
||||
OUTPUT_PERFETTO_TRACE = 'devlib-trace.perfetto-trace'
|
||||
PERFETTO_CONFIG_FILE = 'config.pbtx'
|
||||
|
||||
|
||||
class PerfettoInstrument(Instrument):
|
||||
name = 'perfetto'
|
||||
description = """
|
||||
perfetto is an instrument that interacts with Google's Perfetto tracing
|
||||
infrastructure.
|
||||
|
||||
From Perfetto's website:
|
||||
Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis.
|
||||
It offers services and libraries for recording system-level and app-level traces, native + java heap profiling,
|
||||
a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.
|
||||
|
||||
The instrument either requires Perfetto to be present on the target device or the standalone tracebox binary
|
||||
to be built from source and included in devlib's Package Bin directory.
|
||||
For more information, consult the PerfettoCollector documentation in devlib.
|
||||
|
||||
More information can be found on https://perfetto.dev/
|
||||
"""
|
||||
|
||||
parameters = [
|
||||
Parameter('config', kind=str, mandatory=True,
|
||||
description="""
|
||||
Path to the Perfetto trace config file.
|
||||
|
||||
All the Perfetto-specific tracing configuration should be done inside
|
||||
that file. This config option should just take a full
|
||||
filesystem path to where the config can be found.
|
||||
"""),
|
||||
Parameter('force_tracebox', kind=bool, default=False,
|
||||
description="""
|
||||
Install tracebox even if traced is already running on the target device.
|
||||
If set to true, the tracebox binary needs to be placed in devlib's Package Bin directory.
|
||||
""")
|
||||
]
|
||||
|
||||
def __init__(self, target, **kwargs):
|
||||
super(PerfettoInstrument, self).__init__(target, **kwargs)
|
||||
self.collector = None
|
||||
|
||||
def initialize(self, context): # pylint: disable=unused-argument
|
||||
self.target_config = self.target.path.join(self.target.working_directory, PERFETTO_CONFIG_FILE)
|
||||
# push the config file to target
|
||||
self.target.push(self.config, self.target_config)
|
||||
collector_params = dict(
|
||||
config=self.target_config,
|
||||
force_tracebox=self.force_tracebox
|
||||
)
|
||||
self.collector = PerfettoCollector(self.target, **collector_params)
|
||||
|
||||
@very_slow
|
||||
def start(self, context): # pylint: disable=unused-argument
|
||||
self.collector.start()
|
||||
|
||||
@very_slow
|
||||
def stop(self, context): # pylint: disable=unused-argument
|
||||
self.collector.stop()
|
||||
|
||||
def update_output(self, context):
|
||||
self.logger.info('Extracting Perfetto trace from target...')
|
||||
outfile = os.path.join(context.output_directory, OUTPUT_PERFETTO_TRACE)
|
||||
self.collector.set_output(outfile)
|
||||
self.collector.get_data()
|
||||
context.add_artifact('perfetto-bin', outfile, 'data')
|
||||
|
||||
def teardown(self, context): # pylint: disable=unused-argument
|
||||
self.target.remove(self.collector.target_output_file)
|
||||
|
||||
def finalize(self, context): # pylint: disable=unused-argument
|
||||
self.target.remove(self.target_config)
|
||||
|
||||
def validate(self):
|
||||
if is_installed('trace-cmd'):
|
||||
raise InstrumentError('perfetto cannot be used at the same time as trace-cmd')
|
||||
if not os.path.isfile(self.config):
|
||||
raise InstrumentError('perfetto config file not found at "{}"'.format(self.config))
|
@ -22,7 +22,7 @@ from devlib import FtraceCollector
|
||||
|
||||
from wa import Instrument, Parameter
|
||||
from wa.framework import signal
|
||||
from wa.framework.instrument import very_slow
|
||||
from wa.framework.instrument import very_slow, is_installed
|
||||
from wa.framework.exception import InstrumentError
|
||||
from wa.utils.types import list_of_strings
|
||||
from wa.utils.misc import which
|
||||
@ -235,6 +235,8 @@ class TraceCmdInstrument(Instrument):
|
||||
def validate(self):
|
||||
if self.report and not self.report_on_target and not which('trace-cmd'):
|
||||
raise InstrumentError('trace-cmd is not in PATH; is it installed?')
|
||||
if is_installed('perfetto'):
|
||||
raise InstrumentError('trace-cmd cannot be used at the same time as perfetto')
|
||||
|
||||
def mark_start(self, context):
|
||||
if self.is_enabled:
|
||||
|
Loading…
x
Reference in New Issue
Block a user