aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Tardy <tardyp@gmail.com>2010-04-28 00:21:34 +0200
committerPierre Tardy <tardyp@gmail.com>2010-04-28 00:33:16 +0200
commitdd2ab94a6c92ec69db3a8df4adbd471ffc16b2e0 (patch)
tree2bd397ed7fe5a1c0b4a35846911e4326cb04815f
parentb8d13383a02e8303660a9613ab7619192dbc549c (diff)
timechart: emphasis positions where irqs are too long
Signed-off-by: Pierre Tardy <tardyp@gmail.com>
-rwxr-xr-xtimechart/timechart.py28
-rwxr-xr-xtimechart/timechart_plot.py93
2 files changed, 77 insertions, 44 deletions
diff --git a/timechart/timechart.py b/timechart/timechart.py
index c262916..7c51b57 100755
--- a/timechart/timechart.py
+++ b/timechart/timechart.py
@@ -31,6 +31,9 @@ class Timechart(HasTraits):
total_time = Property(Int)
max_types = Property(Int)
bg_color = Property(ColorTrait)
+ max_latency = Property(Int)
+ max_latency_ts = Property(CArray)
+
@cached_property
def _get_total_time(self):
return sum(self.end_ts-self.start_ts)
@@ -56,7 +59,9 @@ class Timechart(HasTraits):
self.types = types
def get_comment(self,i):
return "%d"%(self.types[i])
-
+ @cached_property
+ def _get_max_latency(self):
+ return -1
class Process(Timechart):
name = Property(String) # overide TimeChart
# start_ts=CArray # inherited from TimeChart
@@ -87,13 +92,26 @@ class Process(Timechart):
else:
return ""
@cached_property
+ def _get_max_latency(self):
+ if self.pid==0 and self.comm.startswith("irq"):
+ return 1000
+
+ @cached_property
+ def _get_max_latency_ts(self):
+ if self.max_latency > 0:
+ indices = np.nonzero((self.end_ts - self.start_ts) > self.max_latency)[0]
+ print indices
+ return np.array(sorted(map(lambda i:self.start_ts[i], indices)))
+ return []
+
+
+ @cached_property
def _get_bg_color(self):
+ if self.max_latency >0 and max(self.end_ts - self.start_ts)>self.max_latency:
+ return (1,.1,.1,1)
if self.pid==0:
if self.comm.startswith("irq"):
- if max(self.end_ts - self.start_ts)>1000:# irq > 1ms!!!
- return (1,.1,.1,1)
- else:
- return (.9,1,.9,1)
+ return (.9,1,.9,1)
if self.comm.startswith("softirq"):
return (.7,1,.7,1)
if self.comm.startswith("work"):
diff --git a/timechart/timechart_plot.py b/timechart/timechart_plot.py
index 2b66770..31a33ed 100755
--- a/timechart/timechart_plot.py
+++ b/timechart/timechart_plot.py
@@ -120,17 +120,16 @@ class TimeChartPlot(BarPlot):
self.request_redraw()
- def _gather_timechart_points(self,tc,y):
- low_i = searchsorted(tc.end_ts,self.index_mapper.range.low)
- high_i = searchsorted(tc.start_ts,self.index_mapper.range.high)
-
+ def _gather_timechart_points(self,start_ts,end_ts,y,step):
+ low_i = searchsorted(end_ts,self.index_mapper.range.low)
+ high_i = searchsorted(start_ts,self.index_mapper.range.high)
if low_i==high_i:
return array([])
- start_ts = tc.start_ts[low_i:high_i]
- end_ts = tc.end_ts[low_i:high_i]
+ start_ts = start_ts[low_i:high_i]
+ end_ts = end_ts[low_i:high_i]
points = column_stack((start_ts,end_ts,
- zeros(high_i-low_i)+(y+.2), ones(high_i-low_i)+(y-.2),array(range(low_i,high_i))))
+ zeros(high_i-low_i)+(y+step), ones(high_i-low_i)+(y-step),array(range(low_i,high_i))))
return points
def _draw_label(self,gc,label,text,x,y):
label.text = text
@@ -140,16 +139,17 @@ class TimeChartPlot(BarPlot):
label.draw(gc)
gc.translate_ctm(*(-offset))
return l_w,l_h
- def _draw_timechart(self,gc,tc,label,y,fill_colors):
- bar_middle_y = self.first_bar_y+(y+.5)*self.bar_height
+ def _draw_timechart(self,gc,tc,label,base_y,fill_colors):
+
+ bar_middle_y = self.first_bar_y+(base_y+.5)*self.bar_height
if bar_middle_y+self.bar_height < self.y or bar_middle_y-self.bar_height>self.y+self.height:
return 1 #quickly decide we are not on the screen
- points = self._gather_timechart_points(tc,y)
+ points = self._gather_timechart_points(tc.start_ts,tc.end_ts,base_y,.2)
if self.options.remove_pids_not_on_screen and points.size == 0:
return 0
# we are too short in height, dont display all the labels
if self.last_label >= bar_middle_y:
- self._draw_bg(gc,y,tc.bg_color)
+ self._draw_bg(gc,base_y,tc.bg_color)
# draw label
l_w,l_h = self._draw_label(gc,label,tc.name,self.x,bar_middle_y)
self.last_label = bar_middle_y-(l_h*2/3)
@@ -175,35 +175,50 @@ class TimeChartPlot(BarPlot):
rects=column_stack((lower_left_pts, bounds))
gc.rects(rects)
gc.draw_path()
- return 1
- # lets display them more nicely
- rects=column_stack((lower_left_pts, bounds,points[:,(4)]))
- last_t = -1
- gc.save_state()
- for x,y,sx,sy,i in rects:
- t = tc.types[i]
-
- if last_t != t:
- # only draw when we change color. agg will then simplify the path
- # note that a path only can only have one color in agg.
- gc.draw_path()
- if len(fill_colors)>t:
- gc.set_fill_color(fill_colors[int(t)])
- last_t = t
- gc.rect(x,y,sx,sy)
- # draw last path
- gc.draw_path()
- if tc.has_comments:
+ else:
+ # lets display them more nicely
+ rects=column_stack((lower_left_pts, bounds,points[:,(4)]))
+ last_t = -1
+ gc.save_state()
for x,y,sx,sy,i in rects:
- if sx<8: # not worth calculatig text size
- continue
- label.text = tc.get_comment(i)
- l_w,l_h = label.get_width_height(gc)
- if l_w < sx:
- offset = array((x,y+self.bar_height*.6/2-l_h/2))
- gc.translate_ctm(*offset)
- label.draw(gc)
- gc.translate_ctm(*(-offset))
+ t = tc.types[i]
+
+ if last_t != t:
+ # only draw when we change color. agg will then simplify the path
+ # note that a path only can only have one color in agg.
+ gc.draw_path()
+ if len(fill_colors)>t:
+ gc.set_fill_color(fill_colors[int(t)])
+ last_t = t
+ gc.rect(x,y,sx,sy)
+ # draw last path
+ gc.draw_path()
+ if tc.has_comments:
+ for x,y,sx,sy,i in rects:
+ if sx<8: # not worth calculatig text size
+ continue
+ label.text = tc.get_comment(i)
+ l_w,l_h = label.get_width_height(gc)
+ if l_w < sx:
+ offset = array((x,y+self.bar_height*.6/2-l_h/2))
+ gc.translate_ctm(*offset)
+ label.draw(gc)
+ gc.translate_ctm(*(-offset))
+ if tc.max_latency > 0: # emphase events where max_latency is reached
+ ts = tc.max_latency_ts
+ if ts.size>0:
+ points = self._gather_timechart_points(ts,ts,base_y,0)
+ if points.size>0:
+ # map the bars start and stop locations into screen space
+ gc.set_alpha(1)
+ lower_left_pts = self.map_screen(points[:,(0,2)])
+ upper_right_pts = self.map_screen(points[:,(1,3)])
+ bounds = upper_right_pts - lower_left_pts
+ rects=column_stack((lower_left_pts, bounds))
+ gc.rects(rects)
+ gc.draw_path()
+
+
return 1
def _draw_freqchart(self,gc,tc,label,y):