Back to index

unity  6.0.0
Functions | Variables
makebootchart Namespace Reference

Functions

def sort_by_domain
def gatherinfo
def draw_bg_graph
def build_graph
def build_data_structure
def usage
def main

Variables

tuple header = Template("""Unity bootchart for $hostname ($date)uname: $unameCPU: $cpuGPU: $gputime: $total_time""")
int width_multiplier = 1000
int bar_height = 16

Function Documentation

Definition at line 156 of file makebootchart.py.

00156 
00157 def build_data_structure (input):
00158   reader = csv.reader(open(input))
00159   structure = []
00160   print "reading", input
00161   for row in reader:
00162     name = row[0]
00163     start = float(row[1])
00164     end = float(row[2])
00165     structure.append ({"name": name, "start": start, "end": end})
00166 
00167   structure.sort (sort_by_domain)
00168   return structure
00169 

def makebootchart.build_graph (   data,
  filename,
  info 
)

Definition at line 97 of file makebootchart.py.

00097 
00098 def build_graph (data, filename, info):
00099 
00100   padding_left = 6
00101   padding_right = 100
00102   padding_top = 6
00103   padding_bottom = 6
00104 
00105   total_size = 0.0
00106   for item in data:
00107     if item['end'] > total_size:
00108       total_size = item['end']
00109 
00110   width = total_size * width_multiplier + padding_left + padding_right
00111   height = (len(data) * (bar_height)) + 80 + padding_bottom + padding_top
00112   surface = cairo.SVGSurface(filename, max (width, 800), max (height, 600))
00113 
00114   ctx = cairo.Context (surface)
00115 
00116   #fill background
00117   ctx.set_source_rgb (1, 1, 1)
00118   ctx.rectangle (0, 0,  max (width, 800), max (height, 600))
00119   ctx.fill ()
00120 
00121   #print header
00122   info['total_time'] = "%s secs" % total_size
00123   sheader = header.substitute(info)
00124 
00125   ctx.translate (padding_left, padding_top)
00126   ctx.set_source_rgb (0, 0, 0)
00127   for line in sheader.split("\n"):
00128     ctx.translate (0, 12)
00129     ctx.show_text (line)
00130     ctx.fill ()
00131 
00132   ctx.translate (6, 12)
00133 
00134   draw_bg_graph (ctx, total_size + 0.5, max (len (data) * bar_height + 64, 500))
00135 
00136   ctx.set_line_width (1)
00137   for item in data:
00138     x = item['start'] * width_multiplier
00139     x1 = (item['end'] - item['start']) * width_multiplier
00140     ctx.translate (x, 0)
00141 
00142     ctx.set_source_rgba (0.35, 0.65, 0.8, 0.5)
00143     ctx.rectangle (0, 0, x1, 16)
00144     ctx.fill ()
00145 
00146     ctx.set_source_rgba (0.35, 0.65, 0.8, 1.0)
00147     ctx.rectangle (0, 0, x1, 16)
00148     ctx.stroke ()
00149 
00150     ctx.translate (8, 10)
00151     ctx.set_source_rgb (0.0, 0.0, 0.0)
00152     ctx.show_text ("%s %.4f seconds" % (item['name'], item["end"] - item["start"]))
00153     ctx.fill()
00154 
00155     ctx.translate (-x-8, 6)

def makebootchart.draw_bg_graph (   ctx,
  seconds,
  height 
)

Definition at line 69 of file makebootchart.py.

00069 
00070 def draw_bg_graph (ctx, seconds, height):
00071 
00072   total_width = seconds * width_multiplier
00073   ctx.set_source_rgba (0.0, 0.0, 0.0, 0.25)
00074 
00075   ctx.move_to (0, 0)
00076   ctx.line_to (total_width, 0)
00077   ctx.stroke ()
00078 
00079   per_ten = 0
00080   for pos in xrange (0, int(total_width), int (0.01 * width_multiplier)):
00081     ctx.set_line_width (1)
00082     ctx.set_source_rgba (0.0, 0.0, 0.0, 0.10)
00083 
00084     if (not per_ten):
00085       ctx.set_line_width (2)
00086       ctx.set_source_rgba (0.0, 0.0, 0.0, 0.25)
00087       ctx.move_to (pos-6, -2)
00088       ctx.show_text (str (pos / float(width_multiplier)))
00089       ctx.stroke ()
00090 
00091     ctx.move_to (pos, 0)
00092     ctx.line_to (pos, height)
00093     ctx.stroke ()
00094 
00095     per_ten += 1
00096     per_ten %= 10

def makebootchart.gatherinfo (   filename)

Definition at line 44 of file makebootchart.py.

00044 
00045 def gatherinfo (filename):
00046   date =  datetime.fromtimestamp(os.path.getmtime(filename))
00047 
00048   cpufile = open ("/proc/cpuinfo")
00049   cpuinfo = cpufile.read (10024)
00050   cpure = re.search (r"^model name\s*: (.*$)", cpuinfo, re.MULTILINE)
00051   cpu = cpure.group(1)
00052 
00053   gpu_prog = subprocess.Popen("glxinfo", stdout=subprocess.PIPE)
00054   gpu_prog.wait ()
00055   gpuinfo = gpu_prog.stdout.read (10024)
00056   gpure = re.search (r"^OpenGL renderer string: (.*$)", gpuinfo, re.MULTILINE)
00057   gpu = gpure.group (1)
00058 
00059   return {"hostname":gethostname(),
00060           "date": date.strftime("%A, %d. %B %Y %I:%M%p"),
00061           "uname": " ".join (os.uname ()),
00062           "cpu": cpu,
00063           "gpu": gpu,
00064           "total_time": "undefined"
00065           }

Definition at line 173 of file makebootchart.py.

00173 
00174 def main():
00175 
00176   try:
00177       opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "output=", "input="])
00178   except getopt.GetoptError, err:
00179     # print help information and exit:
00180     print str(err) # will print something like "option -a not recognized"
00181     usage()
00182     sys.exit(2)
00183 
00184   output = None
00185   input = None
00186   for o, a in opts:
00187     if o in ("-h", "--help"):
00188       usage()
00189       sys.exit()
00190     elif o in ("--output"):
00191       output = a
00192     elif o in ("--input"):
00193       input = a
00194     else:
00195       assert False, "unhandled option"
00196 
00197   if (not output or not input):
00198     usage()
00199     sys.exit()
00200 
00201   data = build_data_structure (input)
00202   info = gatherinfo (input)
00203   build_graph (data, output, info)
00204 
00205 
00206   return 0

Here is the call graph for this function:

def makebootchart.sort_by_domain (   x,
  y 
)

Definition at line 38 of file makebootchart.py.

00038 
00039 def sort_by_domain (x, y):
00040   if x["start"] - y["start"] < 0:
00041     return -1
00042   else:
00043     return +1

Definition at line 170 of file makebootchart.py.

00170 
00171 def usage():
00172   print "use --input=filename.log and --output=filename.svg :)"

Here is the caller graph for this function:


Variable Documentation

Definition at line 67 of file makebootchart.py.

tuple makebootchart.header = Template("""Unity bootchart for $hostname ($date)uname: $unameCPU: $cpuGPU: $gputime: $total_time""")

Definition at line 32 of file makebootchart.py.

Definition at line 66 of file makebootchart.py.