NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

GraphManager.py (6193B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\trinity\GraphManager.py
      2 from __future__ import print_function
      3 import blue
      4 from . import _trinity as trinity
      5 from .renderJob import renderJobs, CreateRenderJob
      6 
      7 class GraphManager:
      8 
      9     def __init__(self):
     10         self.isEnabled = False
     11         self.renderJobContainer = None
     12         self.renderJob = None
     13         self.graphGroups = {}
     14         self.graphs = {}
     15         self.bounds = (0, 0, 400, 400)
     16         renderer = trinity.TriStepRenderLineGraph()
     17         renderer.name = 'time'
     18         renderer.legendScale = 1000.0
     19         renderer.maxLegend = 300.0
     20         grp = {}
     21         grp['viewport'] = trinity.TriViewport()
     22         grp['renderer'] = renderer
     23         grp['graphs'] = []
     24         self.graphGroups['time'] = grp
     25         renderer = trinity.TriStepRenderLineGraph()
     26         renderer.name = 'counterLow'
     27         grp = {}
     28         grp['viewport'] = trinity.TriViewport()
     29         grp['renderer'] = renderer
     30         grp['graphs'] = []
     31         self.graphGroups['counterLow'] = grp
     32         renderer = trinity.TriStepRenderLineGraph()
     33         renderer.name = 'counterHigh'
     34         grp = {}
     35         grp['viewport'] = trinity.TriViewport()
     36         grp['renderer'] = renderer
     37         grp['graphs'] = []
     38         self.graphGroups['counterHigh'] = grp
     39         renderer = trinity.TriStepRenderLineGraph()
     40         renderer.name = 'memory'
     41         renderer.legendScale = 1e-06
     42         grp = {}
     43         grp['viewport'] = trinity.TriViewport()
     44         grp['renderer'] = renderer
     45         grp['graphs'] = []
     46         self.graphGroups['memory'] = grp
     47         self.AdjustViewports(self.bounds)
     48         self.colors = {'counterHigh': [],
     49          'counterLow': [],
     50          'time': [],
     51          'memory': []}
     52         availColors = [(0.8, 0.8, 0.8, 1.0),
     53          (0.4, 0.8, 0.8, 1.0),
     54          (0.8, 0.4, 0.8, 1.0),
     55          (0.4, 0.4, 0.8, 1.0),
     56          (0.8, 0.8, 0.4, 1.0),
     57          (0.4, 0.8, 0.4, 1.0),
     58          (0.8, 0.4, 0.4, 1.0),
     59          (0.8, 0.0, 0.0, 1.0),
     60          (0.0, 0.8, 0.8, 1.0),
     61          (0.8, 0.8, 0.0, 1.0)]
     62         for each in availColors:
     63             self.colors['counterHigh'].append(each)
     64             self.colors['counterLow'].append(each)
     65             self.colors['time'].append(each)
     66             self.colors['memory'].append(each)
     67 
     68     def AdjustViewports(self, bounds):
     69         self.bounds = bounds
     70         width = bounds[2]
     71         height = bounds[3]
     72         counts = {}
     73         for key, val in self.graphGroups.iteritems():
     74             counts[key] = len(val['graphs'])
     75 
     76         grpCount = 0
     77         for each in counts.values():
     78             if each > 0:
     79                 grpCount += 1
     80 
     81         margin = 4
     82         grpHeight = 0
     83         if grpCount > 0:
     84             grpHeight = (height - (grpCount - 1) * margin) / grpCount
     85         y = margin + self.bounds[1]
     86         for key, val in self.graphGroups.iteritems():
     87             vp = self.graphGroups[key]['viewport']
     88             if counts[key] > 0:
     89                 vp.x = self.bounds[0]
     90                 vp.y = y
     91                 vp.width = width - margin * 2
     92                 vp.height = grpHeight
     93                 y += grpHeight + margin
     94             else:
     95                 vp.x = 1
     96                 vp.y = 1
     97                 vp.width = 10
     98                 vp.height = 10
     99 
    100     def SetEnabled(self, enable):
    101         if self.isEnabled == enable:
    102             return
    103         if enable:
    104             self.renderJob = self.AssembleRenderJob()
    105             if self.renderJobContainer:
    106                 self.renderJobContainer.steps.append(self.renderJob)
    107             else:
    108                 renderJobs.recurring.append(self.renderJob)
    109         else:
    110             try:
    111                 if self.renderJobContainer:
    112                     self.renderJobContainer.steps.remove(self.renderJob)
    113                 else:
    114                     renderJobs.recurring.remove(self.renderJob)
    115             except blue.error:
    116                 pass
    117 
    118             self.renderJob = None
    119         self.isEnabled = enable
    120 
    121     def IsEnabled(self):
    122         return self.isEnabled
    123 
    124     def AssembleRenderJob(self):
    125         renderJob = CreateRenderJob('Graphs')
    126         for grp in self.graphGroups.values():
    127             renderJob.SetViewport(grp['viewport'])
    128             renderJob.steps.append(grp['renderer'])
    129 
    130         return renderJob
    131 
    132     def AddGraph(self, statisticName):
    133         if statisticName in self.graphs:
    134             print(statisticName, 'is already being graphed')
    135             return self.graphs[statisticName][1]
    136         lg = blue.statistics.GetAccumulator(statisticName)
    137         if lg is not None:
    138             print(statisticName, 'already has an accumulator')
    139             return lg
    140         statsDesc = blue.statistics.GetDescriptions()
    141         grpName = statsDesc[statisticName][1]
    142         if len(self.colors[grpName]) == 0:
    143             raise Exception('Too many graphs per category')
    144         grp = self.graphGroups[grpName]
    145         grp['graphs'].append(statisticName)
    146         lg = trinity.Tr2LineGraph()
    147         lg.name = statisticName
    148         lg.color = self.colors[grpName].pop()
    149         blue.statistics.SetAccumulator(statisticName, lg)
    150         renderer = grp['renderer']
    151         renderer.lineGraphs.append(lg)
    152         self.graphs[statisticName] = [grp, lg]
    153         self.AdjustViewports(self.bounds)
    154         return lg
    155 
    156     def RemoveGraph(self, statisticName):
    157         blue.statistics.SetAccumulator(statisticName, None)
    158         entry = self.graphs[statisticName]
    159         grp = entry[0]
    160         lg = entry[1]
    161         grp['renderer'].lineGraphs.fremove(lg)
    162         del self.graphs[statisticName]
    163         grp['graphs'].remove(statisticName)
    164         statsDesc = blue.statistics.GetDescriptions()
    165         grpName = statsDesc[statisticName][1]
    166         self.colors[grpName].append(lg.color)
    167         self.AdjustViewports(self.bounds)
    168 
    169     def HasGraph(self, statisticName):
    170         return statisticName in self.graphs
    171 
    172     def Clear(self):
    173         while len(self.graphs) > 0:
    174             self.RemoveGraph(self.graphs.keys()[0])
    175 
    176     def AddMarker(self, statisticName, name):
    177         if statisticName not in self.graphs:
    178             return
    179         self.graphs[statisticName][1].AddMarker(name)