Skip to content

Commit

Permalink
trace/perf: Introduce a new, generic collector
Browse files Browse the repository at this point in the history
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
pietos01-arm committed May 14, 2019
1 parent 519138d commit 030a931
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions devlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

from devlib.trace.ftrace import FtraceCollector
from devlib.trace.perf_stat import PerfStatCollector
from devlib.trace.perf import PerfCollector
from devlib.trace.serial_trace import SerialTraceCollector

from devlib.host import LocalConnection
Expand Down
76 changes: 76 additions & 0 deletions devlib/trace/perf.py
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
2 changes: 1 addition & 1 deletion devlib/trace/perf_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, target,
self.events = events if events else DEFAULT_EVENTS
self.force_install = force_install
self.labels = labels

# TODO: deprecation log message
# Validate parameters
if isinstance(optionstring, list):
self.optionstrings = optionstring
Expand Down

0 comments on commit 030a931

Please sign in to comment.