2007-11-22 08:47:06 +00:00
|
|
|
# -*- coding: utf-8; mode: python; -*-
|
|
|
|
#
|
|
|
|
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""GStreamer Debug Viewer timeline widget plugin."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
from GstDebugViewer import Common, Data, GUI
|
2007-11-14 08:30:19 +00:00
|
|
|
from GstDebugViewer.Plugins import *
|
|
|
|
|
|
|
|
import cairo
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
def iter_model_reversed (model):
|
|
|
|
|
|
|
|
count = model.iter_n_children (None)
|
|
|
|
for i in xrange (count - 1, 0, -1):
|
|
|
|
yield model[i]
|
|
|
|
|
|
|
|
class LineFrequencySentinel (object):
|
|
|
|
|
|
|
|
def __init__ (self, model):
|
|
|
|
|
|
|
|
self.model = model
|
2007-11-21 15:40:31 +00:00
|
|
|
self.clear ()
|
|
|
|
|
|
|
|
def clear (self):
|
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
self.data = None
|
2007-11-21 15:40:31 +00:00
|
|
|
self.n_partitions = None
|
2007-11-16 15:25:08 +00:00
|
|
|
self.partitions = None
|
|
|
|
self.step = None
|
2007-11-21 15:40:31 +00:00
|
|
|
self.ts_range = (None, None,)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
def _search_ts (self, target_ts, first_index, last_index):
|
|
|
|
|
2007-11-20 11:56:15 +00:00
|
|
|
model_get = self.model.get_value
|
2007-11-14 08:30:19 +00:00
|
|
|
model_iter_nth_child = self.model.iter_nth_child
|
|
|
|
col_id = self.model.COL_TIME
|
|
|
|
|
|
|
|
while True:
|
|
|
|
middle = (last_index - first_index) // 2 + first_index
|
|
|
|
if middle == first_index:
|
|
|
|
return last_index
|
2007-11-20 11:56:15 +00:00
|
|
|
ts = model_get (model_iter_nth_child (None, middle), col_id)
|
2007-11-14 08:30:19 +00:00
|
|
|
if ts < target_ts:
|
|
|
|
first_index = middle + 1
|
|
|
|
elif ts > target_ts:
|
|
|
|
last_index = middle - 1
|
|
|
|
else:
|
|
|
|
return middle
|
|
|
|
|
|
|
|
def run_for (self, n):
|
|
|
|
|
|
|
|
if n == 0:
|
|
|
|
raise ValueError ("illegal value for n")
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.n_partitions = n
|
|
|
|
|
|
|
|
def process (self):
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
model = self.model
|
|
|
|
result = []
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions = []
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-21 11:42:32 +00:00
|
|
|
first_ts = None
|
|
|
|
for row in self.model:
|
|
|
|
first_ts = row[model.COL_TIME]
|
|
|
|
if first_ts is not None:
|
|
|
|
break
|
|
|
|
|
|
|
|
if first_ts is None:
|
|
|
|
return
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
last_ts = None
|
|
|
|
for row in iter_model_reversed (self.model):
|
|
|
|
last_ts = row[model.COL_TIME]
|
2007-11-21 11:42:32 +00:00
|
|
|
# FIXME: We ignore 0 here (unparsable lines!), this should be
|
|
|
|
# handled differently!
|
2007-11-14 08:30:19 +00:00
|
|
|
if last_ts:
|
|
|
|
last_index = row.path[0]
|
|
|
|
break
|
|
|
|
|
|
|
|
if last_ts is None:
|
2007-11-16 15:25:08 +00:00
|
|
|
return
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
step = int (float (last_ts - first_ts) / float (self.n_partitions))
|
|
|
|
|
|
|
|
YIELD_LIMIT = 100
|
|
|
|
limit = YIELD_LIMIT
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
first_index = 0
|
2007-11-21 11:42:32 +00:00
|
|
|
target_ts = first_ts + step
|
2007-11-14 08:30:19 +00:00
|
|
|
old_found = 0
|
|
|
|
while target_ts < last_ts:
|
2007-11-21 15:40:31 +00:00
|
|
|
limit -= 1
|
|
|
|
if limit == 0:
|
|
|
|
limit = YIELD_LIMIT
|
|
|
|
yield True
|
2007-11-14 08:30:19 +00:00
|
|
|
found = self._search_ts (target_ts, first_index, last_index)
|
|
|
|
result.append (found - old_found)
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions.append (found)
|
2007-11-14 08:30:19 +00:00
|
|
|
old_found = found
|
|
|
|
first_index = found
|
|
|
|
target_ts += step
|
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
self.step = step
|
|
|
|
self.data = result
|
|
|
|
self.partitions = partitions
|
2007-11-21 11:42:32 +00:00
|
|
|
self.ts_range = (first_ts, last_ts,)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-16 13:06:59 +00:00
|
|
|
class LevelDistributionSentinel (object):
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
def __init__ (self, freq_sentinel, model):
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.freq_sentinel = freq_sentinel
|
2007-11-16 13:06:59 +00:00
|
|
|
self.model = model
|
2007-11-16 15:25:08 +00:00
|
|
|
self.data = []
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
def clear (self):
|
|
|
|
|
|
|
|
del self.data[:]
|
|
|
|
|
|
|
|
def process (self):
|
|
|
|
|
|
|
|
YIELD_LIMIT = 10000
|
|
|
|
y = YIELD_LIMIT
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-20 11:56:15 +00:00
|
|
|
model_get = self.model.get_value
|
2007-11-16 13:06:59 +00:00
|
|
|
model_next = self.model.iter_next
|
|
|
|
id_time = self.model.COL_TIME
|
|
|
|
id_level = self.model.COL_LEVEL
|
2007-11-22 07:31:37 +00:00
|
|
|
del self.data[:]
|
|
|
|
data = self.data
|
2007-11-16 13:06:59 +00:00
|
|
|
i = 0
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions_i = 0
|
2007-11-21 15:40:31 +00:00
|
|
|
partitions = self.freq_sentinel.partitions
|
2007-11-16 13:06:59 +00:00
|
|
|
counts = [0] * 6
|
|
|
|
tree_iter = self.model.get_iter_first ()
|
|
|
|
while tree_iter:
|
2007-11-21 15:40:31 +00:00
|
|
|
y -= 1
|
|
|
|
if y == 0:
|
|
|
|
y = YIELD_LIMIT
|
|
|
|
yield True
|
2007-11-20 11:56:15 +00:00
|
|
|
level = model_get (tree_iter, id_level)
|
2007-11-16 15:25:08 +00:00
|
|
|
if i > partitions[partitions_i]:
|
2007-11-22 07:31:37 +00:00
|
|
|
data.append (tuple (counts))
|
2007-11-16 13:06:59 +00:00
|
|
|
counts = [0] * 6
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions_i += 1
|
|
|
|
if partitions_i == len (partitions):
|
|
|
|
# FIXME?
|
|
|
|
break
|
|
|
|
i += 1
|
2007-11-16 13:06:59 +00:00
|
|
|
counts[level] += 1
|
|
|
|
tree_iter = model_next (tree_iter)
|
|
|
|
|
|
|
|
# FIXME: We lose the last partition here!
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
yield False
|
|
|
|
|
|
|
|
class UpdateProcess (object):
|
|
|
|
|
|
|
|
def __init__ (self, freq_sentinel, dist_sentinel):
|
|
|
|
|
|
|
|
self.freq_sentinel = freq_sentinel
|
|
|
|
self.dist_sentinel = dist_sentinel
|
|
|
|
self.is_running = False
|
|
|
|
self.dispatcher = Common.Data.GSourceDispatcher ()
|
|
|
|
|
|
|
|
def __process (self):
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if self.freq_sentinel is None or self.dist_sentinel is None:
|
|
|
|
return
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.is_running = True
|
|
|
|
|
|
|
|
for x in self.freq_sentinel.process ():
|
|
|
|
yield True
|
|
|
|
|
|
|
|
self.handle_sentinel_finished (self.freq_sentinel)
|
|
|
|
|
|
|
|
for x in self.dist_sentinel.process ():
|
|
|
|
yield True
|
2007-11-22 07:31:37 +00:00
|
|
|
self.handle_sentinel_progress (self.dist_sentinel)
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
self.is_running = False
|
|
|
|
|
|
|
|
self.handle_sentinel_finished (self.dist_sentinel)
|
|
|
|
self.handle_process_finished ()
|
|
|
|
|
|
|
|
yield False
|
|
|
|
|
|
|
|
def run (self):
|
|
|
|
|
|
|
|
if self.is_running:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.dispatcher (self.__process ())
|
|
|
|
|
|
|
|
def abort (self):
|
|
|
|
|
|
|
|
if not self.is_running:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.dispatcher.cancel ()
|
|
|
|
self.is_running = False
|
|
|
|
|
2007-11-22 07:31:37 +00:00
|
|
|
def handle_sentinel_progress (self, sentinel):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
def handle_sentinel_finished (self, sentinel):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
def handle_process_finished (self):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
2007-11-23 09:46:43 +00:00
|
|
|
class VerticalTimelineWidget (gtk.DrawingArea):
|
|
|
|
|
|
|
|
__gtype_name__ = "GstDebugViewerVerticalTimelineWidget"
|
|
|
|
|
|
|
|
def __init__ (self):
|
|
|
|
|
|
|
|
gtk.DrawingArea.__init__ (self)
|
|
|
|
|
|
|
|
self.logger = logging.getLogger ("ui.vtimeline")
|
|
|
|
|
|
|
|
self.params = None
|
|
|
|
|
|
|
|
self.connect ("expose-event", self.__handle_expose_event)
|
|
|
|
self.connect ("size-request", self.__handle_size_request)
|
|
|
|
|
|
|
|
def __handle_expose_event (self, self_, event):
|
|
|
|
|
|
|
|
self.__draw (self.window)
|
|
|
|
|
|
|
|
def __draw (self, drawable):
|
|
|
|
|
|
|
|
ctx = drawable.cairo_create ()
|
|
|
|
x, y, w, h = self.get_allocation ()
|
|
|
|
|
|
|
|
# White background rectangle.
|
|
|
|
ctx.set_line_width (0.)
|
|
|
|
ctx.rectangle (0, 0, w, h)
|
|
|
|
ctx.set_source_rgb (1., 1., 1.)
|
|
|
|
ctx.fill ()
|
|
|
|
ctx.new_path ()
|
|
|
|
|
|
|
|
if self.params is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
first_y, cell_height, ts_list = self.params
|
|
|
|
first_ts, last_ts = ts_list[0], ts_list[-1]
|
|
|
|
ts_range = last_ts - first_ts
|
|
|
|
|
|
|
|
if ts_range == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
ctx.set_line_width (1.)
|
|
|
|
ctx.set_source_rgb (0., 0., 0.)
|
|
|
|
|
|
|
|
first_y += cell_height // 2 - .5
|
|
|
|
for i, ts in enumerate (ts_list):
|
|
|
|
ts_fraction = float (ts - first_ts) / ts_range
|
|
|
|
ts_offset = ts_fraction * h
|
|
|
|
row_offset = first_y + i * cell_height
|
|
|
|
ctx.move_to (-.5, ts_offset)
|
|
|
|
ctx.line_to (4.5, ts_offset)
|
|
|
|
ctx.line_to (w - 4.5, row_offset)
|
|
|
|
ctx.line_to (w + .5, row_offset)
|
|
|
|
ctx.stroke ()
|
|
|
|
|
|
|
|
def __handle_size_request (self, self_, req):
|
|
|
|
|
|
|
|
req.width = 64 # FIXME
|
|
|
|
|
2007-11-23 13:04:14 +00:00
|
|
|
def clear (self):
|
|
|
|
|
|
|
|
self.params = None
|
|
|
|
self.queue_draw ()
|
|
|
|
|
2007-11-23 09:46:43 +00:00
|
|
|
def update (self, first_y, cell_height, ts_list):
|
|
|
|
|
|
|
|
# FIXME: Ideally we should be informed of the vertical position
|
|
|
|
# difference of the view (which is 0) with the current UI layout.
|
|
|
|
|
|
|
|
self.params = (first_y, cell_height, ts_list,)
|
|
|
|
self.queue_draw ()
|
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
class TimelineWidget (gtk.DrawingArea):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
__gtype_name__ = "GstDebugViewerTimelineWidget"
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
def __init__ (self):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
gtk.DrawingArea.__init__ (self)
|
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
self.logger = logging.getLogger ("ui.timeline")
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
self.process = UpdateProcess (None, None)
|
2007-11-14 08:30:19 +00:00
|
|
|
self.connect ("expose-event", self.__handle_expose_event)
|
|
|
|
self.connect ("configure-event", self.__handle_configure_event)
|
|
|
|
self.connect ("size-request", self.__handle_size_request)
|
2007-11-22 07:31:37 +00:00
|
|
|
self.process.handle_sentinel_progress = self.handle_sentinel_progress
|
2007-11-21 15:40:31 +00:00
|
|
|
self.process.handle_sentinel_finished = self.handle_sentinel_finished
|
|
|
|
self.process.handle_process_finished = self.handle_process_finished
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
self.model = None
|
2007-11-21 15:40:31 +00:00
|
|
|
self.__offscreen = None
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 07:31:37 +00:00
|
|
|
def handle_sentinel_progress (self, sentinel):
|
|
|
|
|
|
|
|
self.__redraw ()
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
def handle_sentinel_finished (self, sentinel):
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if sentinel == self.process.freq_sentinel:
|
2007-11-21 15:40:31 +00:00
|
|
|
self.__redraw ()
|
|
|
|
|
|
|
|
def handle_process_finished (self):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
self.__redraw ()
|
|
|
|
|
|
|
|
def __redraw (self):
|
|
|
|
|
|
|
|
if not self.props.visible:
|
|
|
|
return
|
|
|
|
|
|
|
|
x, y, w, h = self.get_allocation ()
|
2007-11-21 15:40:31 +00:00
|
|
|
self.__offscreen = gtk.gdk.Pixmap (self.window, w, h, -1)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.__draw (self.__offscreen)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
self.__update ()
|
|
|
|
|
|
|
|
def __update (self):
|
|
|
|
|
|
|
|
if not self.props.visible:
|
|
|
|
return
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
if self.__offscreen is None:
|
|
|
|
self.__redraw ()
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
gc = gtk.gdk.GC (self.window)
|
2007-11-21 15:40:31 +00:00
|
|
|
self.window.draw_drawable (gc, self.__offscreen, 0, 0, 0, 0, -1, -1)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
def update (self, model):
|
|
|
|
|
|
|
|
self.model = model
|
2007-11-22 08:29:23 +00:00
|
|
|
|
|
|
|
width = self.get_allocation ()[2]
|
|
|
|
|
|
|
|
self.process.abort ()
|
2007-11-22 14:06:55 +00:00
|
|
|
if model:
|
|
|
|
self.process.freq_sentinel = LineFrequencySentinel (model)
|
|
|
|
self.process.dist_sentinel = LevelDistributionSentinel (self.process.freq_sentinel, model)
|
|
|
|
self.process.freq_sentinel.run_for (width)
|
|
|
|
self.process.run ()
|
|
|
|
|
|
|
|
def clear (self):
|
|
|
|
|
|
|
|
self.process.abort ()
|
|
|
|
self.process.freq_sentinel = None
|
|
|
|
self.process.dist_sentinel = None
|
|
|
|
self.__redraw ()
|
2007-11-22 08:29:23 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
def update_position (self, start_ts, end_ts):
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.process.freq_sentinel:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not self.process.freq_sentinel.data:
|
2007-11-21 15:40:31 +00:00
|
|
|
return
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
self.__update ()
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
first_ts, last_ts = self.process.freq_sentinel.ts_range
|
|
|
|
step = self.process.freq_sentinel.step
|
2007-11-21 11:42:32 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
position1 = int (float (start_ts - first_ts) / step)
|
|
|
|
position2 = int (float (end_ts - first_ts) / step)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
ctx = self.window.cairo_create ()
|
|
|
|
x, y, w, h = self.get_allocation ()
|
|
|
|
|
|
|
|
line_width = position2 - position1
|
|
|
|
if line_width <= 1:
|
2007-11-14 08:44:08 +00:00
|
|
|
ctx.set_source_rgb (1., 0., 0.)
|
2007-11-14 08:30:19 +00:00
|
|
|
ctx.set_line_width (1.)
|
|
|
|
ctx.move_to (position1 + .5, 0)
|
|
|
|
ctx.line_to (position1 + .5, h)
|
|
|
|
ctx.stroke ()
|
|
|
|
else:
|
2007-11-14 08:44:08 +00:00
|
|
|
ctx.set_source_rgba (1., 0., 0., .5)
|
2007-11-14 08:30:19 +00:00
|
|
|
ctx.rectangle (position1, 0, line_width, h)
|
|
|
|
ctx.fill ()
|
|
|
|
|
2007-11-14 18:35:18 +00:00
|
|
|
def find_indicative_time_step (self):
|
|
|
|
|
|
|
|
MINIMUM_PIXEL_STEP = 32
|
2007-11-22 14:06:55 +00:00
|
|
|
time_per_pixel = self.process.freq_sentinel.step
|
|
|
|
return 32 # FIXME use self.freq_sentinel.step and len (self.process.freq_sentinel.data)
|
2007-11-14 18:35:18 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
def __draw (self, drawable):
|
|
|
|
|
|
|
|
ctx = drawable.cairo_create ()
|
|
|
|
x, y, w, h = self.get_allocation ()
|
2007-11-22 08:19:36 +00:00
|
|
|
|
|
|
|
# White background rectangle.
|
2007-11-14 08:30:19 +00:00
|
|
|
ctx.set_line_width (0.)
|
|
|
|
ctx.rectangle (0, 0, w, h)
|
|
|
|
ctx.set_source_rgb (1., 1., 1.)
|
|
|
|
ctx.fill ()
|
|
|
|
ctx.new_path ()
|
|
|
|
|
2007-11-22 08:19:36 +00:00
|
|
|
# Horizontal reference lines.
|
2007-11-14 13:49:03 +00:00
|
|
|
ctx.set_line_width (1.)
|
2007-11-14 18:35:18 +00:00
|
|
|
ctx.set_source_rgb (.95, .95, .95)
|
2007-11-14 13:49:03 +00:00
|
|
|
for i in range (h // 16):
|
|
|
|
y = i * 16 - .5
|
|
|
|
ctx.move_to (0, y)
|
|
|
|
ctx.line_to (w, y)
|
|
|
|
ctx.stroke ()
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if self.process.freq_sentinel is None:
|
|
|
|
return
|
|
|
|
|
2007-11-22 08:19:36 +00:00
|
|
|
# Vertical reference lines.
|
2007-11-14 18:35:18 +00:00
|
|
|
pixel_step = self.find_indicative_time_step ()
|
|
|
|
ctx.set_source_rgb (.9, .9, .9)
|
2007-11-22 08:19:36 +00:00
|
|
|
for i in range (1, w // pixel_step + 1):
|
2007-11-14 18:35:18 +00:00
|
|
|
x = i * pixel_step - .5
|
|
|
|
ctx.move_to (x, 0)
|
|
|
|
ctx.line_to (x, h)
|
|
|
|
ctx.stroke ()
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.process.freq_sentinel.data:
|
2007-11-21 15:40:31 +00:00
|
|
|
self.logger.debug ("frequency sentinel has no data yet")
|
2007-11-14 08:30:19 +00:00
|
|
|
return
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
maximum = max (self.process.freq_sentinel.data)
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
ctx.set_source_rgb (0., 0., 0.)
|
2007-11-22 14:06:55 +00:00
|
|
|
self.__draw_graph (ctx, w, h, maximum, self.process.freq_sentinel.data)
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.process.dist_sentinel.data:
|
2007-11-21 15:40:31 +00:00
|
|
|
self.logger.debug ("level distribution sentinel has no data yet")
|
|
|
|
return
|
2007-11-16 13:06:59 +00:00
|
|
|
|
|
|
|
theme = GUI.LevelColorThemeTango ()
|
2007-11-22 14:06:55 +00:00
|
|
|
dist_data = self.process.dist_sentinel.data
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-19 08:59:52 +00:00
|
|
|
def cumulative_level_counts (*levels):
|
|
|
|
for level_counts in dist_data:
|
|
|
|
yield sum ((level_counts[level] for level in levels))
|
|
|
|
|
|
|
|
level = Data.debug_level_info
|
|
|
|
levels_prev = (Data.debug_level_log, Data.debug_level_debug,)
|
|
|
|
ctx.set_source_rgb (*(theme.colors_float (level)[1]))
|
|
|
|
self.__draw_graph (ctx, w, h, maximum,
|
|
|
|
list (cumulative_level_counts (level, *levels_prev)))
|
|
|
|
|
2007-11-16 13:06:59 +00:00
|
|
|
level = Data.debug_level_debug
|
2007-11-19 08:59:52 +00:00
|
|
|
levels_prev = (Data.debug_level_log,)
|
2007-11-16 13:06:59 +00:00
|
|
|
ctx.set_source_rgb (*(theme.colors_float (level)[1]))
|
2007-11-19 08:59:52 +00:00
|
|
|
self.__draw_graph (ctx, w, h, maximum,
|
|
|
|
list (cumulative_level_counts (level, *levels_prev)))
|
2007-11-16 13:06:59 +00:00
|
|
|
|
|
|
|
level = Data.debug_level_log
|
|
|
|
ctx.set_source_rgb (*(theme.colors_float (level)[1]))
|
|
|
|
self.__draw_graph (ctx, w, h, maximum, [counts[level] for counts in dist_data])
|
|
|
|
|
2007-11-19 08:59:52 +00:00
|
|
|
# Draw error and warning triangle indicators:
|
|
|
|
|
2007-11-16 13:56:57 +00:00
|
|
|
for level in (Data.debug_level_warning, Data.debug_level_error,):
|
|
|
|
ctx.set_source_rgb (*(theme.colors_float (level)[1]))
|
|
|
|
for i, counts in enumerate (dist_data):
|
|
|
|
if counts[level] == 0:
|
|
|
|
continue
|
|
|
|
SIZE = 8
|
|
|
|
ctx.move_to (i - SIZE // 2, 0)
|
|
|
|
ctx.line_to (i + SIZE // 2, 0)
|
|
|
|
ctx.line_to (i, SIZE / 1.41)
|
|
|
|
ctx.close_path ()
|
|
|
|
ctx.fill ()
|
|
|
|
|
2007-11-16 13:06:59 +00:00
|
|
|
def __draw_graph (self, ctx, w, h, maximum, data):
|
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
if not data:
|
|
|
|
return
|
|
|
|
|
2007-11-16 13:06:59 +00:00
|
|
|
from operator import add
|
|
|
|
heights = [h * float (d) / maximum for d in data]
|
|
|
|
ctx.move_to (0, h)
|
2007-11-14 08:30:19 +00:00
|
|
|
for i in range (len (heights)):
|
|
|
|
ctx.line_to (i - .5, h - heights[i] + .5)
|
|
|
|
|
|
|
|
ctx.line_to (i, h)
|
|
|
|
ctx.close_path ()
|
|
|
|
|
|
|
|
ctx.fill ()
|
|
|
|
|
|
|
|
def __handle_expose_event (self, self_, event):
|
|
|
|
|
|
|
|
self.__redraw ()
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __handle_configure_event (self, self_, event):
|
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
self.logger.debug ("widget size configured to %ix%i",
|
|
|
|
event.width, event.height)
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
if event.width < 16:
|
2007-11-16 15:25:08 +00:00
|
|
|
return False
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
self.update (self.model)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __handle_size_request (self, self_, req):
|
|
|
|
|
|
|
|
# FIXME:
|
|
|
|
req.height = 64
|
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
class TimelineFeature (FeatureBase):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
state_section_name = "timeline"
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
def __init__ (self):
|
|
|
|
|
2007-11-23 13:04:14 +00:00
|
|
|
self.logger = logging.getLogger ("ui.timeline")
|
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
self.action_group = gtk.ActionGroup ("TimelineActions")
|
|
|
|
self.action_group.add_toggle_actions ([("show-timeline",
|
2007-11-22 08:29:23 +00:00
|
|
|
None, _("_Timeline"),)])
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
def handle_attach_window (self, window):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
self.log_view = window.log_view
|
|
|
|
|
|
|
|
ui = window.ui_manager
|
|
|
|
|
|
|
|
ui.insert_action_group (self.action_group, 0)
|
|
|
|
|
|
|
|
self.merge_id = ui.new_merge_id ()
|
|
|
|
ui.add_ui (self.merge_id, "/menubar/ViewMenu/ViewMenuAdditions",
|
2007-11-17 08:06:09 +00:00
|
|
|
"ViewTimeline", "show-timeline",
|
2007-11-14 08:30:19 +00:00
|
|
|
gtk.UI_MANAGER_MENUITEM, False)
|
|
|
|
|
|
|
|
box = window.get_top_attach_point ()
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
self.timeline = TimelineWidget ()
|
2007-11-17 08:06:09 +00:00
|
|
|
self.timeline.add_events (gtk.gdk.ALL_EVENTS_MASK) # FIXME
|
2007-11-20 09:06:27 +00:00
|
|
|
self.timeline.connect ("button-press-event", self.handle_timeline_button_press_event)
|
|
|
|
self.timeline.connect ("motion-notify-event", self.handle_timeline_motion_notify_event)
|
2007-11-17 08:06:09 +00:00
|
|
|
box.pack_start (self.timeline, False, False, 0)
|
|
|
|
self.timeline.hide ()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-23 09:46:43 +00:00
|
|
|
box = window.get_side_attach_point ()
|
|
|
|
|
|
|
|
self.vtimeline = VerticalTimelineWidget ()
|
|
|
|
box.pack_start (self.vtimeline, False, False, 0)
|
|
|
|
self.vtimeline.hide ()
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
window.widgets.log_view_scrolled_window.props.vadjustment.connect ("value-changed",
|
|
|
|
self.handle_log_view_adjustment_value_changed)
|
|
|
|
|
|
|
|
handler = self.handle_show_action_toggled
|
2007-11-22 08:29:23 +00:00
|
|
|
action = self.action_group.get_action ("show-timeline")
|
|
|
|
action.connect ("toggled", handler)
|
|
|
|
action.activate ()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
def handle_detach_window (self, window):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
window.ui_manager.remove_ui (self.merge_id)
|
|
|
|
self.merge_id = None
|
|
|
|
|
2007-11-20 11:31:58 +00:00
|
|
|
window.ui_manager.remove_action_group (self.action_group)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
self.timeline.destroy ()
|
|
|
|
self.timeline = None
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
def handle_attach_log_file (self, window, log_file):
|
2007-11-22 08:29:23 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
model = window.log_filter
|
|
|
|
self.timeline.update (model)
|
2007-11-23 13:04:14 +00:00
|
|
|
# FIXME: On startup, this triggers a GtkWarning in
|
|
|
|
# view.get_visible_range for no apparent reason.
|
|
|
|
## self.update_vtimeline ()
|
2007-11-22 14:06:55 +00:00
|
|
|
|
|
|
|
def handle_detach_log_file (self, window, log_file):
|
|
|
|
|
|
|
|
self.timeline.clear ()
|
2007-11-23 13:04:14 +00:00
|
|
|
self.vtimeline.clear ()
|
2007-11-22 08:29:23 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
def handle_log_view_adjustment_value_changed (self, adj):
|
|
|
|
|
|
|
|
# FIXME: If not visible, disconnect this handler!
|
2007-11-17 08:06:09 +00:00
|
|
|
if not self.timeline.props.visible:
|
2007-11-14 08:30:19 +00:00
|
|
|
return
|
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
model = self.log_view.props.model
|
2007-11-14 08:30:19 +00:00
|
|
|
start_path, end_path = self.log_view.get_visible_range ()
|
2007-11-23 09:46:43 +00:00
|
|
|
ts1 = model.get_value (model.get_iter (start_path),
|
|
|
|
model.COL_TIME)
|
|
|
|
ts2 = model.get_value (model.get_iter (end_path),
|
|
|
|
model.COL_TIME)
|
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
self.timeline.update_position (ts1, ts2)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-23 13:04:14 +00:00
|
|
|
self.update_vtimeline ()
|
|
|
|
|
|
|
|
def update_vtimeline (self):
|
|
|
|
|
|
|
|
model = self.log_view.props.model
|
|
|
|
start_path, end_path = self.log_view.get_visible_range ()
|
|
|
|
|
|
|
|
if not start_path or not end_path:
|
|
|
|
return
|
|
|
|
|
2007-11-23 09:46:43 +00:00
|
|
|
column = self.log_view.get_column (0)
|
|
|
|
cell_rect = self.log_view.get_cell_area (start_path, column)
|
|
|
|
first_y = self.log_view.convert_bin_window_to_widget_coords (cell_rect.x, cell_rect.y)[1]
|
|
|
|
bg_rect = self.log_view.get_background_area (start_path, column)
|
|
|
|
cell_height = bg_rect.height
|
|
|
|
|
|
|
|
ts_list = []
|
|
|
|
tree_iter = model.get_iter (start_path)
|
|
|
|
while model.get_path (tree_iter) != end_path:
|
|
|
|
ts_list.append (model.get_value (tree_iter, model.COL_TIME))
|
|
|
|
tree_iter = model.iter_next (tree_iter)
|
|
|
|
|
|
|
|
self.vtimeline.update (first_y, cell_height, ts_list)
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
def handle_show_action_toggled (self, action):
|
|
|
|
|
|
|
|
show = action.props.active
|
|
|
|
|
|
|
|
if show:
|
2007-11-17 08:06:09 +00:00
|
|
|
self.timeline.show ()
|
2007-11-23 09:46:43 +00:00
|
|
|
self.vtimeline.show ()
|
2007-11-14 08:30:19 +00:00
|
|
|
else:
|
2007-11-17 08:06:09 +00:00
|
|
|
self.timeline.hide ()
|
2007-11-23 09:46:43 +00:00
|
|
|
self.vtimeline.hide ()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-20 09:06:27 +00:00
|
|
|
def handle_timeline_button_press_event (self, widget, event):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if event.button != 1:
|
|
|
|
return True
|
|
|
|
|
|
|
|
pos = int (event.x)
|
2007-11-20 09:06:27 +00:00
|
|
|
self.goto_time_position (pos)
|
2007-11-14 08:30:19 +00:00
|
|
|
return False
|
|
|
|
|
2007-11-20 09:06:27 +00:00
|
|
|
def handle_timeline_motion_notify_event (self, widget, event):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if not event.state & gtk.gdk.BUTTON1_MASK:
|
|
|
|
return True
|
|
|
|
|
|
|
|
pos = int (event.x)
|
2007-11-20 09:06:27 +00:00
|
|
|
self.goto_time_position (pos)
|
2007-11-14 08:30:19 +00:00
|
|
|
return False
|
|
|
|
|
2007-11-20 09:06:27 +00:00
|
|
|
def goto_time_position (self, pos):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.timeline.process.freq_sentinel:
|
|
|
|
return True
|
|
|
|
|
|
|
|
data = self.timeline.process.freq_sentinel.data
|
2007-11-14 08:30:19 +00:00
|
|
|
if not data:
|
|
|
|
return True
|
2007-11-22 09:03:09 +00:00
|
|
|
|
|
|
|
if pos < 0:
|
|
|
|
pos = 0
|
|
|
|
elif pos >= len (data):
|
|
|
|
pos = len (data) - 1
|
|
|
|
|
2007-11-20 10:33:47 +00:00
|
|
|
count = sum (data[:pos + 1])
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
model = self.log_view.props.model
|
|
|
|
row = model[count]
|
2007-11-14 08:30:19 +00:00
|
|
|
self.log_view.scroll_to_cell ((count,), use_align = True, row_align = .5)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
class Plugin (PluginBase):
|
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
features = [TimelineFeature]
|