blob: b8fe1311bea70dc427d0de0608623e19a129483b [file] [log] [blame]
Javi Merinoaace7c02015-08-10 14:10:47 +01001# Copyright 2015-2015 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 Merino81cbdd82015-06-19 16:47:44 +010017"""Definitions of scheduler events registered by the Run class"""
18
Javi Merino435457c2015-08-10 15:59:10 +010019from trappy.base import Base
20from trappy.dynamic import register_dynamic
21from trappy.run import Run
Dietmar Eggemannf545f852014-12-30 11:56:22 +010022
23class SchedLoadAvgSchedGroup(Base):
24 """Corresponds to Linux kernel trace event sched_load_avg_sched_group"""
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010025
Javi Merino81cbdd82015-06-19 16:47:44 +010026 unique_word = "sched_load_avg_sg:"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010027 """The unique word that will be matched in a trace line"""
28
Javi Merino81cbdd82015-06-19 16:47:44 +010029 name = "sched_load_avg_sched_group"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010030 """The name of the :mod:`pandas.DataFrame` member that will be created in a
31 :mod:`trappy.run.Run` object"""
32
Dietmar Eggemannf545f852014-12-30 11:56:22 +010033 _cpu_mask_column = "cpus"
34
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +000035 pivot = "cpus"
36 """The Pivot along which the data is orthogonal"""
37
Javi Merino6f34d902015-02-21 11:39:09 +000038 def __init__(self):
Dietmar Eggemannf545f852014-12-30 11:56:22 +010039 super(SchedLoadAvgSchedGroup, self).__init__(
Dietmar Eggemannf545f852014-12-30 11:56:22 +010040 unique_word=self.unique_word,
41 )
42
43 def finalize_object(self):
44 """This condition is necessary to force column 'cpus' to be printed
45 as 8 digits w/ leading 0
46 """
47 if self._cpu_mask_column in self.data_frame.columns:
Javi Merino81cbdd82015-06-19 16:47:44 +010048 dfr = self.data_frame[self._cpu_mask_column].apply('{:0>8}'.format)
49 self.data_frame[self._cpu_mask_column] = dfr
Dietmar Eggemannf545f852014-12-30 11:56:22 +010050
Javi Merino323bb8d2015-04-20 17:09:15 +010051Run.register_class(SchedLoadAvgSchedGroup, "sched")
52
Dietmar Eggemannf545f852014-12-30 11:56:22 +010053class SchedLoadAvgTask(Base):
54 """Corresponds to Linux kernel trace event sched_load_avg_task"""
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010055
Javi Merino81cbdd82015-06-19 16:47:44 +010056 unique_word = "sched_load_avg_task:"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010057 """The unique word that will be matched in a trace line"""
58
Javi Merino81cbdd82015-06-19 16:47:44 +010059 name = "sched_load_avg_task"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010060 """The name of the :mod:`pandas.DataFrame` member that will be created in a
61 :mod:`trappy.run.Run` object"""
Dietmar Eggemannf545f852014-12-30 11:56:22 +010062
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +000063 pivot = "pid"
64 """The Pivot along which the data is orthogonal"""
65
Javi Merino6f34d902015-02-21 11:39:09 +000066 def __init__(self):
Dietmar Eggemannf545f852014-12-30 11:56:22 +010067 super(SchedLoadAvgTask, self).__init__(
Dietmar Eggemannf545f852014-12-30 11:56:22 +010068 unique_word=self.unique_word,
69 )
70
71 def get_pids(self, key=""):
72 """Returns a list of (comm, pid) that contain
73 'key' in their 'comm'."""
Javi Merino81cbdd82015-06-19 16:47:44 +010074 dfr = self.data_frame.drop_duplicates(subset=['comm', 'pid'])
75 dfr = dfr.ix[:, ['comm', 'pid']]
Dietmar Eggemannf545f852014-12-30 11:56:22 +010076
Javi Merino81cbdd82015-06-19 16:47:44 +010077 return dfr[dfr['comm'].str.contains(key)].values.tolist()
Dietmar Eggemannf545f852014-12-30 11:56:22 +010078
Javi Merino323bb8d2015-04-20 17:09:15 +010079Run.register_class(SchedLoadAvgTask, "sched")
Dietmar Eggemannf545f852014-12-30 11:56:22 +010080
Javi Merino81cbdd82015-06-19 16:47:44 +010081# pylint doesn't like globals that are not ALL_CAPS
82# pylint: disable=invalid-name
Kapileshwar Singhff2b31e2015-05-15 16:24:56 +010083SchedLoadAvgCpu = register_dynamic("SchedLoadAvgCpu",
84 "sched_load_avg_cpu:",
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +000085 "sched", pivot="cpu")
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010086"""Load and Utilization Signals for CPUs"""
Kapileshwar Singhff2b31e2015-05-15 16:24:56 +010087
88SchedContribScaleFactor = register_dynamic("SchedContribScaleFactor",
89 "sched_contrib_scale_f:",
90 "sched")
Kapileshwar Singh34825fa2015-09-09 14:52:16 +010091"""Event to register tracing of contrib factor"""
Kapileshwar Singhff2b31e2015-05-15 16:24:56 +010092
Patrick Bellasi4ce5fe22015-11-13 18:35:19 +000093class SchedCpuCapacity(Base):
94 """Corresponds to Linux kernel trace event sched/cpu_capacity"""
95
96 unique_word = "cpu_capacity:"
97 """The unique word that will be matched in a trace line"""
98
99 name = "sched_cpu_capacity"
100 """The name of the :mod:`pandas.DataFrame` member that will be created in a
101 :mod:`trappy.run.Run` object"""
102
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +0000103 pivot = "cpu"
104 """The Pivot along which the data is orthogonal"""
105
Patrick Bellasi4ce5fe22015-11-13 18:35:19 +0000106 def __init__(self):
107 super(SchedCpuCapacity, self).__init__(
108 unique_word=self.unique_word,
109 )
110
111 def finalize_object(self):
112 """This renaming is necessary because our cpu related pivot is 'cpu'
113 and not 'cpu_id'. Otherwise you cannot 'mix and match' with other
114 classes
115 """
116 self.data_frame.rename(columns={'cpu_id':'cpu'}, inplace=True)
Patrick Bellasi8dd24172015-11-16 12:38:09 +0000117 self.data_frame.rename(columns={'state' :'capacity'}, inplace=True)
Patrick Bellasi4ce5fe22015-11-13 18:35:19 +0000118
119Run.register_class(SchedCpuCapacity, "sched")
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100120
Kapileshwar Singh8733fa62015-06-18 23:01:22 +0100121SchedSwitch = register_dynamic("SchedSwitch",
122 "sched_switch",
123 "sched",
124 parse_raw=True)
Kapileshwar Singh34825fa2015-09-09 14:52:16 +0100125"""Register SchedSwitch Event"""
Javi Merino81cbdd82015-06-19 16:47:44 +0100126# pylint: enable=invalid-name
Kapileshwar Singh8733fa62015-06-18 23:01:22 +0100127
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100128class SchedCpuFrequency(Base):
129 """Corresponds to Linux kernel trace event power/cpu_frequency"""
Kapileshwar Singh34825fa2015-09-09 14:52:16 +0100130
Javi Merino81cbdd82015-06-19 16:47:44 +0100131 unique_word = "cpu_frequency:"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +0100132 """The unique word that will be matched in a trace line"""
133
Javi Merino81cbdd82015-06-19 16:47:44 +0100134 name = "sched_cpu_frequency"
Kapileshwar Singh34825fa2015-09-09 14:52:16 +0100135 """The name of the :mod:`pandas.DataFrame` member that will be created in a
136 :mod:`trappy.run.Run` object"""
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100137
Kapileshwar Singhbd1a5c12015-11-19 14:53:59 +0000138 pivot = "cpu"
139 """The Pivot along which the data is orthogonal"""
140
Javi Merino6f34d902015-02-21 11:39:09 +0000141 def __init__(self):
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100142 super(SchedCpuFrequency, self).__init__(
Dietmar Eggemannf545f852014-12-30 11:56:22 +0100143 unique_word=self.unique_word,
144 )
145
146 def finalize_object(self):
147 """This renaming is necessary because our cpu related pivot is 'cpu'
148 and not 'cpu_id'. Otherwise you cannot 'mix and match' with other
149 classes
150 """
151 self.data_frame.rename(columns={'cpu_id':'cpu'}, inplace=True)
Patrick Bellasi8dd24172015-11-16 12:38:09 +0000152 self.data_frame.rename(columns={'state' :'frequency'}, inplace=True)
Javi Merino323bb8d2015-04-20 17:09:15 +0100153
154Run.register_class(SchedCpuFrequency, "sched")