blob: 67b9f6cda8ecc857abe9691e9eb4840c36dd6595 [file] [log] [blame]
Javi Merino491cf732014-03-31 17:34:44 +01001#!/usr/bin/python
Javi Merino5bd3d442014-04-08 12:55:13 +01002"""Process the output of the power allocator trace in the current
3directory's trace.dat"""
Javi Merino572049d2014-03-31 16:45:23 +01004
5import os
Javi Merinoee56c362014-03-31 17:30:34 +01006import re
Javi Merinoa6399fb2014-03-31 19:17:08 +01007from matplotlib import pyplot as plt
Javi Merino572049d2014-03-31 16:45:23 +01008
Dietmar Eggemannb42a50b2014-12-11 20:28:45 +00009from base import Base
Javi Merino1a3dca32014-08-11 16:12:50 +010010from plot_utils import normalize_title, pre_plot_setup, post_plot_setup, plot_hist
Javi Merino51db3632014-06-13 11:24:51 +010011
Dietmar Eggemannb42a50b2014-12-11 20:28:45 +000012class Thermal(Base):
Javi Merino0e83b612014-06-05 11:45:23 +010013 """Process the thermal framework data in a ftrace dump"""
KP Singh7319a882014-12-24 18:18:01 +000014
15 unique_word="thermal_temperature:"
16 name="thermal"
17
Javi Merino0e83b612014-06-05 11:45:23 +010018 def __init__(self, path=None):
19 super(Thermal, self).__init__(
20 basepath=path,
KP Singh7319a882014-12-24 18:18:01 +000021 unique_word=self.unique_word,
Javi Merino0e83b612014-06-05 11:45:23 +010022 )
23
Javi Merino516d5942014-06-26 15:06:04 +010024 def plot_temperature(self, control_temperature=None, title="", width=None,
Javi Merino80114162014-08-08 16:48:32 +010025 height=None, ylim="range", ax=None, legend_label=""):
Javi Merino516d5942014-06-26 15:06:04 +010026 """Plot the temperature.
27
28 If control_temp is a pd.Series() representing the (possible)
29 variation of control_temp during the run, draw it using a
30 dashed yellow line. Otherwise, only the temperature is
31 plotted.
32
33 """
Javi Merinoc68737a2014-06-10 15:21:59 +010034 title = normalize_title("Temperature", title)
35
Javi Merino49cbcfe2014-08-08 16:03:49 +010036 setup_plot = False
37 if not ax:
38 ax = pre_plot_setup(width, height)
39 setup_plot = True
40
Javi Merino80114162014-08-08 16:48:32 +010041 temp_label = normalize_title("Temperature", legend_label)
Javi Merino92f4d012014-08-08 17:55:32 +010042 (self.data_frame["temp"] / 1000).plot(ax=ax, label=temp_label)
Javi Merino516d5942014-06-26 15:06:04 +010043 if control_temperature is not None:
Javi Merino80114162014-08-08 16:48:32 +010044 ct_label = normalize_title("Control", legend_label)
Javi Merino516d5942014-06-26 15:06:04 +010045 control_temperature.plot(ax=ax, color="y", linestyle="--",
Javi Merino80114162014-08-08 16:48:32 +010046 label=ct_label)
Javi Merinoc68737a2014-06-10 15:21:59 +010047
Javi Merino49cbcfe2014-08-08 16:03:49 +010048 if setup_plot:
49 post_plot_setup(ax, title=title, ylim=ylim)
50 plt.legend()
Javi Merinoc68737a2014-06-10 15:21:59 +010051
Javi Merinoe5ea60a2014-08-12 16:41:42 +010052 def plot_temperature_hist(self, ax, title):
Javi Merino1a3dca32014-08-11 16:12:50 +010053 """Plot a temperature histogram"""
54
55 temps = self.data_frame["temp"] / 1000
56 title = normalize_title("Temperature", title)
57 xlim = (0, temps.max())
58
Javi Merinoe5ea60a2014-08-12 16:41:42 +010059 plot_hist(temps, ax, title, 30, "Temperature", xlim, "default")
Javi Merino1a3dca32014-08-11 16:12:50 +010060
Dietmar Eggemannb42a50b2014-12-11 20:28:45 +000061class ThermalGovernor(Base):
Javi Merino5bd3d442014-04-08 12:55:13 +010062 """Process the power allocator data in a ftrace dump"""
KP Singh7319a882014-12-24 18:18:01 +000063
64 unique_word="thermal_power_allocator:"
65 name="thermal_governor"
Javi Merino68461552014-04-08 11:40:09 +010066 def __init__(self, path=None):
Javi Merino1e69e2c2014-06-04 18:25:09 +010067 super(ThermalGovernor, self).__init__(
Javi Merino68461552014-04-08 11:40:09 +010068 basepath=path,
KP Singh7319a882014-12-24 18:18:01 +000069 unique_word=self.unique_word,
Javi Merinoc2ec5682014-04-01 15:16:06 +010070 )
71
Javi Merino29223812014-08-12 15:24:43 +010072 def plot_input_power(self, actor_order, title="", width=None, height=None, ax=None):
Javi Merinod6d5f892014-07-03 16:24:23 +010073 """Plot input power
74
75 actor_order is an array with the order in which the actors were registered.
76 """
77
Javi Merino92f4d012014-08-08 17:55:32 +010078 dfr = self.data_frame
Javi Merinof7968a72014-07-03 15:35:02 +010079 in_cols = [s for s in dfr.columns if re.match("req_power[0-9]+", s)]
Javi Merinoe0ddf0d2014-05-07 18:40:12 +010080
Javi Merinod6d5f892014-07-03 16:24:23 +010081 plot_dfr = dfr[in_cols]
82 # Rename the columns from "req_power0" to "A15" or whatever is
83 # in actor_order. Note that we can do it just with an
84 # assignment because the columns are already sorted (i.e.:
85 # req_power0, req_power1...)
86 plot_dfr.columns = actor_order
87
Javi Merinoc00feff2014-04-14 15:41:51 +010088 title = normalize_title("Input Power", title)
Javi Merino8ecd8172014-07-03 16:09:01 +010089
Javi Merino29223812014-08-12 15:24:43 +010090 if not ax:
91 ax = pre_plot_setup(width, height)
92
Javi Merinod6d5f892014-07-03 16:24:23 +010093 plot_dfr.plot(ax=ax)
Javi Merino8ecd8172014-07-03 16:09:01 +010094 post_plot_setup(ax, title=title)
Javi Merino9c010772014-04-02 16:54:41 +010095
Javi Merino6003b252014-08-12 15:32:17 +010096 def plot_output_power(self, actor_order, title="", width=None, height=None, ax=None):
Javi Merinod6d5f892014-07-03 16:24:23 +010097 """Plot output power
98
99 actor_order is an array with the order in which the actors were registered.
100 """
101
Javi Merino92f4d012014-08-08 17:55:32 +0100102 out_cols = [s for s in self.data_frame.columns
Javi Merinof7968a72014-07-03 15:35:02 +0100103 if re.match("granted_power[0-9]+", s)]
Javi Merinoe0ddf0d2014-05-07 18:40:12 +0100104
Javi Merinod6d5f892014-07-03 16:24:23 +0100105 # See the note in plot_input_power()
Javi Merino92f4d012014-08-08 17:55:32 +0100106 plot_dfr = self.data_frame[out_cols]
Javi Merinod6d5f892014-07-03 16:24:23 +0100107 plot_dfr.columns = actor_order
108
Javi Merinoc00feff2014-04-14 15:41:51 +0100109 title = normalize_title("Output Power", title)
Javi Merino8ecd8172014-07-03 16:09:01 +0100110
Javi Merino6003b252014-08-12 15:32:17 +0100111 if not ax:
112 ax = pre_plot_setup(width, height)
113
Javi Merinod6d5f892014-07-03 16:24:23 +0100114 plot_dfr.plot(ax=ax)
Javi Merino8ecd8172014-07-03 16:09:01 +0100115 post_plot_setup(ax, title=title)
Javi Merinocd4a8272014-04-14 15:50:01 +0100116
Javi Merino9fc54852014-05-07 19:06:53 +0100117 def plot_inout_power(self, title="", width=None, height=None):
118 """Make multiple plots showing input and output power for each actor"""
Javi Merino92f4d012014-08-08 17:55:32 +0100119 dfr = self.data_frame
Javi Merino9fc54852014-05-07 19:06:53 +0100120
121 actors = []
122 for col in dfr.columns:
123 match = re.match("P(.*)_in", col)
124 if match and col != "Ptot_in":
125 actors.append(match.group(1))
126
127 for actor in actors:
128 cols = ["P" + actor + "_in", "P" + actor + "_out"]
129 this_title = normalize_title(actor, title)
130 dfr[cols].plot(title=this_title)