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
|
/* Log time taken for AJAX requests.
*/
function start_ajax_logging() {
/* Requests slower than this are marked as slow. Value in seconds.
*/
var AJAX_OK_TIME = 1;
LPS.use('node', 'lazr.anim', function(Y) {
Y.on('contentready', function() {
var node = Y.one('#ajax-time-list');
var ajax_request_times = {};
var ajax_menu_animating = false;
var flash_menu = Y.lazr.anim.green_flash({node:'#ajax-time'});
flash_menu.on('end', function() {
ajax_menu_animating = false;
});
/* When an AJAX event starts, record the time.
*/
Y.on('io:start', function(transactionid) {
var now = new Date();
ajax_request_times[transactionid] = now;
});
/* When an AJAX event finishes add it to the log.
*/
Y.on('io:complete', function(transactionid, response) {
/* The AJAX event has finished so record the time.
*/
var finish_time = new Date();
/* Remove the initial message in the log.
*/
Y.all('#ajax-time-list li.no-events').remove();
if (ajax_request_times[transactionid]) {
var start_time = ajax_request_times[transactionid];
/* The time take for the AJAX event, in seconds.
*/
var time_taken = (finish_time - start_time)/1000;
var log_node = Y.Node.create(
'<li>Time: <strong></strong><span></span></li>');
log_node.addClass('transaction-' + transactionid);
log_node.one('strong').set(
'text', time_taken.toFixed(2) + ' seconds');
/* If the AJAX event takes longer than AJAX_OK_TIME
then add a warning.
*/
if (time_taken > AJAX_OK_TIME) {
log_node.one('strong').addClass('warning');
}
log_node.one('span').set(
'text',
'ID: ' + transactionid +
', status: ' + response.status +
' (' + response.statusText + ')');
var oops = response.getResponseHeader('X-Lazr-OopsId');
if (oops) {
var oops_node = Y.Node.create('<a/>');
oops_node.setAttribute(
'href', 'http://pad.lv/' + oops);
oops_node.set('text', oops);
log_node.one('span').append(', OOPS ID: ');
log_node.one('span').append(oops_node);
}
node.prepend(log_node);
/* Highlight the new entry in the log.
*/
Y.lazr.anim.green_flash({
node: '#ajax-time-list li.transaction-'+transactionid
}).run();
/* Signify a new entry has been added to the log.
*/
if (ajax_menu_animating === false) {
flash_menu.run();
ajax_menu_animating = true;
}
}
});
/* Open/close the log.
*/
Y.on('click', function(e) {
e.halt();
Y.one('#ajax-time-list').toggleClass('hidden');
}, '#ajax-time a');
}, '#ajax-time');
});
}
|