Javi Merino | c47d2df | 2015-02-06 16:04:03 +0000 | [diff] [blame] | 1 | # $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 Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 15 | |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 16 | """Definitions of scheduler events registered by the Run class""" |
| 17 | |
Javi Merino | 91e92dc | 2015-06-17 17:02:03 +0100 | [diff] [blame] | 18 | from cr2.base import Base |
Javi Merino | 323bb8d | 2015-04-20 17:09:15 +0100 | [diff] [blame] | 19 | from cr2.dynamic import register_dynamic |
| 20 | from cr2.run import Run |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 21 | |
| 22 | class SchedLoadAvgSchedGroup(Base): |
| 23 | """Corresponds to Linux kernel trace event sched_load_avg_sched_group""" |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 24 | unique_word = "sched_load_avg_sg:" |
| 25 | name = "sched_load_avg_sched_group" |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 26 | _cpu_mask_column = "cpus" |
| 27 | |
Javi Merino | 6f34d90 | 2015-02-21 11:39:09 +0000 | [diff] [blame] | 28 | def __init__(self): |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 29 | super(SchedLoadAvgSchedGroup, self).__init__( |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 30 | 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 Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 38 | dfr = self.data_frame[self._cpu_mask_column].apply('{:0>8}'.format) |
| 39 | self.data_frame[self._cpu_mask_column] = dfr |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 40 | |
Javi Merino | 323bb8d | 2015-04-20 17:09:15 +0100 | [diff] [blame] | 41 | Run.register_class(SchedLoadAvgSchedGroup, "sched") |
| 42 | |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 43 | class SchedLoadAvgTask(Base): |
| 44 | """Corresponds to Linux kernel trace event sched_load_avg_task""" |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 45 | unique_word = "sched_load_avg_task:" |
| 46 | name = "sched_load_avg_task" |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 47 | |
Javi Merino | 6f34d90 | 2015-02-21 11:39:09 +0000 | [diff] [blame] | 48 | def __init__(self): |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 49 | super(SchedLoadAvgTask, self).__init__( |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 50 | 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 Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 56 | dfr = self.data_frame.drop_duplicates(subset=['comm', 'pid']) |
| 57 | dfr = dfr.ix[:, ['comm', 'pid']] |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 58 | |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 59 | return dfr[dfr['comm'].str.contains(key)].values.tolist() |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 60 | |
Javi Merino | 323bb8d | 2015-04-20 17:09:15 +0100 | [diff] [blame] | 61 | Run.register_class(SchedLoadAvgTask, "sched") |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 62 | |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 63 | # pylint doesn't like globals that are not ALL_CAPS |
| 64 | # pylint: disable=invalid-name |
Kapileshwar Singh | ff2b31e | 2015-05-15 16:24:56 +0100 | [diff] [blame] | 65 | SchedLoadAvgCpu = register_dynamic("SchedLoadAvgCpu", |
| 66 | "sched_load_avg_cpu:", |
| 67 | "sched") |
| 68 | |
| 69 | SchedContribScaleFactor = register_dynamic("SchedContribScaleFactor", |
| 70 | "sched_contrib_scale_f:", |
| 71 | "sched") |
| 72 | |
| 73 | SchedCpuCapacity = register_dynamic("SchedCpuCapacity", |
| 74 | "sched_cpu_capacity:", |
| 75 | "sched") |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 76 | |
Kapileshwar Singh | 8733fa6 | 2015-06-18 23:01:22 +0100 | [diff] [blame] | 77 | SchedSwitch = register_dynamic("SchedSwitch", |
| 78 | "sched_switch", |
| 79 | "sched", |
| 80 | parse_raw=True) |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 81 | # pylint: enable=invalid-name |
Kapileshwar Singh | 8733fa6 | 2015-06-18 23:01:22 +0100 | [diff] [blame] | 82 | |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 83 | class SchedCpuFrequency(Base): |
| 84 | """Corresponds to Linux kernel trace event power/cpu_frequency""" |
Javi Merino | 81cbdd8 | 2015-06-19 16:47:44 +0100 | [diff] [blame^] | 85 | unique_word = "cpu_frequency:" |
| 86 | name = "sched_cpu_frequency" |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 87 | |
Javi Merino | 6f34d90 | 2015-02-21 11:39:09 +0000 | [diff] [blame] | 88 | def __init__(self): |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 89 | super(SchedCpuFrequency, self).__init__( |
Dietmar Eggemann | f545f85 | 2014-12-30 11:56:22 +0100 | [diff] [blame] | 90 | 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 Merino | 323bb8d | 2015-04-20 17:09:15 +0100 | [diff] [blame] | 99 | |
| 100 | Run.register_class(SchedCpuFrequency, "sched") |