sbsv2/raptor/bin/timelines.py
branchwip
changeset 100 55250667c668
parent 85 d82b03c7df17
equal deleted inserted replaced
99:7204b1c9d0e8 100:55250667c668
    23 import pygame
    23 import pygame
    24 from pygame.locals import *
    24 from pygame.locals import *
    25 import time
    25 import time
    26 
    26 
    27 class Timeline(object):
    27 class Timeline(object):
       
    28 	"""A bar representing a number of recipes which were executed in 
       
    29 	   time sequence.  There is no guarantee about what host but in 
       
    30 	   theory they could have been executed on the same host."""
    28 
    31 
    29 	globalmax = 2.0
    32 	globalmax = 2.0
    30 
    33 
    31 	def __init__(self,ylevel):
    34 	def __init__(self,ylevel):
    32 		self.maxtime = 0.0
    35 		self.maxtime = 0.0
    33 		self.recipes = []
    36 		self.recipes = []
    34 		self.ylevel = ylevel
    37 		self.ylevel = ylevel
    35 
    38 
    36 	def append(self, recipe):
    39 	def append(self, recipe):
       
    40 		"" add this recipe to this timeline if it happens after the latest recipe already in the timeline ""
    37 		if recipe.starttime + recipe.duration > self.maxtime:
    41 		if recipe.starttime + recipe.duration > self.maxtime:
    38 			self.maxtime = recipe.starttime + recipe.duration
    42 			self.maxtime = recipe.starttime + recipe.duration
    39 			if self.maxtime > Timeline.globalmax:
    43 			if self.maxtime > Timeline.globalmax:
    40 				Timeline.globalmax = self.maxtime 
    44 				Timeline.globalmax = self.maxtime 
    41 			#print "maxtime:",self.maxtime
       
    42 			#print "xscale:",self.xscale
       
    43 		else:
    45 		else:
    44 			pass
    46 			pass
    45 			#print "bob",self.maxtime
       
    46 
    47 
    47 		self.recipes.append(recipe)
    48 		self.recipes.append(recipe)
    48 
    49 
    49 	def draw(self):
    50 	def draw(self):
    50 		glLoadIdentity()
    51 		glLoadIdentity()
    60 
    61 
    61 			count += 1
    62 			count += 1
    62 			r.draw(self.xscale, self.ylevel, coloff)
    63 			r.draw(self.xscale, self.ylevel, coloff)
    63 
    64 
    64 class Recipe(object):
    65 class Recipe(object):
       
    66 	"""Represents a task completed in a raptor build. 
       
    67 	   Drawn as a colour-coded bar with different 
       
    68 	   colours for the various recipe types."""
    65 	STAT_OK = 0
    69 	STAT_OK = 0
    66 	colours = {
    70 	colours = {
    67 		'compile': (0.5,0.5,1.0),
    71 		'compile': (0.5,0.5,1.0),
    68 		'compile2object': (0.5,0.5,1.0),
    72 		'compile2object': (0.5,0.5,1.0),
    69 		'win32compile2object': (0.5,0.5,1.0),
    73 		'win32compile2object': (0.5,0.5,1.0),
    70 		'tools2linkexe': (0.5,1.0,0.5),
    74 		'tools2linkexe': (0.5,1.0,0.5),
    71 		'link': (0.5,1.0,0.5),
    75 		'link': (0.5,1.0,0.5),
       
    76 		'linkandpostlink': (0.5,1.0,0.5),
    72 		'win32stageonelink': (0.5,1.0,0.5),
    77 		'win32stageonelink': (0.5,1.0,0.5),
    73 		'tools2lib': (0.5,1.0,1.0),
    78 		'tools2lib': (0.5,1.0,1.0),
    74 		'win32stagetwolink': (1.0,0.1,1.0),
    79 		'win32stagetwolink': (1.0,0.1,1.0),
    75 		'postlink': (1.0,0.5,1.0)
    80 		'postlink': (1.0,0.5,1.0)
    76 		}
    81 		}
    90 		if self.status == Recipe.STAT_OK:
    95 		if self.status == Recipe.STAT_OK:
    91 			glColor4f(self.colour[0]*coloff, self.colour[1]*coloff, self.colour[2]*coloff,0.2)
    96 			glColor4f(self.colour[0]*coloff, self.colour[1]*coloff, self.colour[2]*coloff,0.2)
    92 		else:
    97 		else:
    93 			glColor4f(1.0*coloff, 0.6*coloff, 0.6*coloff,0.2)
    98 			glColor4f(1.0*coloff, 0.6*coloff, 0.6*coloff,0.2)
    94 
    99 
    95 		print "ylevel: %s %f " % (self.name, ylevel)
       
    96 
   100 
    97 		x = self.starttime * scale
   101 		x = self.starttime * scale
    98 		y = ylevel
   102 		y = ylevel
    99 		x2 = x + self.duration * scale
   103 		x2 = x + self.duration * scale
   100 		y2 = ylevel + 0.2
   104 		y2 = ylevel + 0.2
   146 	timelines = []
   150 	timelines = []
   147 	ylevel = 0.0
   151 	ylevel = 0.0
   148 	for i in xrange(0,4):
   152 	for i in xrange(0,4):
   149 		ylevel += 0.6 
   153 		ylevel += 0.6 
   150 		timelines.append(Timeline(ylevel))
   154 		timelines.append(Timeline(ylevel))
   151 		print "TIMELINE", ylevel
       
   152 
   155 
   153 	f = sys.stdin
   156 	f = sys.stdin
   154 
   157 
   155 	recipe_re = re.compile(".*<recipe name='([^']+)'.*")
   158 	recipe_re = re.compile(".*<recipe name='([^']+)'.*")
   156 	time_re = re.compile(".*<time start='([0-9]+\.[0-9]+)' *elapsed='([0-9]+\.[0-9]+)'.*")
   159 	time_re = re.compile(".*<time start='([0-9]+\.[0-9]+)' *elapsed='([0-9]+\.[0-9]+)'.*")
   177 			if start_time == 0.0:
   180 			if start_time == 0.0:
   178 				start_time = s
   181 				start_time = s
   179 
   182 
   180 			s -= start_time
   183 			s -= start_time
   181 
   184 
   182 			#print s,elapsed
       
   183 			continue
   185 			continue
   184 
   186 
   185 		sm = status_re.match(l2)
   187 		sm = status_re.match(l2)
   186 
   188 
   187 		if sm is None:
   189 		if sm is None:
   196 		tnum = 0
   198 		tnum = 0
   197 		for t in timelines:
   199 		for t in timelines:
   198 			newdiff = s - t.maxtime
   200 			newdiff = s - t.maxtime
   199 			if newdiff < 0.0:
   201 			if newdiff < 0.0:
   200 				continue
   202 				continue
   201 			#print "diff: %f" % (newdiff)
       
   202 			if olddiff > newdiff:
   203 			if olddiff > newdiff:
   203 				dest_timeline = t
   204 				dest_timeline = t
   204 				olddiff = newdiff
   205 				olddiff = newdiff
   205 				#print "timeline selected: %d diff: %f" % (tnum,newdiff)
       
   206 			tnum += 1
   206 			tnum += 1
   207 		#print "----------"
       
   208 
   207 
   209 		dest_timeline.append(Recipe(s, elapsed, rname, status))
   208 		dest_timeline.append(Recipe(s, elapsed, rname, status))
   210 		event = pygame.event.poll()
   209 		event = pygame.event.poll()
   211 		if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
   210 		if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
   212 			break
   211 			break