blob: 84e30be96fbab77a4ca90ae01871e5ac5cfc6d4c [file] [log] [blame]
Brendan Jackmane81fdcb2017-01-04 17:10:29 +00001# Copyright 2015-2017 ARM Limited
Javi Merinoc47d2df2015-02-06 16:04:03 +00002#
Javi Merinoaace7c02015-08-10 14:10:47 +01003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
Dietmar Eggemannf545f852014-12-30 11:56:22 +010016
Javi Merinoc26a3232015-12-11 18:00:30 +000017"""Definitions of scheduler events registered by the FTrace class"""
Javi Merino81cbdd82015-06-19 16:47:44 +010018
Javi Merino435457c2015-08-10 15:59:10 +010019from trappy.base import Base
Javi Merino094e7422016-03-22 11:53:55 +000020from trappy.dynamic import register_ftrace_parser, register_dynamic_ftrace
Dietmar Eggemannf545f852014-12-30 11:56:22 +010021
22class SchedLoadAvgSchedGroup(Base):
23 """Corresponds to Linux kernel trace event sched_load_avg_sched_group"""
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010024
Javi Merino81cbdd82015-06-19 16:47:44 +010025 unique_word = "sched_load_avg_sg:"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010026 """The unique word that will be matched in a trace line"""
27
Dietmar Eggemannf545f852014-12-30 11:56:22 +010028 _cpu_mask_column = "cpus"
29
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +000030 pivot = "cpus"
31 """The Pivot along which the data is orthogonal"""
32
Dietmar Eggemannf545f852014-12-30 11:56:22 +010033 def finalize_object(self):
34 """This condition is necessary to force column 'cpus' to be printed
35 as 8 digits w/ leading 0
36 """
37 if self._cpu_mask_column in self.data_frame.columns:
Javi Merino81cbdd82015-06-19 16:47:44 +010038 dfr = self.data_frame[self._cpu_mask_column].apply('{:0>8}'.format)
39 self.data_frame[self._cpu_mask_column] = dfr
Dietmar Eggemannf545f852014-12-30 11:56:22 +010040
Javi Merino094e7422016-03-22 11:53:55 +000041register_ftrace_parser(SchedLoadAvgSchedGroup, "sched")
Javi Merino323bb8d2015-04-20 17:09:15 +010042
Dietmar Eggemannf545f852014-12-30 11:56:22 +010043class SchedLoadAvgTask(Base):
44 """Corresponds to Linux kernel trace event sched_load_avg_task"""
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010045
Javi Merino81cbdd82015-06-19 16:47:44 +010046 unique_word = "sched_load_avg_task:"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010047 """The unique word that will be matched in a trace line"""
48
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +000049 pivot = "pid"
50 """The Pivot along which the data is orthogonal"""
51
Dietmar Eggemannf545f852014-12-30 11:56:22 +010052 def get_pids(self, key=""):
53 """Returns a list of (comm, pid) that contain
54 'key' in their 'comm'."""
Javi Merino81cbdd82015-06-19 16:47:44 +010055 dfr = self.data_frame.drop_duplicates(subset=['comm', 'pid'])
56 dfr = dfr.ix[:, ['comm', 'pid']]
Dietmar Eggemannf545f852014-12-30 11:56:22 +010057
Javi Merino81cbdd82015-06-19 16:47:44 +010058 return dfr[dfr['comm'].str.contains(key)].values.tolist()
Dietmar Eggemannf545f852014-12-30 11:56:22 +010059
Javi Merino094e7422016-03-22 11:53:55 +000060register_ftrace_parser(SchedLoadAvgTask, "sched")
Dietmar Eggemannf545f852014-12-30 11:56:22 +010061
Javi Merino81cbdd82015-06-19 16:47:44 +010062# pylint doesn't like globals that are not ALL_CAPS
63# pylint: disable=invalid-name
Javi Merinofecb2672015-12-21 18:34:57 +000064SchedLoadAvgCpu = register_dynamic_ftrace("SchedLoadAvgCpu",
65 "sched_load_avg_cpu:", "sched",
66 pivot="cpu")
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010067"""Load and Utilization Signals for CPUs"""
Kapileshwar Singhff2b31e2015-05-15 16:24:56 +010068
Javi Merinofecb2672015-12-21 18:34:57 +000069SchedContribScaleFactor = register_dynamic_ftrace("SchedContribScaleFactor",
70 "sched_contrib_scale_f:",
71 "sched")
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010072"""Event to register tracing of contrib factor"""
Kapileshwar Singhff2b31e2015-05-15 16:24:56 +010073
Patrick Bellasi4ce5fe22015-11-13 18:35:19 +000074class SchedCpuCapacity(Base):
75 """Corresponds to Linux kernel trace event sched/cpu_capacity"""
76
77 unique_word = "cpu_capacity:"
78 """The unique word that will be matched in a trace line"""
79
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +000080 pivot = "cpu"
81 """The Pivot along which the data is orthogonal"""
82
Patrick Bellasi4ce5fe22015-11-13 18:35:19 +000083 def finalize_object(self):
84 """This renaming is necessary because our cpu related pivot is 'cpu'
85 and not 'cpu_id'. Otherwise you cannot 'mix and match' with other
86 classes
87 """
88 self.data_frame.rename(columns={'cpu_id':'cpu'}, inplace=True)
Patrick Bellasi8dd24172015-11-16 12:38:09 +000089 self.data_frame.rename(columns={'state' :'capacity'}, inplace=True)
Patrick Bellasi4ce5fe22015-11-13 18:35:19 +000090
Javi Merino094e7422016-03-22 11:53:55 +000091register_ftrace_parser(SchedCpuCapacity, "sched")
Dietmar Eggemannf545f852014-12-30 11:56:22 +010092
Patrick Bellasi62342472016-02-03 16:14:11 +000093SchedWakeup = register_dynamic_ftrace("SchedWakeup", "sched_wakeup:", "sched",
94 parse_raw=True)
95"""Register SchedWakeup Event"""
96
97SchedWakeupNew = register_dynamic_ftrace("SchedWakeupNew", "sched_wakeup_new:",
98 "sched", parse_raw=True)
99"""Register SchedWakeupNew Event"""
100
Javi Merino81cbdd82015-06-19 16:47:44 +0100101# pylint: enable=invalid-name
Kapileshwar Singh8733fa62015-06-18 23:01:22 +0100102
Javi Merino03410822016-03-24 10:50:03 +0000103class SchedSwitch(Base):
104 """Parse sched_switch"""
105
106 unique_word = "sched_switch:"
Chris Redpath55c39222017-06-17 16:25:49 +0100107 parse_raw = True
Javi Merino03410822016-03-24 10:50:03 +0000108
109 def __init__(self):
Chris Redpath55c39222017-06-17 16:25:49 +0100110 super(SchedSwitch, self).__init__(parse_raw=self.parse_raw)
Javi Merino03410822016-03-24 10:50:03 +0000111
112 def create_dataframe(self):
113 self.data_array = [line.replace(" ==> ", " ", 1)
114 for line in self.data_array]
115
116 super(SchedSwitch, self).create_dataframe()
117
118register_ftrace_parser(SchedSwitch, "sched")
119
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100120class SchedCpuFrequency(Base):
121 """Corresponds to Linux kernel trace event power/cpu_frequency"""
Kapileshwar Singh34825fa2015-09-09 14:52:16 +0100122
Javi Merino81cbdd82015-06-19 16:47:44 +0100123 unique_word = "cpu_frequency:"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +0100124 """The unique word that will be matched in a trace line"""
125
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +0000126 pivot = "cpu"
127 """The Pivot along which the data is orthogonal"""
128
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100129 def finalize_object(self):
130 """This renaming is necessary because our cpu related pivot is 'cpu'
131 and not 'cpu_id'. Otherwise you cannot 'mix and match' with other
132 classes
133 """
134 self.data_frame.rename(columns={'cpu_id':'cpu'}, inplace=True)
Patrick Bellasi8dd24172015-11-16 12:38:09 +0000135 self.data_frame.rename(columns={'state' :'frequency'}, inplace=True)
Javi Merino323bb8d2015-04-20 17:09:15 +0100136
Javi Merino094e7422016-03-22 11:53:55 +0000137register_ftrace_parser(SchedCpuFrequency, "sched")
Javi Merino35042e22016-09-08 11:25:04 +0100138
Javi Merino49899822016-09-13 14:28:16 +0100139register_dynamic_ftrace("SchedMigrateTask", "sched_migrate_task:", "sched")