Beispiel #1
0
    def GetHeapGraph(self):
        if self.GetGraphType() != GRAPH_HEAP:
            return
        fontSize = 7.5
        fontFace = 'arial.ttc'
        wnd = self.GetWnd()
        wnd.sr.graph.Flush()
        w, h = wnd.sr.graph.absoluteRight - wnd.sr.graph.absoluteLeft, wnd.sr.graph.absoluteBottom - wnd.sr.graph.absoluteTop
        width = w
        height = h
        c = chart.XYChart(width, height, bgColor=chart.Transparent)
        c.setColors(chart.whiteOnBlackPalette)
        c.setBackground(chart.Transparent)
        c.setTransparentColor(-1)
        c.setAntiAlias(1, 1)
        offsX = 60
        offsY = 17
        canvasWidth = width - 1 * offsX - 50
        canvasHeight = height - offsY * 2.5
        plotArea = c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight,
                                 1711276032, -1, -1, 5592405)
        import random
        c.addLegend(85, 18, 0, fontFace,
                    fontSize).setBackground(chart.Transparent)
        random.seed(1001)
        for k, lst in self.heaphistory.iteritems():
            name = 'monitor_setting_heap_%s' % k
            if not settings.user.ui.Get(name, 1):
                continue
            memData = []
            timeData = []
            for t, n in lst:
                memData.append(n / 1024 / 1024)
                year, month, wd, day, hour, minutes, sec, ms = util.GetTimeParts(
                    t)
                timeData.append(
                    chart.chartTime(year, month, day, hour, minutes, sec))

            lines = c.addLineLayer()
            l = (random.randint(0, 15), random.randint(0, 255),
                 random.randint(0, 255))
            l = '0x%X%X%Xee' % (l[0], l[1], l[2])
            lines.addDataSet(memData, int(l, 16), '#%s' % k).setLineWidth(1)
            lines.setXData(timeData)

        c.xAxis().setDateScale3('{value|hh:nn}')
        leftAxis = c.yAxis()
        leftAxis.setTitle('Heap Size (MB)')
        buf = c.makeChart2(chart.PNG)
        hostBitmap = trinity.Tr2HostBitmap(w, h, 1,
                                           trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        hostBitmap.LoadFromPngInMemory(buf)
        linegr = uicls.Sprite(parent=wnd.sr.graph, align=uiconst.TOALL)
        linegr.GetMenu = self.GetHeapGraphMenu
        linegr.texture.atlasTexture = uicore.uilib.CreateTexture(width, height)
        linegr.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
Beispiel #2
0
    def GetHeapGraph(self):
        if self.GetGraphType() != GRAPH_HEAP:
            return
        fontSize = 7.5
        fontFace = 'arial.ttc'
        wnd = self.GetWnd()
        wnd.sr.graph.Flush()
        w, h = wnd.sr.graph.absoluteRight - wnd.sr.graph.absoluteLeft, wnd.sr.graph.absoluteBottom - wnd.sr.graph.absoluteTop
        width = w
        height = h
        c = chart.XYChart(width, height, bgColor=chart.Transparent)
        c.setColors(chart.whiteOnBlackPalette)
        c.setBackground(chart.Transparent)
        c.setTransparentColor(-1)
        c.setAntiAlias(1, 1)
        offsX = 60
        offsY = 17
        canvasWidth = width - 1 * offsX - 50
        canvasHeight = height - offsY * 2.5
        plotArea = c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight, 1711276032, -1, -1, 5592405)
        import random
        c.addLegend(85, 18, 0, fontFace, fontSize).setBackground(chart.Transparent)
        r = random.Random()
        r.seed(1001)
        for k, lst in self.heaphistory.iteritems():
            name = 'monitor_setting_heap_%s' % k
            if not settings.user.ui.Get(name, 1):
                continue
            memData = []
            timeData = []
            for t, n in lst:
                memData.append(n / 1024 / 1024)
                year, month, wd, day, hour, minutes, sec, ms = util.GetTimeParts(t)
                timeData.append(chart.chartTime(year, month, day, hour, minutes, sec))

            lines = c.addLineLayer()
            l = (r.randint(0, 15), r.randint(0, 255), r.randint(0, 255))
            l = '0x%X%X%Xee' % (l[0], l[1], l[2])
            lines.addDataSet(memData, int(l, 16), '#%s' % k).setLineWidth(1)
            lines.setXData(timeData)

        c.xAxis().setDateScale3('{value|hh:nn}')
        leftAxis = c.yAxis()
        leftAxis.setTitle('Heap Size (MB)')
        buf = c.makeChart2(chart.PNG)
        hostBitmap = trinity.Tr2HostBitmap(w, h, 1, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        hostBitmap.LoadFromPngInMemory(buf)
        linegr = uiprimitives.Sprite(parent=wnd.sr.graph, align=uiconst.TOALL)
        linegr.GetMenu = self.GetHeapGraphMenu
        linegr.texture.atlasTexture = uicore.uilib.CreateTexture(width, height)
        linegr.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
Beispiel #3
0
    def GetGraph(self):
        isPerf = False
        if self.GetGraphType() == GRAPH_PERFORMANCE:
            isPerf = True
        fontSize = 7.5
        fontFace = 'arial.ttc'
        wnd = self.GetWnd()
        wnd.sr.graph.Flush()
        w, h = wnd.sr.graph.absoluteRight - wnd.sr.graph.absoluteLeft, wnd.sr.graph.absoluteBottom - wnd.sr.graph.absoluteTop
        minutes = settings.user.ui.Get('monitor_setting_memory_time', 60)
        trend = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memCounters = {}
        perfCounters = {}
        mega = 1.0 / 1024.0 / 1024.0
        timeData = []
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        ppsData = []
        fpsData = []
        threadCpuData = []
        procCpuData = []
        lastT = lastpf = 0
        t1 = 0
        if len(trend) > 1:
            t, cpu, mem, sched = trend[0]
            lastT = t
            lastpf = mem[-1]
            t1 = trend[0][0]
        benice = blue.pyos.BeNice
        for t, cpu, mem, sched in trend:
            benice()
            elap = t - t1
            t1 = t
            mem, pymem, workingset, pagefaults, bluemem = mem
            fps, nr_1, ny, ns, dur, nr_2 = sched
            fpsData.append(fps)
            memData.append(mem * mega)
            pymemData.append(pymem * mega)
            bluememData.append(bluemem * mega)
            othermem = (mem - bluemem) * mega
            if othermem < 0:
                othermem = 0
            othermemData.append(othermem)
            workingsetData.append(workingset * mega)
            thread_u, proc_u, kernel_u, process_kernel_u = cpu
            if elap:
                thread_cpupct = thread_u / float(elap) * 100.0
                proc_cpupct = proc_u / float(elap) * 100.0
            else:
                thread_cpupct = proc_cpupct = 0.0
            threadCpuData.append(thread_cpupct)
            procCpuData.append(proc_cpupct)
            dt = t - lastT
            lastT = t
            pf = pagefaults - lastpf
            lastpf = pagefaults
            pps = pf / (dt * 1e-07) if dt else 0
            ppsData.append(pps)
            year, month, wd, day, hour, minutes, sec, ms = util.GetTimeParts(t)
            timeData.append(
                chart.chartTime(year, month, day, hour, minutes, sec))

        if len(ppsData) > 1:
            ppsData[0] = ppsData[1]
        memCounters['blue_memory'] = (False, bluememData, 3377390, 1, False)
        memCounters['other_memory'] = (False, othermemData, 16776960, 1, False)
        memCounters['python_memory'] = (False, pymemData, 65280, 1, False)
        memCounters['total_memory'] = (False, memData, 16711680, 2, False)
        memCounters['working_set'] = (False, workingsetData, 65535, 1, False)
        memCounters['thread_cpu'] = (True, threadCpuData, 6749952, 1, True)
        memCounters['fps'] = (True, fpsData, 16711680, 1, False)
        width = w
        height = h
        c = chart.XYChart(width, height, bgColor=chart.Transparent)
        c.setColors(chart.whiteOnBlackPalette)
        c.setBackground(chart.Transparent)
        c.setTransparentColor(-1)
        c.setAntiAlias(1, 1)
        offsX = 60
        offsY = 17
        canvasWidth = width - 1 * offsX - 50
        canvasHeight = height - offsY * 2.5
        plotArea = c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight,
                                 1711276032, -1, -1, 5592405)
        c.addLegend(85, 18, 0, fontFace,
                    fontSize).setBackground(chart.Transparent)
        if len(timeData) > 1:
            c.xAxis().setDateScale3('{value|hh:nn}')
        lines = c.addLineLayer()
        lines2 = c.addLineLayer2()
        lines2.setUseYAxis2()
        leftAxis = c.yAxis()
        rightAxis = c.yAxis2()
        if isPerf:
            leftAxis.setTitle('Frames per second')
            rightAxis.setTitle('CPU (%)')
        else:
            leftAxis.setTitle('Memory (MB)')
        for i, k in enumerate(memCounters.keys()):
            if settings.user.ui.Get('monitor_setting_%s' % k, 1):
                title = k.replace('_', ' ').capitalize()
                if isPerf == memCounters[k][0]:
                    data = memCounters[k][1]
                    col = memCounters[k][2]
                    lineWidth = memCounters[k][3]
                    if not memCounters[k][4]:
                        l = lines
                    else:
                        l = lines2
                    l.addDataSet(data, col, title).setLineWidth(lineWidth)

        lines.setXData(timeData)
        lines2.setXData(timeData)
        if trend:
            pf = trend[-1][2][-1]
            label = 'Working set: %iMB, Virtual mem: %iMB, Page faults: %s' % (
                workingsetData[-1], memData[-1], util.FmtAmt(pf))
            c.addText(offsX, 2, label)
        buf = c.makeChart2(chart.PNG)
        hostBitmap = trinity.Tr2HostBitmap(w, h, 1,
                                           trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        hostBitmap.LoadFromPngInMemory(buf)
        linegr = uicls.Sprite(parent=wnd.sr.graph, align=uiconst.TOALL)
        linegr.GetMenu = self.GetGraphMenu
        linegr.texture.atlasTexture = uicore.uilib.CreateTexture(width, height)
        linegr.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
Beispiel #4
0
    def GetGraph(self):
        isPerf = False
        if self.GetGraphType() == GRAPH_PERFORMANCE:
            isPerf = True
        fontSize = 7.5
        fontFace = 'arial.ttc'
        wnd = self.GetWnd()
        wnd.sr.graph.Flush()
        w, h = wnd.sr.graph.absoluteRight - wnd.sr.graph.absoluteLeft, wnd.sr.graph.absoluteBottom - wnd.sr.graph.absoluteTop
        minutes = settings.user.ui.Get('monitor_setting_memory_time', 60)
        trend = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memCounters = {}
        perfCounters = {}
        mega = 1.0 / 1024.0 / 1024.0
        timeData = []
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        ppsData = []
        fpsData = []
        threadCpuData = []
        procCpuData = []
        lastT = lastpf = 0
        t1 = 0
        if len(trend) > 1:
            t, cpu, mem, sched = trend[0]
            lastT = t
            lastpf = mem[-1]
            t1 = trend[0][0]
        benice = blue.pyos.BeNice
        for t, cpu, mem, sched in trend:
            benice()
            elap = t - t1
            t1 = t
            mem, pymem, workingset, pagefaults, bluemem = mem
            fps, nr_1, ny, ns, dur, nr_2 = sched
            fpsData.append(fps)
            memData.append(mem * mega)
            pymemData.append(pymem * mega)
            bluememData.append(bluemem * mega)
            othermem = (mem - bluemem) * mega
            if othermem < 0:
                othermem = 0
            othermemData.append(othermem)
            workingsetData.append(workingset * mega)
            thread_u, proc_u, kernel_u, process_kernel_u = cpu
            if elap:
                thread_cpupct = thread_u / float(elap) * 100.0
                proc_cpupct = proc_u / float(elap) * 100.0
            else:
                thread_cpupct = proc_cpupct = 0.0
            threadCpuData.append(thread_cpupct)
            procCpuData.append(proc_cpupct)
            dt = t - lastT
            lastT = t
            pf = pagefaults - lastpf
            lastpf = pagefaults
            pps = pf / (dt * 1e-07) if dt else 0
            ppsData.append(pps)
            year, month, wd, day, hour, minutes, sec, ms = util.GetTimeParts(t)
            timeData.append(chart.chartTime(year, month, day, hour, minutes, sec))

        if len(ppsData) > 1:
            ppsData[0] = ppsData[1]
        memCounters['blue_memory'] = (False,
         bluememData,
         3377390,
         1,
         False)
        memCounters['other_memory'] = (False,
         othermemData,
         16776960,
         1,
         False)
        memCounters['python_memory'] = (False,
         pymemData,
         65280,
         1,
         False)
        memCounters['total_memory'] = (False,
         memData,
         16711680,
         2,
         False)
        memCounters['working_set'] = (False,
         workingsetData,
         65535,
         1,
         False)
        memCounters['thread_cpu'] = (True,
         threadCpuData,
         6749952,
         1,
         True)
        memCounters['fps'] = (True,
         fpsData,
         16711680,
         1,
         False)
        width = w
        height = h
        c = chart.XYChart(width, height, bgColor=chart.Transparent)
        c.setColors(chart.whiteOnBlackPalette)
        c.setBackground(chart.Transparent)
        c.setTransparentColor(-1)
        c.setAntiAlias(1, 1)
        offsX = 60
        offsY = 17
        canvasWidth = width - 1 * offsX - 50
        canvasHeight = height - offsY * 2.5
        plotArea = c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight, 1711276032, -1, -1, 5592405)
        c.addLegend(85, 18, 0, fontFace, fontSize).setBackground(chart.Transparent)
        if len(timeData) > 1:
            c.xAxis().setDateScale3('{value|hh:nn}')
        lines = c.addLineLayer()
        lines2 = c.addLineLayer2()
        lines2.setUseYAxis2()
        leftAxis = c.yAxis()
        rightAxis = c.yAxis2()
        if isPerf:
            leftAxis.setTitle('Frames per second')
            rightAxis.setTitle('CPU (%)')
        else:
            leftAxis.setTitle('Memory (MB)')
        for i, k in enumerate(memCounters.keys()):
            if settings.user.ui.Get('monitor_setting_%s' % k, 1):
                title = k.replace('_', ' ').capitalize()
                if isPerf == memCounters[k][0]:
                    data = memCounters[k][1]
                    col = memCounters[k][2]
                    lineWidth = memCounters[k][3]
                    if not memCounters[k][4]:
                        l = lines
                    else:
                        l = lines2
                    l.addDataSet(data, col, title).setLineWidth(lineWidth)

        lines.setXData(timeData)
        lines2.setXData(timeData)
        if trend:
            pf = trend[-1][2][-1]
            label = 'Working set: %iMB, Virtual mem: %iMB, Page faults: %s' % (workingsetData[-1], memData[-1], util.FmtAmt(pf))
            c.addText(offsX, 2, label)
        buf = c.makeChart2(chart.PNG)
        hostBitmap = trinity.Tr2HostBitmap(w, h, 1, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        hostBitmap.LoadFromPngInMemory(buf)
        linegr = uicls.Sprite(parent=wnd.sr.graph, align=uiconst.TOALL)
        linegr.GetMenu = self.GetGraphMenu
        linegr.texture.atlasTexture = uicore.uilib.CreateTexture(width, height)
        linegr.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
Beispiel #5
0
def dt(s):
    return pychartdir.chartTime(s[0:4], s[5:7], s[8:10])