# 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" pivot = "cpu_id" 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)
"""The unique word that will be matched in a trace line""" _cpu_mask_column = "cpus" pivot = "cpus" """The Pivot along which the data is orthogonal""" def finalize_object(self): """This condition is necessary to force column 'cpus' to be printed as 8 digits w/ leading 0 """ if self._cpu_mask_column in self.data_frame.columns: dfr = self.data_frame[self._cpu_mask_column].apply('{:0>8}'.format) self.data_frame[self._cpu_mask_column] = dfr register_ftrace_parser(SchedLoadAvgSchedGroup, "sched") class SchedLoadAvgTask(Base): """Corresponds to Linux kernel trace event sched_load_avg_task""" unique_word = "sched_load_avg_task:" """The unique word that will be matched in a trace line""" pivot = "pid" """The Pivot along which the data is orthogonal""" def get_pids(self, key=""): """Returns a list of (comm, pid) that contain 'key' in their 'comm'.""" dfr = self.data_frame.drop_duplicates(subset=['comm', 'pid']) dfr = dfr.ix[:, ['comm', 'pid']]
unique_word = "thermal_power_devfreq_get_power:" """The event name in the trace""" def get_all_freqs(self): """Return a :mod:`pandas.DataFrame` with the frequencies for the devfreq device The format should be the same as the one for :code:`CpuInPower().get_all_freqs()`. .. note:: Frequencies are in MHz. """ return pd.DataFrame(self.data_frame["freq"] / 1000000) register_ftrace_parser(DevfreqInPower, "thermal") class DevfreqOutPower(Base): """Process de devfreq cooling device data regarding power2state in an ftrace dump""" name = "devfreq_out_power" """The name of the :mod:`pandas.DataFrame` member that will be created in a :mod:`trappy.ftrace.FTrace` object""" unique_word = "thermal_power_devfreq_limit:" """The event name in the trace""" def get_all_freqs(self): """Return a :mod:`pandas.DataFrame` with the output frequencies for the devfreq device
def register_class(*args, **kwargs): """register_class() is deprecated. Use register_ftrace_parser() instead""" warnings.warn("register_class() is deprecated. Use register_ftrace_parser() instead") return register_ftrace_parser(*args, **kwargs)
"""This module contains the class for representing a tracing_mark_write trace_event used for ftrace events injected from userspace. """ from trappy.base import Base from trappy.dynamic import register_ftrace_parser class TracingMarkWrite(Base): """Parse tracing_mark_write events that couldn't be matched with more specific unique words This class is always used as a fallback if nothing more specific could match the particular tracing_mark_write event. """ unique_word = "tracing_mark_write" def generate_data_dict(self, data_str): if self.tracer: data_dict = self.tracer.generate_data_dict(data_str) if data_dict: return data_dict data_dict = {'string': data_str} return data_dict def __init__(self): super(TracingMarkWrite, self).__init__(fallback=True) register_ftrace_parser(TracingMarkWrite)
def get_all_freqs(self, mapping_label): """Get a :mod:`pandas.DataFrame` with the maximum frequencies allowed by the governor :param mapping_label: A dictionary that maps cpumasks to name of the cpu. :type mapping_label: dict :return: freqs are in MHz """ dfr = self.data_frame return pivot_with_labels(dfr, "freq", "cpus", mapping_label) / 1000 register_ftrace_parser(CpuOutPower, "thermal") class CpuInPower(Base): """Process the cpufreq cooling power actor data in a ftrace dump """ unique_word = "thermal_power_cpu_get" """The unique word that will be matched in a trace line""" name = "cpu_in_power" """The name of the :mod:`pandas.DataFrame` member that will be created in a :mod:`trappy.ftrace.FTrace` object""" pivot = "cpus" """The Pivot along which the data is orthogonal"""
# Copyright 2019 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 __future__ import unicode_literals from trappy.base import Base from trappy.dynamic import register_ftrace_parser class FunctionTracer(Base): """Parse 'function' events ('function' tracer)""" unique_word = "function" parse_raw = True def __init__(self): super().__init__(parse_raw=self.parse_raw) register_ftrace_parser(FunctionTracer)
# 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" pivot = "cpu_id" 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)
:param ax: Axis instance :type ax: :mod:`matplotlib.Axis` :param title: The title of the plot :type title: str """ from trappy.plot_utils import normalize_title, plot_hist temps = self.data_frame["temp"] / 1000 title = normalize_title("Temperature", title) xlim = (0, temps.max()) plot_hist(temps, ax, title, "C", 30, "Temperature", xlim, "default") register_ftrace_parser(Thermal, "thermal") class ThermalGovernor(Base): """Process the power allocator data in a ftrace dump""" unique_word = "thermal_power_allocator:" """The unique word that will be matched in a trace line""" name = "thermal_governor" """The name of the :mod:`pandas.DataFrame` member that will be created in a :mod:`trappy.ftrace.FTrace` object""" pivot = "thermal_zone_id" """The Pivot along which the data is orthogonal""" def plot_temperature(self, title="", width=None, height=None, ylim="range",
class CommonClkBase(Base): #clock traces are of the form "clk_name field0=x field1=y ..." def generate_data_dict(self, data_str): clk_name, fields = data_str.split(' ', 1) ret = super(CommonClkBase, self).generate_data_dict(fields) ret['clk_name'] = clk_name return ret class CommonClkEnable(CommonClkBase): """Corresponds to Linux kernel trace event clock_enable""" unique_word = "clock_enable:" """The unique word that will be matched in a trace line""" register_ftrace_parser(CommonClkEnable) class CommonClkDisable(CommonClkBase): """Corresponds to Linux kernel trace event clock_disable""" unique_word = "clock_disable:" """The unique word that will be matched in a trace line""" register_ftrace_parser(CommonClkDisable) class CommonClkSetRate(CommonClkBase): """Corresponds to Linux kernel trace event clock_set_rate""" unique_word = "clock_set_rate:" """The unique word that will be matched in a trace line"""
def get_all_freqs(self, mapping_label): """Get a :mod:`pandas.DataFrame` with the maximum frequencies allowed by the governor :param mapping_label: A dictionary that maps cpumasks to name of the cpu. :type mapping_label: dict :return: freqs are in MHz """ dfr = self.data_frame return pivot_with_labels(dfr, "freq", "cpus", mapping_label) / 1000 register_ftrace_parser(CpuOutPower, "thermal") class CpuInPower(Base): """Process the cpufreq cooling power actor data in a ftrace dump """ unique_word = "thermal_power_cpu_get" """The unique word that will be matched in a trace line""" name = "cpu_in_power" """The name of the :mod:`pandas.DataFrame` member that will be created in a :mod:`trappy.ftrace.FTrace` object""" pivot = "cpus" """The Pivot along which the data is orthogonal"""
def register_class(*args, **kwargs): """register_class() is deprecated. Use register_ftrace_parser() instead""" warnings.warn("register_class() is deprecated. Use register_ftrace_parser() instead") return register_ftrace_parser(*args, **kwargs)
unique_word = "thermal_power_allocator_pid" """The event name in the trace""" def plot_controller(self, title="", width=None, height=None, ax=None): """Plot a summary of the controller data :param ax: Axis instance :type ax: :mod:`matplotlib.Axis` :param title: The title of the plot :type title: str :param width: The width of the plot :type width: int :param height: The height of the plot :type int: int """ import trappy.plot_utils title = trappy.plot_utils.normalize_title("PID", title) if not ax: ax = trappy.plot_utils.pre_plot_setup(width, height) self.data_frame[["output", "p", "i", "d"]].plot(ax=ax) trappy.plot_utils.post_plot_setup(ax, title=title) register_ftrace_parser(PIDController, "thermal")
# limitations under the License. # from __future__ import unicode_literals from trappy.base import Base from trappy.dynamic import register_ftrace_parser class FuncgraphEntry(Base): """Parse funcgraph_entry""" unique_word = "funcgraph_entry" parse_raw = True def __init__(self): super().__init__(parse_raw=self.parse_raw) register_ftrace_parser(FuncgraphEntry) class FuncgraphExit(Base): """Parse funcgraph_exit""" unique_word = "funcgraph_exit" parse_raw = True def __init__(self): super().__init__(parse_raw=self.parse_raw) register_ftrace_parser(FuncgraphExit)
:param ax: Axis instance :type ax: :mod:`matplotlib.Axis` :param title: The title of the plot :type title: str """ from trappy.plot_utils import normalize_title, plot_hist temps = self.data_frame["temp"] / 1000 title = normalize_title("Temperature", title) xlim = (0, temps.max()) plot_hist(temps, ax, title, "C", 30, "Temperature", xlim, "default") register_ftrace_parser(Thermal, "thermal") class ThermalGovernor(Base): """Process the power allocator data in a ftrace dump""" unique_word = "thermal_power_allocator:" """The unique word that will be matched in a trace line""" name = "thermal_governor" """The name of the :mod:`pandas.DataFrame` member that will be created in a :mod:`trappy.ftrace.FTrace` object""" pivot = "thermal_zone_id" """The Pivot along which the data is orthogonal"""
"""The unique word that will be matched in a trace line""" _cpu_mask_column = "cpus" pivot = "cpus" """The Pivot along which the data is orthogonal""" def finalize_object(self): """This condition is necessary to force column 'cpus' to be printed as 8 digits w/ leading 0 """ if self._cpu_mask_column in self.data_frame.columns: dfr = self.data_frame[self._cpu_mask_column].apply('{:0>8}'.format) self.data_frame[self._cpu_mask_column] = dfr register_ftrace_parser(SchedLoadAvgSchedGroup, "sched") class SchedLoadAvgTask(Base): """Corresponds to Linux kernel trace event sched_load_avg_task""" unique_word = "sched_load_avg_task:" """The unique word that will be matched in a trace line""" pivot = "pid" """The Pivot along which the data is orthogonal""" def get_pids(self, key=""): """Returns a list of (comm, pid) that contain 'key' in their 'comm'.""" dfr = self.data_frame.drop_duplicates(subset=['comm', 'pid']) dfr = dfr.ix[:, ['comm', 'pid']]
#fieldA valueA fieldB valueB ... data = data_str.split(' ') return zip(data[0::2], data[1::2]) def finalize_object(self): self.data_frame.rename(columns={'ino':'inode'}, inplace=True) class FilesystemExt4DaWriteBegin(FilesystemExt4Base): """Corresponds to Linux kernel trace event ext4_da_write_begin""" unique_word = "ext4_da_write_begin:" """The unique word that will be matched in a trace line""" register_ftrace_parser(FilesystemExt4DaWriteBegin) class FilesystemExt4DaWriteEnd(FilesystemExt4Base): """Corresponds to Linux kernel trace event ext4_da_write_end""" unique_word = "ext4_da_write_end:" """The unique word that will be matched in a trace line""" register_ftrace_parser(FilesystemExt4DaWriteEnd) class FilesystemExt4SyncFileEnter(FilesystemExt4Base): """Corresponds to Linux kernel trace event ext4_sync_file_enter""" unique_word = "ext4_sync_file_enter:" """The unique word that will be matched in a trace line"""
match = self.pat.search(line) num, *args = match.group(1, 2, 3, 4, 5, 6, 7) num = int(num) args = [int(x, 16) for x in args] ret = "nr={} arg0={} arg1={} arg2={} arg3={} arg4={} arg5={}".format( num, args[0], args[1], args[2], args[3], args[4], args[5]) return ret except Exception as e: raise ValueError("failed to parse line {}: {}".format(line, e)) def create_dataframe(self): self.data_array = [self.explode(line) for line in self.data_array] super(SysEnter, self).create_dataframe() register_ftrace_parser(SysEnter) class SysExit(Base): """Parse sys exit""" unique_word = "sys_exit" pivot = "pid" parse_raw = False pat = re.compile("NR ([-+]?\d+) = ([-+]?\d+)") def __init__(self): super(SysExit, self).__init__(parse_raw=self.parse_raw) def explode(self, line): """ trace-cmd-29016 [000] 99937.172659: sys_exit: NR 64 = 1 """
unique_word = "thermal_power_allocator_pid" """The event name in the trace""" def plot_controller(self, title="", width=None, height=None, ax=None): """Plot a summary of the controller data :param ax: Axis instance :type ax: :mod:`matplotlib.Axis` :param title: The title of the plot :type title: str :param width: The width of the plot :type width: int :param height: The height of the plot :type int: int """ import trappy.plot_utils title = trappy.plot_utils.normalize_title("PID", title) if not ax: ax = trappy.plot_utils.pre_plot_setup(width, height) self.data_frame[["output", "p", "i", "d"]].plot(ax=ax) trappy.plot_utils.post_plot_setup(ax, title=title) register_ftrace_parser(PIDController, "thermal")
unique_word="thermal_power_devfreq_get_power:" """The event name in the trace""" def get_all_freqs(self): """Return a :mod:`pandas.DataFrame` with the frequencies for the devfreq device The format should be the same as the one for :code:`CpuInPower().get_all_freqs()`. .. note:: Frequencies are in MHz. """ return pd.DataFrame(self.data_frame["freq"] / 1000000) register_ftrace_parser(DevfreqInPower, "thermal") class DevfreqOutPower(Base): """Process de devfreq cooling device data regarding power2state in an ftrace dump""" name = "devfreq_out_power" """The name of the :mod:`pandas.DataFrame` member that will be created in a :mod:`trappy.ftrace.FTrace` object""" unique_word="thermal_power_devfreq_limit:" """The event name in the trace""" def get_all_freqs(self): """Return a :mod:`pandas.DataFrame` with