trace.html 2.46 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
2
3
4
5
6
7
8
9
10
11
12
13
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<head>
 <title>
  Trace
 </title>
</head>

<body background="achtergrond.jpg">

<div id="trace_win"></div>

Jeroen Vreeken's avatar
Jeroen Vreeken committed
14

Jeroen Vreeken's avatar
Jeroen Vreeken committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

</body>

<script src="js/load.js" type="application/javascript"></script>
<script src="js/trace.js" type="application/javascript"></script>
<script src="js/dt_ui.js" type="application/javascript"></script>
<script src="js/dygraph-combined.js" type="application/javascript"></script>

<script type="application/javascript">


var tw = new dt_ui_window("trace_win");

tw.title_set("Trace");

var graph = new dt_ui_element("trace_win_graph");
var tsel = new dt_ui_select("trace_win_select");
Jeroen Vreeken's avatar
Jeroen Vreeken committed
32
33
34
var tlabel = new dt_ui_element("trace_win_label");

tw.add([ graph, tsel, tlabel ]);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
35

Jeroen Vreeken's avatar
Jeroen Vreeken committed
36
tlabel.text_set("Select trace...");
Jeroen Vreeken's avatar
Jeroen Vreeken committed
37

Jeroen Vreeken's avatar
Jeroen Vreeken committed
38
39
40
41
graph.width_set(window.innerWidth - 60);
graph.height_set(window.innerHeight - 200);

tw.align_vertical([ tsel, tlabel, graph ]);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
42
43
44
45
46
47
48
49
50
51
52
53


var traces_url = "/traces/";

var traces_index = load(traces_url, true);
var traces_links = traces_index.split("href=");
var i;
traces_links.shift();
for (i = 0; i < traces_links.length; i++)
	traces_links[i] = traces_links[i].match("'.*'")[0];
for (i = 0; i < traces_links.length; i++)
	traces_links[i] = traces_links[i].substring(1, traces_links[i].length - 1);
54
traces_links.sort();
Jeroen Vreeken's avatar
Jeroen Vreeken committed
55
56
57
58


function load_trace(tracename)
{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
59
60
	tlabel.text_set("Loading " + tracename + " ...");
	
Jeroen Vreeken's avatar
Jeroen Vreeken committed
61
62
63
64
65
66
	load_bin(tracename, function(buf) {
		var ts = new trace_stream();
		var got_time = false;
	
		var trace_data = new Array();
	
67
		ts.handler_value = function(ts, channel, value) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
			var td = new trace_value();
			td.set(value);
			trace_data.push(td);
		}
	
		ts.rx(buf);
		ts.handle();
	
		var i;
		for (i = 0; i < trace_data.length; i++) {
			if (!got_time && trace_data[i].t.sec > 100000) {
				var newt = new timespec();
				newt.set(trace_data[i].t);
				
				var j;
				for (j = i -1; j >= 0; j--) {
					newt.sub(ts.interval);
					trace_data[j].t.set(newt);
				}
				got_time = true;
			}
		}
	
		var graph_data = new Array();
		
		for (i = 0; i < trace_data.length; i++) {
			var td = new Array();
	
			td.push(new Date(trace_data[i].t.ms_get()));
			td.push(trace_data[i].value);
			graph_data.push(td);
		}

		g = new Dygraph(
			graph.element,

			graph_data,
			{ labels: [ "x", ts.name ] }
		);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
107
		tlabel.text_set("Viewing " + tracename);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
108
109
110
111
112
113
114
115
116
117
118
	});
}

var i;
for (i = 0; i < traces_links.length; i++) {
	tsel.option_add(traces_links[i], load_trace, traces_url + traces_links[i]);
}

</script>

</html>