Home | History | Annotate | Download | only in plotter
      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 """Init Module for the Plotter Code"""
     17 
     18 
     19 import pandas as pd
     20 import LinePlot
     21 import AttrConf
     22 try:
     23     import trappy.plotter.EventPlot
     24 except ImportError:
     25     pass
     26 import Utils
     27 import trappy
     28 import IPythonConf
     29 
     30 def register_forwarding_arg(arg_name):
     31     """Allows the user to register args to
     32        be forwarded to matplotlib
     33 
     34     :param arg_name: The arg to register
     35     :type arg_name: str
     36     """
     37     if arg_name not in AttrConf.ARGS_TO_FORWARD:
     38         AttrConf.ARGS_TO_FORWARD.append(arg_name)
     39 
     40 def unregister_forwarding_arg(arg_name):
     41     """Unregisters arg_name from being passed to
     42        plotter matplotlib calls
     43 
     44     :param arg_name: The arg to register
     45     :type arg_name: str
     46     """
     47     try:
     48         AttrConf.ARGS_TO_FORWARD.remove(arg_name)
     49     except ValueError:
     50         pass
     51 
     52 def plot_trace(trace,
     53                execnames=None,
     54                pids=None):
     55     """Creates a kernelshark like plot of the trace file
     56 
     57     :param trace: The path to the trace or a trace object
     58     :type trace: str, :mod:`trappy.trace.FTrace`, :mod:`trappy.trace.SysTrace`
     59         or :mod:`trappy.trace.BareTrace`.
     60 
     61     :param execnames: List of execnames to be filtered. If not
     62         specified all execnames will be plotted
     63     :type execnames: list, str
     64 
     65     :param pids: List of pids to be filtered. If not specified
     66         all pids will be plotted
     67     :type pids: list, str
     68     """
     69 
     70     if not IPythonConf.check_ipython():
     71         raise RuntimeError("plot_trace needs ipython environment")
     72 
     73     if not isinstance(trace, trappy.BareTrace):
     74         if trace.endswith("html"):
     75             trace = trappy.SysTrace(trace)
     76         else:
     77             trace = trappy.FTrace(trace)
     78 
     79     data, procs, domain = Utils.get_trace_event_data(trace, execnames, pids)
     80     trace_graph = EventPlot.EventPlot(data, procs, domain,
     81                                       lane_prefix="CPU :",
     82                                       num_lanes=int(trace._cpus))
     83     trace_graph.view()
     84