diff --git a/libs/utils/analysis/cpus_analysis.py b/libs/utils/analysis/cpus_analysis.py index d28f5b20cc7a13a5ebe7dd5a478e88d22b71f198..416be843ca151b342837d4eda39c4ff9e908e261 100644 --- a/libs/utils/analysis/cpus_analysis.py +++ b/libs/utils/analysis/cpus_analysis.py @@ -61,6 +61,32 @@ class CpusAnalysis(AnalysisModule): ctx_sw_df.index.name = 'cpu' return ctx_sw_df + def _dfg_cpu_wakeups(self, cpus=None): + """" + Get a DataFrame showing when a CPU was woken from idle + + :param cpus: List of CPUs to find wakeups for. If None, all CPUs. + :type cpus: list(int) or None + + :returns: :mod:`pandas.DataFrame` with one column ``cpu``, where each + row shows a time when the given ``cpu`` was woken up from + idle. + """ + if not self._trace.hasEvents('cpu_idle'): + self._log.warning('Events [cpu_idle] not found, cannot ' + 'get CPU wakeup events.') + return None + + cpus = cpus or range(self._trace.platform['cpus_count']) + + sr = pd.Series() + for cpu in cpus: + cpu_sr = self._trace.getCPUActiveSignal(cpu) + cpu_sr = cpu_sr[cpu_sr == 1] + cpu_sr = cpu_sr.replace(1, cpu) + sr = sr.append(cpu_sr) + + return pd.DataFrame({'cpu': sr}).sort_index() ############################################################################### # Plotting Methods diff --git a/tests/lisa/test_trace.py b/tests/lisa/test_trace.py index 25ccba24dbd9916cfb616d9fb448d063ac4359db..400f0f24330712b39aad19a207399d90fa113fb4 100644 --- a/tests/lisa/test_trace.py +++ b/tests/lisa/test_trace.py @@ -162,6 +162,35 @@ class TestTrace(TestCase): self.assertEqual(trace.platform['cpus_count'], 3) + def test_dfg_cpu_wakeups(self): + """ + Test the cpu_wakeups DataFrame getter + """ + trace = self.make_trace(""" + -0 [004] 519.021928: cpu_idle: state=4294967295 cpu_id=4 + -0 [004] 519.022147: cpu_idle: state=0 cpu_id=4 + -0 [004] 519.022641: cpu_idle: state=4294967295 cpu_id=4 + -0 [001] 519.022642: cpu_idle: state=4294967295 cpu_id=1 + -0 [002] 519.022643: cpu_idle: state=4294967295 cpu_id=2 + -0 [001] 519.022788: cpu_idle: state=0 cpu_id=1 + -0 [002] 519.022831: cpu_idle: state=2 cpu_id=2 + -0 [003] 519.022867: cpu_idle: state=4294967295 cpu_id=3 + -0 [003] 519.023045: cpu_idle: state=2 cpu_id=3 + -0 [004] 519.023080: cpu_idle: state=1 cpu_id=4 + """) + + df = trace.data_frame.cpu_wakeups() + + exp_index=[519.021928, 519.022641, 519.022642, 519.022643, 519.022867] + exp_cpus= [ 4, 4, 1, 2, 3] + self.assertListEqual(df.index.tolist(), exp_index) + self.assertListEqual(df.cpu.tolist(), exp_cpus) + + df = trace.data_frame.cpu_wakeups([2]) + + self.assertListEqual(df.index.tolist(), [519.022643]) + self.assertListEqual(df.cpu.tolist(), [2]) + class TestTraceNoClusterData(TestTrace): """ Test Trace without cluster data