blob: cee68ab05314b4671d1e5abaf1bcfbc52e72543a [file] [log] [blame]
Javi Merinoc47d2df2015-02-06 16:04:03 +00001# $Copyright:
2# ----------------------------------------------------------------
3# This confidential and proprietary software may be used only as
4# authorised by a licensing agreement from ARM Limited
5# (C) COPYRIGHT 2015 ARM Limited
6# ALL RIGHTS RESERVED
7# The entire notice above must be reproduced on all authorised
8# copies and copies may only be made to the extent permitted
9# by a licensing agreement from ARM Limited.
10# ----------------------------------------------------------------
11# File: sched.py
12# ----------------------------------------------------------------
13# $
14#
Dietmar Eggemannf545f852014-12-30 11:56:22 +010015
Javi Merino81cbdd82015-06-19 16:47:44 +010016"""Definitions of scheduler events registered by the Run class"""
17
Javi Merino91e92dc2015-06-17 17:02:03 +010018from cr2.base import Base
Javi Merino323bb8d2015-04-20 17:09:15 +010019from cr2.dynamic import register_dynamic
20from cr2.run import Run
Dietmar Eggemannf545f852014-12-30 11:56:22 +010021
22class SchedLoadAvgSchedGroup(Base):
23 """Corresponds to Linux kernel trace event sched_load_avg_sched_group"""
Javi Merino81cbdd82015-06-19 16:47:44 +010024 unique_word = "sched_load_avg_sg:"
25 name = "sched_load_avg_sched_group"
Dietmar Eggemannf545f852014-12-30 11:56:22 +010026 _cpu_mask_column = "cpus"
27
Javi Merino6f34d902015-02-21 11:39:09 +000028 def __init__(self):
Dietmar Eggemannf545f852014-12-30 11:56:22 +010029 super(SchedLoadAvgSchedGroup, self).__init__(
Dietmar Eggemannf545f852014-12-30 11:56:22 +010030 unique_word=self.unique_word,
31 )
32
33 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 Merino323bb8d2015-04-20 17:09:15 +010041Run.register_class(SchedLoadAvgSchedGroup, "sched")
42
Dietmar Eggemannf545f852014-12-30 11:56:22 +010043class SchedLoadAvgTask(Base):
44 """Corresponds to Linux kernel trace event sched_load_avg_task"""
Javi Merino81cbdd82015-06-19 16:47:44 +010045 unique_word = "sched_load_avg_task:"
46 name = "sched_load_avg_task"
Dietmar Eggemannf545f852014-12-30 11:56:22 +010047
Javi Merino6f34d902015-02-21 11:39:09 +000048 def __init__(self):
Dietmar Eggemannf545f852014-12-30 11:56:22 +010049 super(SchedLoadAvgTask, self).__init__(
Dietmar Eggemannf545f852014-12-30 11:56:22 +010050 unique_word=self.unique_word,
51 )
52
53 def get_pids(self, key=""):
54 """Returns a list of (comm, pid) that contain
55 'key' in their 'comm'."""
Javi Merino81cbdd82015-06-19 16:47:44 +010056 dfr = self.data_frame.drop_duplicates(subset=['comm', 'pid'])
57 dfr = dfr.ix[:, ['comm', 'pid']]
Dietmar Eggemannf545f852014-12-30 11:56:22 +010058
Javi Merino81cbdd82015-06-19 16:47:44 +010059 return dfr[dfr['comm'].str.contains(key)].values.tolist()
Dietmar Eggemannf545f852014-12-30 11:56:22 +010060
Javi Merino323bb8d2015-04-20 17:09:15 +010061Run.register_class(SchedLoadAvgTask, "sched")
Dietmar Eggemannf545f852014-12-30 11:56:22 +010062
Javi Merino81cbdd82015-06-19 16:47:44 +010063# pylint doesn't like globals that are not ALL_CAPS
64# pylint: disable=invalid-name
Kapileshwar Singhff2b31e2015-05-15 16:24:56 +010065SchedLoadAvgCpu = register_dynamic("SchedLoadAvgCpu",
66 "sched_load_avg_cpu:",
67 "sched")
68
69SchedContribScaleFactor = register_dynamic("SchedContribScaleFactor",
70 "sched_contrib_scale_f:",
71 "sched")
72
73SchedCpuCapacity = register_dynamic("SchedCpuCapacity",
74 "sched_cpu_capacity:",
75 "sched")
Dietmar Eggemannf545f852014-12-30 11:56:22 +010076
Kapileshwar Singh8733fa62015-06-18 23:01:22 +010077SchedSwitch = register_dynamic("SchedSwitch",
78 "sched_switch",
79 "sched",
80 parse_raw=True)
Javi Merino81cbdd82015-06-19 16:47:44 +010081# pylint: enable=invalid-name
Kapileshwar Singh8733fa62015-06-18 23:01:22 +010082
Dietmar Eggemannf545f852014-12-30 11:56:22 +010083class SchedCpuFrequency(Base):
84 """Corresponds to Linux kernel trace event power/cpu_frequency"""
Javi Merino81cbdd82015-06-19 16:47:44 +010085 unique_word = "cpu_frequency:"
86 name = "sched_cpu_frequency"
Dietmar Eggemannf545f852014-12-30 11:56:22 +010087
Javi Merino6f34d902015-02-21 11:39:09 +000088 def __init__(self):
Dietmar Eggemannf545f852014-12-30 11:56:22 +010089 super(SchedCpuFrequency, self).__init__(
Dietmar Eggemannf545f852014-12-30 11:56:22 +010090 unique_word=self.unique_word,
91 )
92
93 def finalize_object(self):
94 """This renaming is necessary because our cpu related pivot is 'cpu'
95 and not 'cpu_id'. Otherwise you cannot 'mix and match' with other
96 classes
97 """
98 self.data_frame.rename(columns={'cpu_id':'cpu'}, inplace=True)
Javi Merino323bb8d2015-04-20 17:09:15 +010099
100Run.register_class(SchedCpuFrequency, "sched")