1#    Copyright 2015-2017 ARM Limited
2#
3# 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
16"""Process the output of the power allocator's PID controller in the
17current directory's trace.dat"""
18
19from trappy.base import Base
20from trappy.dynamic import register_ftrace_parser
21
22class PIDController(Base):
23    """Process the power allocator PID controller data in a FTrace dump"""
24
25    name = "pid_controller"
26    """The name of the :mod:`pandas.DataFrame` member that will be created in a
27    :mod:`trappy.ftrace.FTrace` object"""
28
29    pivot = "thermal_zone_id"
30    """The Pivot along which the data is orthogonal"""
31
32    unique_word="thermal_power_allocator_pid"
33    """The event name in the trace"""
34
35    def plot_controller(self, title="", width=None, height=None, ax=None):
36        """Plot a summary of the controller data
37
38        :param ax: Axis instance
39        :type ax: :mod:`matplotlib.Axis`
40
41        :param title: The title of the plot
42        :type title: str
43
44        :param width: The width of the plot
45        :type width: int
46
47        :param height: The height of the plot
48        :type int: int
49        """
50        import trappy.plot_utils
51
52        title = trappy.plot_utils.normalize_title("PID", title)
53
54        if not ax:
55            ax = trappy.plot_utils.pre_plot_setup(width, height)
56
57        self.data_frame[["output", "p", "i", "d"]].plot(ax=ax)
58        trappy.plot_utils.post_plot_setup(ax, title=title)
59
60register_ftrace_parser(PIDController, "thermal")
61