Skip to content

Commit 030a931

Browse files
committed
trace/perf: Introduce a new, generic collector
Introduce a perf collector that is more generic than the previous one and which is expected to be able to handle all potential calls to perf (irrespective of the subcommand, flags, options or arguments being used).
1 parent 519138d commit 030a931

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

devlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
from devlib.trace.ftrace import FtraceCollector
4949
from devlib.trace.perf_stat import PerfStatCollector
50+
from devlib.trace.perf import PerfCollector
5051
from devlib.trace.serial_trace import SerialTraceCollector
5152

5253
from devlib.host import LocalConnection

devlib/trace/perf.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2018-2019 ARM Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import os
17+
import shlex
18+
from typing import Any, Dict, Optional
19+
20+
from devlib.host import PACKAGE_BIN_DIRECTORY
21+
from devlib.trace import TraceCollector
22+
23+
class PerfCollector(TraceCollector):
24+
"""
25+
"""
26+
def __init__(self,
27+
target,
28+
force_install : bool = False,
29+
pre_commands : Optional[Dict[str, Any]] = None,
30+
commands : Optional[Dict[str, Any]] = None,
31+
post_commands : Optional[Dict[str, Any]] = None):
32+
super().__init__(target)
33+
self.pre_commands = pre_commands or {}
34+
self.commands = commands or {}
35+
self.post_commands = post_commands or {}
36+
37+
self.binary = self.target.get_installed('perf')
38+
if force_install or not self.binary:
39+
host_binary = os.path.join(PACKAGE_BIN_DIRECTORY,
40+
self.target.abi, 'perf')
41+
self.binary = self.target.install(host_binary)
42+
43+
self.kill_sleep = False
44+
45+
# TODO: folder tree for files on device to avoid clashes
46+
# TODO: user has to figure out file classhes (e.g. between perf.data)
47+
48+
def reset(self):
49+
super().reset()
50+
self.target.killall('perf', as_root=self.target.is_rooted)
51+
52+
def start(self):
53+
super().start()
54+
self.cwd = f'cd {shlex.quote(self.target.working_directory)}'
55+
# TODO: why isn't target.execute running in working_directory?
56+
for label, command in self.pre_commands.items():
57+
self.target.execute(f'{self.cwd} && {self.binary} {command}',
58+
as_root=self.target.is_rooted)
59+
for label, command in self.commands.items():
60+
self.target.kick_off(f'{self.binary} {command}',
61+
as_root=self.target.is_rooted)
62+
if 'sleep' in command:
63+
self.kill_sleep = True
64+
65+
def stop(self):
66+
super().stop()
67+
self.target.killall('perf', signal='SIGINT',
68+
as_root=self.target.is_rooted)
69+
if self.kill_sleep:
70+
self.target.killall('sleep', as_root=self.target.is_rooted)
71+
for label, command in self.post_commands.items():
72+
self.target.execute(f'{self.cwd} && {self.binary} {command}',
73+
as_root=self.target.is_rooted)
74+
75+
def get_trace(self, outfile):
76+
raise NotImplementedError # TODO

devlib/trace/perf_stat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, target,
7474
self.events = events if events else DEFAULT_EVENTS
7575
self.force_install = force_install
7676
self.labels = labels
77-
77+
# TODO: deprecation log message
7878
# Validate parameters
7979
if isinstance(optionstring, list):
8080
self.optionstrings = optionstring

0 commit comments

Comments
 (0)