-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
182 lines (154 loc) · 4.05 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<HTML>
<HEAD>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Test XHRMeasure</title>
<script src="xhrm.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.4.0/vis.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.4.0/vis.min.css" rel="stylesheet" type="text/css" />
<style>
body {
font-family: Arial;
}
div#visualization {
}
div#errors {
border-width:1px;
border-style:dotted;
font-family: courier;
font-size: 13px;
display: block;
height: 100px;
overflow-y:scroll;
margin-bottom: 20px;
}
div#stats {
border-width:1px;
border-style:dotted;
font-family: courier;
font-size: 13px;
display: block;
height: 200px;
overflow-y:scroll;
margin-bottom: 20px;
}
</style>
</HEAD>
<BODY>
<script>
function makeJQXHRCall() {
xhrurlObj = document.getElementById("xhrurl");
if(xhrurlObj.value) {
jQuery.ajax(xhrurlObj.value);
//jQuery.ajax('http://test.nerv.home/plants.xml');
}
}
function printStats() {
// take sample from JS object that contains samples
sample = popMetricsSample()
if(sample){
// print log and add a data point in the graph
var statsDiv = document.getElementById('stats');
statsDiv.innerHTML = statsDiv.innerHTML + line(sample);
addDataPoint(sample['total']);
delete sample;
}
var statsDiv = document.getElementById("stats");
statsDiv.scrollTop = statsDiv.scrollHeight;
}
function line(sample) {
ct = sample['connect'] - sample['start'];
rt = sample['received'] - sample['connect'];
tt = sample['processing'] - sample['received'];
pt = sample['ready'] - sample['processing'];
return b(sample['status']) + " " + b(sample['text']) + " " + ct + "ms " + rt + "ms " + tt + "ms " + pt + "ms " + b(sample['total']+"ms") + " " + sample['size']+"bytes" + " " + sample['url'] + " " + "</br>";
}
function b(a) {
return "<b>"+a+"</b>";
}
function popMetricsSample() {
for (var key in XHRM.log) {
if (XHRM.log[key]['complete'] == true) {
var sample = jQuery.extend(true, {}, XHRM.log[key])
delete XHRM.log[key];
return sample;
}
}
}
</script>
<label>Provide a URL: </label><input type="text" size="50" id="xhrurl" value="sleep.php"></input>
<h4>Performance</h4>
<script type="text/javascript">
// Partial example from the VisJS example pages
function renderStep() {
var now = vis.moment();
var range = graph2d.getWindow();
var interval = range.end - range.start;
graph2d.setWindow(now - interval, now, {
animation : false
});
setTimeout(renderStep, DELAY);
}
function addDataPoint(millies) {
// add a new data point to the dataset
var now = vis.moment();
dataset.add({
x : now,
y : millies
});
// remove all data points which are no longer visible
var range = graph2d.getWindow();
var interval = range.end - range.start;
var oldIds = dataset.getIds({
filter : function(item) {
return item.x < range.start - interval;
}
});
dataset.remove(oldIds);
}
</script>
<div id="visualization"></div>
<h4>XHR Log</h4>
<div id="stats"></div>
<h4>Errors</h4>
<div id="errors"></div>
<script>
var DELAY = 1000;
var container = document.getElementById('visualization');
var dataset = new vis.DataSet();
var options = {
start : vis.moment().add(-30, 'seconds'), // changed so its faster
end : vis.moment(),
dataAxis : {
left : {
range : {
min : 0,
max : 1000
}
}
},
drawPoints : {
style : 'square' // square, circle
},
shaded : {
orientation : 'bottom' // top, bottom
},
width: '100%',
height: '200px',
};
var graph2d = new vis.Graph2d(container, dataset, options);
// start up when page is loaded
document.body.onload = function () {
try {
XHRM.init();
} catch(err) {
document.getElementById("errors").innerHTML = err.message;
}
renderStep();
var XHLloopHandle = setInterval(makeJQXHRCall, 1000);
var printStatsLoopHandle = setInterval(printStats, 400);
}
</script>
</BODY>
</HTML>