/usr/share/arm/gui/graphing/graphPanel.py is in tor-arm 1.4.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | """
Base class for implementing graphing functionality.
"""
import random
import sys
from collections import deque
import gobject
import gtk
from util import gtkTools, torTools, uiTools
from TorCtl import TorCtl
from cagraph.axis.xaxis import CaGraphXAxis
from cagraph.axis.yaxis import CaGraphYAxis
from cagraph.ca_graph_grid import CaGraphGrid
from cagraph.ca_graph import CaGraph
from cagraph.series.area import CaGraphSeriesArea
GRAPH_INTERVAL = 30
class GraphPanel(TorCtl.PostEventListener):
def __init__(self, builder):
TorCtl.PostEventListener.__init__(self)
self.builder = builder
self.graphs = {
'primary' : None,
'secondary' : None }
self.data = {
'primary' : deque([0.0] * GRAPH_INTERVAL),
'secondary' : deque([0.0] * GRAPH_INTERVAL)}
self.total = {'primary': 0.0, 'secondary' : 0.0}
self.ticks = {'primary': 0, 'secondary' : 0}
def pack_widgets(self):
self._pack_graph_widget('primary')
self._pack_graph_widget('secondary')
gobject.timeout_add(1000, self.draw_graph, 'primary')
gobject.timeout_add(1000, self.draw_graph, 'secondary')
gobject.timeout_add(1000, self.update_labels, 'primary')
gobject.timeout_add(1000, self.update_labels, 'secondary')
def get_graph_data(self, name):
packedData = []
for (index, value) in enumerate(self.data[name]):
packedData.append((index, value))
return packedData
def is_graph_data_zero(self, name):
data = self.data[name]
return len(data) == map(int, data).count(0)
def draw_graph(self, name):
graph = self.graphs[name]
data = self.get_graph_data(name)
graph.seriess[0].data = data
if not self.is_graph_data_zero(name):
for (index, axis) in enumerate(graph.axiss):
if axis.type != 'xaxis':
graph.auto_set_yrange(index)
graph.queue_draw()
return True
def update_labels(self, name):
avg = 0
try:
avg = self.total[name] / float(self.ticks[name])
except ZeroDivisionError:
pass
msg = "avg: %s/s, total: %s" % (uiTools.getSizeLabel(avg, 2, isBytes=False),
uiTools.getSizeLabel(self.total[name], 2))
label = self.builder.get_object('label_graph_%s_bottom' % name)
label.set_text(msg)
return True
def update_header(self, name, msg):
label = self.builder.get_object('label_graph_%s_top' % name)
label.set_text(msg)
def _pack_graph_widget(self, name):
graph = CaGraph()
graph.set_size_request(200, 200)
placeholder = self.builder.get_object('placeholder_graph_%s' % name)
placeholder.pack_start(graph)
xAxis = CaGraphXAxis(graph)
yAxis = CaGraphYAxis(graph)
xAxis.min = 0
xAxis.max = GRAPH_INTERVAL - 1
xAxis.axis_style.draw_labels = False
yAxis.axis_style.label_color = (0, 0, 0)
graph.axiss.append(xAxis)
graph.axiss.append(yAxis)
series = CaGraphSeriesArea(graph, 0, 1)
theme = gtkTools.Theme()
primaryColor = theme.colors['normal']
secondaryColor = theme.colors['insensitive']
colors = { 'primary' : (primaryColor.red_float, primaryColor.green_float, primaryColor.blue_float, 0.5),
'secondary' : (secondaryColor.red_float, secondaryColor.green_float, secondaryColor.blue_float, 0.5) }
series.style.point_radius = 0.0
series.style.line_color = colors[name]
series.style.fill_color = colors[name]
graph.seriess.append(series)
graph.grid = CaGraphGrid(graph, 0, 1)
self.graphs[name] = graph
return graph
def _process_event(self, primary, secondary):
values = {'primary' : primary, 'secondary' : secondary}
for name in ('primary', 'secondary'):
# right shift and store kbytes in left-most location
self.data[name].rotate(1)
self.data[name][0] = values[name] / 1024
self.total[name] = self.total[name] + values[name]
if values[name] > 0:
self.ticks[name] = self.ticks[name] + 1
|