aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_idle.py68
-rw-r--r--tests/trace_empty.txt15
-rw-r--r--tests/trace_idle.datbin0 -> 3301376 bytes
-rw-r--r--trappy/idle.py31
4 files changed, 99 insertions, 15 deletions
diff --git a/tests/test_idle.py b/tests/test_idle.py
new file mode 100644
index 0000000..dec1b43
--- /dev/null
+++ b/tests/test_idle.py
@@ -0,0 +1,68 @@
+# Copyright 2016 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 sys
+import unittest
+
+import pandas as pd
+from pandas.util.testing import assert_series_equal
+
+import utils_tests
+import trappy
+
+@unittest.skipUnless(utils_tests.trace_cmd_installed(),
+ "trace-cmd not installed")
+class TestCpuIdle(utils_tests.SetupDirectory):
+ def __init__(self, *args, **kwargs):
+ super(TestCpuIdle, self).__init__(
+ [("trace_idle.dat", "trace.dat")],
+ *args,
+ **kwargs)
+
+ def test_get_dataframe(self):
+ """Test that CpuIdle creates a proper data_frame"""
+
+ df = trappy.FTrace(normalize_time=False).cpu_idle.data_frame
+
+ exp_index = pd.Float64Index([
+ 162534.215764,
+ 162534.216001,
+ 162534.216552,
+ 162534.216568,
+ 162534.217401,
+ 162534.217521,
+ 162534.217655,
+ 162534.219077,
+ 162534.219252,
+ 162534.219268,
+ 162534.219329,
+ 162534.219336,
+ 162534.219587,
+ 162534.219763,
+ 162534.219853,
+ 162534.220947,
+ 162534.220947
+ ], name="Time")
+
+ exp_states = pd.Series([
+ 2, -1, 2, -1, -1, -1, 2, -1, 2, -1, 0, 0, 2, -1, 2, -1, -1
+ ], index=exp_index, name="state")
+ exp_cpus = pd.Series([
+ 5, 2, 2, 1, 3, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 3, 1
+ ], index=exp_index, name="cpu_id")
+
+ assert_series_equal(df["state"], exp_states, check_exact=True)
+ assert_series_equal(df["cpu_id"], exp_cpus, check_exact=True)
diff --git a/tests/trace_empty.txt b/tests/trace_empty.txt
index 26e18be..b35ba6f 100644
--- a/tests/trace_empty.txt
+++ b/tests/trace_empty.txt
@@ -5,7 +5,6 @@ cpus=5
trace-cmd-2461 [000] 34.896972: sched_wakeup: sshd:2450 [120] success=1 CPU:000
trace-cmd-2461 [000] 34.897022: sched_stat_wait: comm=sshd pid=2450 delay=0 [ns]
trace-cmd-2461 [000] 34.897053: sched_switch: trace-cmd:2461 [120] R ==> sshd:2450 [120]
- <idle>-0 [001] 34.897119: cpu_idle: state=4294967295 cpu_id=1
<idle>-0 [001] 34.897147: sched_stat_wait: comm=rcuos/0 pid=9 delay=0 [ns]
<idle>-0 [001] 34.897153: sched_switch: swapper/1:0 [120] R ==> rcuos/0:9 [120]
rcuos/0-9 [001] 34.897169: sched_stat_runtime: comm=sshd pid=2450 runtime=258292 [ns] vruntime=6078688361 [ns]
@@ -13,7 +12,6 @@ cpus=5
rcuos/0-9 [001] 34.897182: sched_wakeup: rcu_sched:7 [120] success=1 CPU:000
rcuos/0-9 [001] 34.897186: sched_stat_runtime: comm=rcuos/0 pid=9 runtime=445750 [ns] vruntime=6730976621 [ns]
rcuos/0-9 [001] 34.897230: sched_switch: rcuos/0:9 [120] S ==> swapper/1:0 [120]
- <idle>-0 [001] 34.897254: cpu_idle: state=1 cpu_id=1
sshd-2450 [000] 34.897303: sched_stat_runtime: comm=sshd pid=2450 runtime=134042 [ns] vruntime=6078822403 [ns]
sshd-2450 [000] 34.897313: sched_stat_wait: comm=rcu_sched pid=7 delay=134042 [ns]
sshd-2450 [000] 34.897319: sched_switch: sshd:2450 [120] S ==> rcu_sched:7 [120]
@@ -27,28 +25,22 @@ cpus=5
trace-cmd-2461 [000] 34.897703: sched_wakeup: bash:2459 [120] success=1 CPU:001
trace-cmd-2461 [000] 34.897708: sched_stat_runtime: comm=trace-cmd pid=2461 runtime=33500 [ns] vruntime=6087809903 [ns]
trace-cmd-2461 [000] 34.897738: sched_switch: trace-cmd:2461 [120] x ==> swapper/0:0 [120]
- <idle>-0 [000] 34.897749: cpu_idle: state=0 cpu_id=0
- <idle>-0 [001] 34.898057: cpu_idle: state=4294967295 cpu_id=1
<idle>-0 [001] 34.898076: sched_stat_wait: comm=bash pid=2459 delay=0 [ns]
<idle>-0 [001] 34.898082: sched_switch: swapper/1:0 [120] R ==> bash:2459 [120]
bash-2459 [001] 34.898188: sched_process_wait: comm=bash pid=0 prio=120
bash-2459 [001] 34.898653: sched_process_exit: comm=bash pid=2459 prio=120
bash-2459 [001] 34.898702: sched_stat_sleep: comm=sshd pid=2450 delay=1394541 [ns]
bash-2459 [001] 34.898708: sched_wakeup: sshd:2450 [120] success=1 CPU:000
- <idle>-0 [000] 34.898709: cpu_idle: state=4294967295 cpu_id=0
<idle>-0 [000] 34.898720: sched_stat_wait: comm=sshd pid=2450 delay=0 [ns]
bash-2459 [001] 34.898721: sched_stat_runtime: comm=bash pid=2459 runtime=1027542 [ns] vruntime=6723004163 [ns]
<idle>-0 [000] 34.898726: sched_switch: swapper/0:0 [120] R ==> sshd:2450 [120]
bash-2459 [001] 34.898732: sched_stat_runtime: comm=bash pid=2459 runtime=11000 [ns] vruntime=6723015163 [ns]
bash-2459 [001] 34.898745: sched_stat_runtime: comm=bash pid=2459 runtime=13458 [ns] vruntime=6723028621 [ns]
bash-2459 [001] 34.898758: sched_switch: bash:2459 [120] x ==> swapper/1:0 [120]
- <idle>-0 [001] 34.898776: cpu_idle: state=1 cpu_id=1
sshd-2450 [000] 34.898825: sched_process_wait: comm=sshd pid=0 prio=120
sshd-2450 [000] 34.898927: sched_process_wait: comm=sshd pid=0 prio=120
sshd-2450 [000] 34.898983: sched_stat_runtime: comm=sshd pid=2450 runtime=285875 [ns] vruntime=6079108278 [ns]
sshd-2450 [000] 34.898996: sched_switch: sshd:2450 [120] S ==> swapper/0:0 [120]
- <idle>-0 [000] 34.899005: cpu_idle: state=0 cpu_id=0
- <idle>-0 [000] 34.899122: cpu_idle: state=4294967295 cpu_id=0
<idle>-0 [000] 34.899144: sched_stat_sleep: comm=rcu_sched pid=7 delay=1810584 [ns]
<idle>-0 [000] 34.899149: sched_wakeup: rcu_sched:7 [120] success=1 CPU:000
<idle>-0 [000] 34.899175: sched_stat_wait: comm=rcu_sched pid=7 delay=0 [ns]
@@ -57,29 +49,22 @@ cpus=5
rcu_sched-7 [000] 34.899200: sched_wakeup: rcuos/0:9 [120] success=1 CPU:001
rcu_sched-7 [000] 34.899205: sched_stat_runtime: comm=rcu_sched pid=7 runtime=65375 [ns] vruntime=6078875278 [ns]
rcu_sched-7 [000] 34.899216: sched_switch: rcu_sched:7 [120] S ==> swapper/0:0 [120]
- <idle>-0 [000] 34.899225: cpu_idle: state=1 cpu_id=0
- <idle>-0 [001] 34.899572: cpu_idle: state=4294967295 cpu_id=1
<idle>-0 [001] 34.899620: sched_stat_wait: comm=rcuos/0 pid=9 delay=0 [ns]
<idle>-0 [001] 34.899628: sched_switch: swapper/1:0 [120] R ==> rcuos/0:9 [120]
rcuos/0-9 [001] 34.899770: sched_stat_sleep: comm=rcu_sched pid=7 delay=538708 [ns]
rcuos/0-9 [001] 34.899807: sched_wakeup: rcu_sched:7 [120] success=1 CPU:000
rcuos/0-9 [001] 34.899848: sched_stat_runtime: comm=rcuos/0 pid=9 runtime=653458 [ns] vruntime=6731630079 [ns]
rcuos/0-9 [001] 34.899877: sched_switch: rcuos/0:9 [120] S ==> swapper/1:0 [120]
- <idle>-0 [000] 34.899884: cpu_idle: state=4294967295 cpu_id=0
- <idle>-0 [001] 34.899903: cpu_idle: state=1 cpu_id=1
<idle>-0 [000] 34.899988: sched_stat_sleep: comm=sshd pid=2450 delay=1003959 [ns]
<idle>-0 [000] 34.899995: sched_wakeup: sshd:2450 [120] success=1 CPU:001
<idle>-0 [000] 34.900052: sched_stat_wait: comm=rcu_sched pid=7 delay=0 [ns]
<idle>-0 [000] 34.900058: sched_switch: swapper/0:0 [120] R ==> rcu_sched:7 [120]
rcu_sched-7 [000] 34.900069: sched_stat_runtime: comm=rcu_sched pid=7 runtime=325042 [ns] vruntime=6079200320 [ns]
rcu_sched-7 [000] 34.900086: sched_switch: rcu_sched:7 [120] S ==> swapper/0:0 [120]
- <idle>-0 [000] 34.900095: cpu_idle: state=1 cpu_id=0
- <idle>-0 [001] 34.900405: cpu_idle: state=4294967295 cpu_id=1
<idle>-0 [001] 34.900452: sched_stat_wait: comm=sshd pid=2450 delay=0 [ns]
<idle>-0 [001] 34.900460: sched_switch: swapper/1:0 [120] R ==> sshd:2450 [120]
sshd-2450 [001] 34.900756: sched_stat_sleep: comm=in:imuxsock pid=1767 delay=1926798326 [ns]
sshd-2450 [001] 34.900767: sched_wakeup: in:imuxsock:1767 [120] success=1 CPU:000
- <idle>-0 [000] 34.901131: cpu_idle: state=4294967295 cpu_id=0
<idle>-0 [000] 34.901148: sched_stat_wait: comm=in:imuxsock pid=1767 delay=0 [ns]
<idle>-0 [000] 34.901155: sched_switch: swapper/0:0 [120] R ==> in:imuxsock:1767 [120]
in:imuxsock-1767 [000] 34.901243: sched_stat_runtime: comm=in:imuxsock pid=1767 runtime=496084 [ns] vruntime=6079305987 [ns]
diff --git a/tests/trace_idle.dat b/tests/trace_idle.dat
new file mode 100644
index 0000000..a2b1d66
--- /dev/null
+++ b/tests/trace_idle.dat
Binary files differ
diff --git a/trappy/idle.py b/trappy/idle.py
new file mode 100644
index 0000000..deec716
--- /dev/null
+++ b/trappy/idle.py
@@ -0,0 +1,31 @@
+# Copyright 2016 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.
+#
+
+from trappy.base import Base
+from trappy.dynamic import register_ftrace_parser
+
+class CpuIdle(Base):
+ """Parse cpu_idle"""
+
+ unique_word = "cpu_idle"
+
+ def finalize_object(self):
+ # The trace contains "4294967295" instead of "-1" when exiting an idle
+ # state.
+ uint32_max = (2 ** 32) - 1
+ self.data_frame.replace(uint32_max, -1, inplace=True)
+ super(CpuIdle, self).finalize_object()
+
+register_ftrace_parser(CpuIdle)