def gen_html_cpu(cpu): lev = tldata.level_order(data) graph = "" for name in lev: opts = { "title": name + " " + cpu, "width": 1000, "height": 180, #"xlabel": "time", } if name in data.metrics: unit = gen_level.get_unit(list(data.levels[name])[0]) if unit: opts["ylabel"] = unit else: opts["stackedGraph"] = 1 opts["stackedGraphNaNFill"] = "none" opts["ylabel"] = "% CPU time" unit = '%' if unit == '%': opts["valueRange"] = [-5, 110] graph += T(""" <div id="d_${cpu}_$name" class="disp"></div> <script type="text/javascript"> i = num_graphs++ goptions[i] = $opts goptions[i].highlightCallback = function(e, x, pts, row) { hilight_help(e, x, pts, row, help_$jname) } goptions[i].unhighlightCallback = unhilight_help goptions[i].drawCallback = draw_graph graphs[i] = new Dygraph(document.getElementById("d_${cpu}_$name"), "$cpu.$file.csv", goptions[i]) goptions[i]["file"] = "$cpu.$file.csv" </script> """).substitute({ "name": name, "jname": jsname(name), "file": name, "cpu": cpu, "opts": opts }) return graph
def gen_html_cpu(cpu): lev = tldata.level_order(data) graph = "" for name in lev: opts = { "title": name + " " + cpu, "width": 1000, "height": 180, #"xlabel": "time", } if name in data.metrics: unit = gen_level.get_unit(list(data.levels[name])[0]) if unit: opts["ylabel"] = unit else: opts["stackedGraph"] = 1 opts["stackedGraphNaNFill"] = "none" opts["ylabel"] = "% CPU time" unit = '%' if unit == '%': opts["valueRange"] = [-5, 110] graph += T(""" <div id="d_${cpu}_$name" class="disp"></div> <script type="text/javascript"> i = num_graphs++ goptions[i] = $opts goptions[i].highlightCallback = function(e, x, pts, row) { hilight_help(e, x, pts, row, help_$jname) } goptions[i].unhighlightCallback = unhilight_help goptions[i].drawCallback = draw_graph graphs[i] = new Dygraph(document.getElementById("d_${cpu}_$name"), "$cpu.$file.csv", goptions[i]) goptions[i]["file"] = "$cpu.$file.csv" </script> """).substitute({"name": name, "jname": jsname(name), "file": name, "cpu": cpu, "opts": opts}) return graph
def suffix(x): dot = x.rfind('.') if dot >= 0: return x[dot + 1:] return x n = 0 numplots = len(levels.keys()) ax = None yset = False max_legend = 0 xaxis = None legend_bbox = (0., 0., -0.07, -0.03) legend_loc = 2 for l in tldata.level_order(data): non_null = [x for x in levels[l] if valid_row(ratios[x])] if not non_null: n += 1 continue all_colors = get_colors(non_null) ax = plt.subplot2grid((numplots, 1), (n, 0), sharex=xaxis) plt.tight_layout() set_title(ax, l) r = [[y if y == y else 0.0 for y in ratios[x]] for x in non_null] if gen_level.is_metric(non_null[0]): for j, name in zip(r, non_null): stack = ax.plot(timestamps, j, label=name) leg = plt.legend(ncol=6, loc=legend_loc,
def suffix(x): dot = x.rfind('.') if dot >= 0: return x[dot+1:] return x n = 0 numplots = len(levels.keys()) ax = None yset = False max_legend = 0 xaxis = None legend_bbox = (0., 0., -0.07, -0.03) legend_loc = 2 for l in tldata.level_order(data): non_null = filter(lambda x: valid_row(ratios[x]), levels[l]) if not non_null: print "nothing in level", l n += 1 continue all_colors = get_colors(non_null) ax = plt.subplot2grid((numplots, 1), (n, 0), sharex=xaxis) plt.tight_layout() set_title(ax, l) r = [ratios[x] for x in non_null] if gen_level.is_metric(non_null[0]): for j, name in zip(r, non_null): stack = ax.plot(timestamps, j, label=name) leg = plt.legend(ncol=6,
def gen_html_header(): graph = """<html><head><title>Toplev</title> <link rel="shortcut icon" href="toplev.ico" /> <script type="text/javascript" src="dygraph-combined.js"></script> </head> <body> <script type="text/javascript"> var cpus = [""" graph += comma_strings(sorted(data.cpus)) + "]\n" graph += "var nodes = [" + comma_strings(tldata.level_order(data)) + "]" graph += """ var graphs = [] var goptions = [] var num_graphs = 0 var block_redraw = false function enable(el) { for (i = 0; i < cpus.length; i++) { p = document.getElementById("d_" + cpus[i] + "_" + el.name) p.style.display = el.checked ? 'block' : 'none'; } } function change_all(flag) { all_displays = document.getElementsByClassName("disp") for (i = 0; i < all_displays.length; i++) { p = all_displays[i]; p.style.display = flag ? 'block' : 'none'; } togs = document.getElementsByClassName("toggles") for (i = 0; i < togs.length; i++) { p = togs[i]; p.checked = flag; } } var timer function toggle_refresh(el) { p = document.getElementById("refresh_rate") if (timer) { clearInterval(timer) timer = null } if (el.checked) { timer = setInterval(function () { for (i = 0; i < num_graphs; i++) { graphs[i].updateOptions(goptions[i]) } }, Number(p.value)) } } function add_node(cpu, nd) { p = document.getElementById("d_" + cpus[cpu] + "_" + nodes[nd]) p.parentNode.appendChild(p) } function toggle_interleave(el) { if (!el.checked) { for (cpu = 0; cpu < cpus.length; cpu++) { for (nd = 0; nd < nodes.length; nd++) { add_node(cpu, nd) } } } else { for (nd = 0; nd < nodes.length; nd++) { for (cpu = 0; cpu < cpus.length; cpu++) { add_node(cpu, nd) } } } } function draw_graph(me, initial) { if (block_redraw || initial) return; block_redraw = true xrange = me.xAxisRange() for (i = 0; i < num_graphs; i++) { if (graphs[i] != me) { graphs[i].updateOptions({ dateWindow: xrange, }) } } block_redraw = false } function hilight_help(e, x, pts, row, help) { p = document.getElementById("help") h = "" for (i = 0; i < pts.length; i++) { n = pts[i].name if (n in help && help[n] != "") { h += "<b>" + n + "</b>: " + help[n] + " <br /> " } else { // location.reload(); // XXX } } p.innerHTML = h } function unhilight_help(e, x, pts, row) { p = document.getElementById("help") p.innerHTML = "" } </script> """ if args.title: graph += T("<h1>$title</h1>\n").substitute({"title": args.title}) graph += """ <div><p> <b>Display:</b> """ lev = tldata.level_order(data) for num, name in enumerate(lev): graph += T("""\ <input id="$id" class="toggles" type=checkbox name="$name" onClick="enable(this)" checked /> <label for="$id">$name</label> """).substitute({ "id": num, "name": name }) graph += """ <input id="all" type=checkbox name="dall" onClick="change_all(this.checked)" checked /> <label for="all">Toggle all</label> <input id="enable_refresh" type=checkbox onClick="toggle_refresh(this)" /> <label for="enable_refresh">Auto-refresh</label> <input id="refresh_rate" type="text" size=4 value="1000" name="refresh" /> <label for="refresh_rate">Refresh rate (ms)</label> <input id="interleave" type=checkbox onClick="toggle_interleave(this)" /> <label for="interleave">Interleave CPUs</label> </p></div> Drag to zoom. Double click to zoom out again<br /> <div id="help" style="position:fixed; right:0; width:300px; font-size: 11"> </div> """ for j in lev: graph += T(""" <script type="text/javascript"> help_$name = { """).substitute({"name": jsname(j)}) for i in data.levels[j]: if i not in data.helptxt: #print i,"not found in",data.helptxt.keys() continue graph += T(""" "$name": "$help", """).substitute({ "name": get_postfix(i), "help": data.helptxt[i] }) graph += """ } </script> """ return graph
def gen_html_header(): graph = """<html><head><title>Toplev</title> <link rel="shortcut icon" href="toplev.ico" /> <script type="text/javascript" src="dygraph-combined.js"></script> </head> <body> <script type="text/javascript"> var cpus = [""" graph += comma_strings(sorted(data.cpus)) + "]\n" graph += "var nodes = [" + comma_strings(tldata.level_order(data)) + "]" graph += """ var graphs = [] var goptions = [] var num_graphs = 0 var block_redraw = false function enable(el) { for (i = 0; i < cpus.length; i++) { p = document.getElementById("d_" + cpus[i] + "_" + el.name) p.style.display = el.checked ? 'block' : 'none'; } } function change_all(flag) { all_displays = document.getElementsByClassName("disp") for (i = 0; i < all_displays.length; i++) { p = all_displays[i]; p.style.display = flag ? 'block' : 'none'; } togs = document.getElementsByClassName("toggles") for (i = 0; i < togs.length; i++) { p = togs[i]; p.checked = flag; } } var timer function toggle_refresh(el) { p = document.getElementById("refresh_rate") if (timer) { clearInterval(timer) timer = null } if (el.checked) { timer = setInterval(function () { for (i = 0; i < num_graphs; i++) { graphs[i].updateOptions(goptions[i]) } }, Number(p.value)) } } function add_node(cpu, nd) { p = document.getElementById("d_" + cpus[cpu] + "_" + nodes[nd]) p.parentNode.appendChild(p) } function toggle_interleave(el) { if (!el.checked) { for (cpu = 0; cpu < cpus.length; cpu++) { for (nd = 0; nd < nodes.length; nd++) { add_node(cpu, nd) } } } else { for (nd = 0; nd < nodes.length; nd++) { for (cpu = 0; cpu < cpus.length; cpu++) { add_node(cpu, nd) } } } } function draw_graph(me, initial) { if (block_redraw || initial) return; block_redraw = true xrange = me.xAxisRange() for (i = 0; i < num_graphs; i++) { if (graphs[i] != me) { graphs[i].updateOptions({ dateWindow: xrange, }) } } block_redraw = false } function hilight_help(e, x, pts, row, help) { p = document.getElementById("help") h = "" for (i = 0; i < pts.length; i++) { n = pts[i].name if (n in help && help[n] != "") { h += "<b>" + n + "</b>: " + help[n] + " <br /> " } else { // location.reload(); // XXX } } p.innerHTML = h } function unhilight_help(e, x, pts, row) { p = document.getElementById("help") p.innerHTML = "" } </script> """ if args.title: graph += T("<h1>$title</h1>\n").substitute({"title": args.title}) graph += """ <div><p> <b>Display:</b> """ lev = tldata.level_order(data) for num, name in enumerate(lev): graph += T("""\ <input id="$id" class="toggles" type=checkbox name="$name" onClick="enable(this)" checked /> <label for="$id">$name</label> """).substitute({"id": num, "name": name}) graph += """ <input id="all" type=checkbox name="dall" onClick="change_all(this.checked)" checked /> <label for="all">Toggle all</label> <input id="enable_refresh" type=checkbox onClick="toggle_refresh(this)" /> <label for="enable_refresh">Auto-refresh</label> <input id="refresh_rate" type="text" size=4 value="1000" name="refresh" /> <label for="refresh_rate">Refresh rate (ms)</label> <input id="interleave" type=checkbox onClick="toggle_interleave(this)" /> <label for="interleave">Interleave CPUs</label> </p></div> Drag to zoom. Double click to zoom out again<br /> <div id="help" style="position:fixed; right:0; width:300px; font-size: 11"> </div> """ for j in lev: graph += T(""" <script type="text/javascript"> help_$name = { """).substitute({"name": jsname(j)}) for i in data.levels[j]: if i not in data.helptxt: #print i,"not found in",data.helptxt.keys() continue graph += T(""" "$name": "$help", """).substitute({"name": get_postfix(i), "help": data.helptxt[i] }) graph += """ } </script> """ return graph