-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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).
- Loading branch information
1 parent
519138d
commit 030a931
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2018-2019 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 | ||
import shlex | ||
from typing import Any, Dict, Optional | ||
|
||
from devlib.host import PACKAGE_BIN_DIRECTORY | ||
from devlib.trace import TraceCollector | ||
|
||
class PerfCollector(TraceCollector): | ||
""" | ||
""" | ||
def __init__(self, | ||
target, | ||
force_install : bool = False, | ||
pre_commands : Optional[Dict[str, Any]] = None, | ||
commands : Optional[Dict[str, Any]] = None, | ||
post_commands : Optional[Dict[str, Any]] = None): | ||
super().__init__(target) | ||
self.pre_commands = pre_commands or {} | ||
self.commands = commands or {} | ||
self.post_commands = post_commands or {} | ||
|
||
self.binary = self.target.get_installed('perf') | ||
if force_install or not self.binary: | ||
host_binary = os.path.join(PACKAGE_BIN_DIRECTORY, | ||
self.target.abi, 'perf') | ||
self.binary = self.target.install(host_binary) | ||
|
||
self.kill_sleep = False | ||
|
||
# TODO: folder tree for files on device to avoid clashes | ||
# TODO: user has to figure out file classhes (e.g. between perf.data) | ||
|
||
def reset(self): | ||
super().reset() | ||
self.target.killall('perf', as_root=self.target.is_rooted) | ||
|
||
def start(self): | ||
super().start() | ||
self.cwd = f'cd {shlex.quote(self.target.working_directory)}' | ||
# TODO: why isn't target.execute running in working_directory? | ||
for label, command in self.pre_commands.items(): | ||
self.target.execute(f'{self.cwd} && {self.binary} {command}', | ||
as_root=self.target.is_rooted) | ||
for label, command in self.commands.items(): | ||
self.target.kick_off(f'{self.binary} {command}', | ||
as_root=self.target.is_rooted) | ||
if 'sleep' in command: | ||
self.kill_sleep = True | ||
|
||
def stop(self): | ||
super().stop() | ||
self.target.killall('perf', signal='SIGINT', | ||
as_root=self.target.is_rooted) | ||
if self.kill_sleep: | ||
self.target.killall('sleep', as_root=self.target.is_rooted) | ||
for label, command in self.post_commands.items(): | ||
self.target.execute(f'{self.cwd} && {self.binary} {command}', | ||
as_root=self.target.is_rooted) | ||
|
||
def get_trace(self, outfile): | ||
raise NotImplementedError # TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters