Ejemplo n.º 1
0
 def staticAnalysis(self, lang="fortran", regenerate=False):
     url = self.getSettingsRelativeURL("%s.static_analysis" % lang)
     dprint(url)
     filename = str(url.path)
     dprint(filename)
     if lang == "fortran":
         stats = FortranStaticAnalysis(serialized_filename=filename, regenerate=regenerate)
         if not regenerate and not stats.isEmpty():
             return url
         for source in self.walkProjectDir(["*.f", "*.f90"]):
             print source
             stats.scan(source)
         stats.analyze()
         stats.summary()
         dprint(filename)
         stats.saveStateToFile()
         return url
     else:
         dprint("%s not supported for static analysis")
         return None
Ejemplo n.º 2
0
class StaticAnalysisMode(XDotMode):
    """
    Major mode for static analysis.  Uses the WxDotWindow as the root window,
    interfacing with the static analysis through the Dot rendering.
    """
    keyword="StaticAnalysis"
    icon='icons/graphviz.png'

    default_classprefs = (
        StrParam('extensions', 'static_analysis', fullwidth=True),
        StrParam('layout', 'dot'),
        StrParam('rankdir', 'TB'),
        FloatParam('gprof_node_thresh', 0.0, help="Ignore gprof functions with total time below this threshold (percentage)"),
        FloatParam('gprof_edge_thresh', 0.0, help="Ignore gprof calls with total time below this threshold (percentage)"),
        )

    def __init__(self, parent, wrapper, buffer, frame):
        MajorMode.__init__(self, parent, wrapper, buffer, frame)
        WxDotWindow.__init__(self, parent, -1)
        self.gprof_file = None
        self.gprof = None
        self.tipitem = None
        self.register_select_callback(self.nodeSelectCallback)
        self.update()
        
    def update(self):
        bytes = self.buffer.stc.GetBinaryData()
        self.sa = FortranStaticAnalysis(pickledata=bytes)
        self.sa.summary()
        self.updateGraph()
    
    def updateGraph(self):
        fh = StringIO()
        self.sa.makeDot(fh=fh, rankdir=self.classprefs.rankdir)
        stdin = fh.getvalue()
        output = JobOutputSaver(self.regenerateFinished)
        cmd = "%s %s -Txdot -K%s" % (GraphvizMode.classprefs.interpreter_exe, GraphvizMode.classprefs.interpreter_args, self.classprefs.layout)
        ProcessManager().run(cmd, self.buffer.cwd(), output, stdin=stdin)
    
    def regenerateFinished(self, output):
        if output.exit_code == 0:
            self.set_xdotcode(output.getOutputText())
            self.zoom_to_fit()
            self.showGprof("/data3/mod6/historical/5.2.1-svn/build-gprof/Eldridge_tape5_Modtran5-original.gprof")
            
        else:
            Publisher().sendMessage('peppy.log.error', output.getErrorText())
    
    def nodeSelectCallback(self, item, event):
        dprint(item.item)
        if self.tipitem != item.item:
            self.tipitem = item.item
            name = self.tipitem.get_text()
            try:
                text = self.getGprofLabel(name)
            except KeyError:
                text = name
            self.setStatusText(text)

    def showGprof(self, filename):
        theme = TEMPERATURE_COLORMAP
        fh = open(filename, 'rb')
        parser = gprof2dot.GprofParser(fh)
        self.gprof = parser.parse()
        self.gprof.prune(self.classprefs.gprof_node_thresh/100.0, self.classprefs.gprof_edge_thresh/100.0)
        self.gprof.by_name = {}
        
        #self.override_pen_by_name(['mdtrn5', 'driver', 'fnames'])
        active = set()
        for function in self.gprof.functions.itervalues():
            if function.name.endswith("_"):
                function.name = function.name[:-1]
                self.gprof.by_name[function.name] = function
                if function.name == "MAIN_":
                    function.name = self.sa.name
                    function.display_time = self.gprof[gprof2dot.TIME]
                    function.events = {}
                if function.weight is not None:
                    weight = function.weight
                else:
                    weight = 0.0
                color = theme.node_bgcolor(weight)
                fontcolor = theme.node_fgcolor(weight)
                    
                #print function.name
                self.override_pen_by_name([function.name], color)
                active.add(function.name)
                
                try:
                    callee = self.sa.callables[function.name]
                    callee.gprof = function
                    #print function.name, callee
                except KeyError:
                    pass
        
        disabled = set(self.sa.getCallableNames()) - active
        self.override_pen_by_name(disabled, dst_edge=True)
    
    def getGprofLabel(self, function_name):
        function = self.gprof.by_name[function_name]
        labels = []
        if function.process is not None:
            labels.append(function.process)
        if function.module is not None:
            labels.append(function.module)
        labels.append(function.name)
        for title, event in ("Cumulative Time", gprof2dot.TOTAL_TIME_RATIO), ("Self Time", gprof2dot.TIME_RATIO):
            if event in function.events:
                label = event.format(function[event])
                labels.append("%s: %s" % (title, label))
        if hasattr(function, "display_time"):
            labels.append(u"Display time: %s" % (function.display_time,))
        elif function.called is not None:
            labels.append(u"Called %u\xd7" % (function.called,))
        return ", ".join(labels)
Ejemplo n.º 3
0
 def update(self):
     bytes = self.buffer.stc.GetBinaryData()
     self.sa = FortranStaticAnalysis(pickledata=bytes)
     self.sa.summary()
     self.updateGraph()
Ejemplo n.º 4
0
 def staticAnalysis(self, lang="fortran", regenerate=False):
     url = self.getSettingsRelativeURL("%s.static_analysis" % lang)
     dprint(url)
     filename = str(url.path)
     dprint(filename)
     if lang == "fortran":
         stats = FortranStaticAnalysis(serialized_filename=filename,
                                       regenerate=regenerate)
         if not regenerate and not stats.isEmpty():
             return url
         for source in self.walkProjectDir(["*.f", "*.f90"]):
             print source
             stats.scan(source)
         stats.analyze()
         stats.summary()
         dprint(filename)
         stats.saveStateToFile()
         return url
     else:
         dprint("%s not supported for static analysis")
         return None