Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions devlib/collector/ftrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from devlib.host import PACKAGE_BIN_DIRECTORY
from devlib.exception import TargetStableError, HostError
from devlib.utils.misc import check_output, which, memoized
from devlib.utils.asyn import asyncf


TRACE_MARKER_START = 'TRACE_MARKER_START'
Expand Down Expand Up @@ -243,7 +244,8 @@ def reset(self):
self.target.write_value(self.function_profile_file, 0, verify=False)
self._reset_needed = False

def start(self):
@asyncf
async def start(self):
self.start_time = time.time()
if self._reset_needed:
self.reset()
Expand Down Expand Up @@ -282,14 +284,17 @@ def start(self):
self.target.cpuidle.perturb_cpus()
# Enable kernel function profiling
if self.functions and self.tracer is None:
self.target.execute('echo nop > {}'.format(self.current_tracer_file),
as_root=True)
self.target.execute('echo 0 > {}'.format(self.function_profile_file),
as_root=True)
self.target.execute('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
as_root=True)
self.target.execute('echo 1 > {}'.format(self.function_profile_file),
as_root=True)
target = self.target
await target.async_manager.concurrently(
execute.asyn('echo nop > {}'.format(self.current_tracer_file),
as_root=True),
execute.asyn('echo 0 > {}'.format(self.function_profile_file),
as_root=True),
execute.asyn('echo {} > {}'.format(self.function_string, self.ftrace_filter_file),
as_root=True),
execute.asyn('echo 1 > {}'.format(self.function_profile_file),
as_root=True),
)


def stop(self):
Expand Down
24 changes: 18 additions & 6 deletions devlib/module/cgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
from shlex import quote
import itertools
import warnings
import asyncio

from devlib.module import Module
from devlib.exception import TargetStableError
from devlib.utils.misc import list_to_ranges, isiterable
from devlib.utils.types import boolean
from devlib.utils.asyn import asyncf


class Controller(object):
Expand Down Expand Up @@ -55,7 +57,8 @@ def __init__(self, kind, hid, clist):
self.mount_point = None
self._cgroups = {}

def mount(self, target, mount_root):
@asyncf
async def mount(self, target, mount_root):

mounted = target.list_file_systems()
if self.mount_name in [e.device for e in mounted]:
Expand All @@ -68,16 +71,16 @@ def mount(self, target, mount_root):
else:
# Mount the controller if not already in use
self.mount_point = target.path.join(mount_root, self.mount_name)
target.execute('mkdir -p {} 2>/dev/null'\
await target.execute.asyn('mkdir -p {} 2>/dev/null'\
.format(self.mount_point), as_root=True)
target.execute('mount -t cgroup -o {} {} {}'\
await target.execute.asyn('mount -t cgroup -o {} {} {}'\
.format(','.join(self.clist),
self.mount_name,
self.mount_point),
as_root=True)

# Check if this controller uses "noprefix" option
output = target.execute('mount | grep "{} "'.format(self.mount_name))
output = await target.execute.asyn('mount | grep "{} "'.format(self.mount_name))
if 'noprefix' in output:
self._noprefix = True
# self.logger.debug('Controller %s using "noprefix" option',
Expand Down Expand Up @@ -394,18 +397,27 @@ def __init__(self, target):
# Initialize controllers
self.logger.info('Available controllers:')
self.controllers = {}
for ss in subsys:

async def register_controller(ss):
hid = ss.hierarchy
controller = Controller(ss.name, hid, hierarchy[hid])
try:
controller.mount(self.target, self.cgroup_root)
await controller.mount.asyn(self.target, self.cgroup_root)
except TargetStableError:
message = 'Failed to mount "{}" controller'
raise TargetStableError(message.format(controller.kind))
self.logger.info(' %-12s : %s', controller.kind,
controller.mount_point)
self.controllers[ss.name] = controller

asyncio.run(
target.async_manager.map_concurrently(
register_controller,
subsys,
)
)


def list_subsystems(self):
subsystems = []
for line in self.target.execute('{} cat /proc/cgroups'\
Expand Down
Loading