Skip to content

Commit eb9e0c9

Browse files
douglas-raillard-armmarcbonnici
authored andcommitted
collector/ftrace: Make emitting cpu_frequency_devlib and extra idle events dependent on the configured events
Make cpu_frequency_devlib dependent on whether the "cpu_frequency" event has been selected rather than dependent on the cpufreq devlib module being loaded on the target. The old behavior became particularly problematic with the lazy loading of modules. However, it was never a reliable way of knowing if the user was interested in the frequency or not. Apply a similar mechanism for the extra idle state transitions only done if "cpu_idle" event is selected.
1 parent ae81490 commit eb9e0c9

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

devlib/collector/ftrace.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def __init__(self, target,
9393
self.host_binary = None
9494
self.start_time = None
9595
self.stop_time = None
96-
self.event_string = None
9796
self.function_string = None
9897
self.trace_clock = trace_clock
9998
self.saved_cmdlines_nr = saved_cmdlines_nr
@@ -195,7 +194,11 @@ def event_is_in_list(event, events):
195194
elif self.tracer == 'function_graph':
196195
self.function_string = _build_graph_functions(selected_functions, trace_children_functions)
197196

198-
self.event_string = _build_trace_events(selected_events)
197+
self._selected_events = selected_events
198+
199+
@property
200+
def event_string(self):
201+
return _build_trace_events(self._selected_events)
199202

200203
@classmethod
201204
def _resolve_tracing_path(cls, target, path):
@@ -270,6 +273,26 @@ def reset(self):
270273

271274
self._reset_needed = False
272275

276+
def _trace_frequencies(self):
277+
if 'cpu_frequency' in self._selected_events:
278+
self.logger.debug('Trace CPUFreq frequencies')
279+
try:
280+
mod = self.target.cpufreq
281+
except TargetStableError as e:
282+
self.logger.error(f'Could not trace CPUFreq frequencies as the cpufreq module cannot be loaded: {e}')
283+
else:
284+
mod.trace_frequencies()
285+
286+
def _trace_idle(self):
287+
if 'cpu_idle' in self._selected_events:
288+
self.logger.debug('Trace CPUIdle states')
289+
try:
290+
mod = self.target.cpuidle
291+
except TargetStableError as e:
292+
self.logger.error(f'Could not trace CPUIdle states as the cpuidle module cannot be loaded: {e}')
293+
else:
294+
mod.perturb_cpus()
295+
273296
@asyncf
274297
async def start(self):
275298
self.start_time = time.time()
@@ -302,12 +325,10 @@ async def start(self):
302325
)
303326
if self.automark:
304327
self.mark_start()
305-
if 'cpufreq' in self.target.modules:
306-
self.logger.debug('Trace CPUFreq frequencies')
307-
self.target.cpufreq.trace_frequencies()
308-
if 'cpuidle' in self.target.modules:
309-
self.logger.debug('Trace CPUIdle states')
310-
self.target.cpuidle.perturb_cpus()
328+
329+
self._trace_frequencies()
330+
self._trace_idle()
331+
311332
# Enable kernel function profiling
312333
if self.functions and self.tracer is None:
313334
target = self.target

0 commit comments

Comments
 (0)