From 0ab287e7072686b121c164242f287c19b32981ae Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 28 Mar 2012 13:59:39 +0100 Subject: [PATCH] modified JSONP statistics, rearranged OSRM debug so that it works in IE --- WebContent/OSRM.JSONP.js | 15 +++++++++------ WebContent/OSRM.debug.js | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/WebContent/OSRM.JSONP.js b/WebContent/OSRM.JSONP.js index 430fc8beb..1c9bcc8ff 100644 --- a/WebContent/OSRM.JSONP.js +++ b/WebContent/OSRM.JSONP.js @@ -26,7 +26,6 @@ OSRM.JSONP = { callbacks: {}, timeouts: {}, timers: {}, - durations: {}, // default callback routines @@ -51,7 +50,7 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } - OSRM.debug.log("[jsonp] timout handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); +// OSRM.debug.log("[jsonp] timout handling: "+id); }; // wrap callback function @@ -67,7 +66,8 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } - OSRM.debug.log("[jsonp] response handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); + OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] ); + OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) ); }; // clean DOM (unfortunately, script elements cannot be reused by all browsers) @@ -84,8 +84,12 @@ OSRM.JSONP = { // start timeout timer OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout); - OSRM.JSONP.durations[id] = new Date(); - + + // statistics + if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; } + if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;} + OSRM.JSONP.durations[id] = new Date(); + // OSRM.debug.log("[jsonp] init: "+id); return true; }, @@ -96,6 +100,5 @@ OSRM.JSONP = { OSRM.JSONP.callbacks = {}; OSRM.JSONP.timeouts = {}; OSRM.JSONP.timers = {}; - OSRM.JSONP.durations = {}; } }; \ No newline at end of file diff --git a/WebContent/OSRM.debug.js b/WebContent/OSRM.debug.js index 3ef9465a3..6da0d2691 100644 --- a/WebContent/OSRM.debug.js +++ b/WebContent/OSRM.debug.js @@ -21,6 +21,16 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.debug = {}; +//working functions +OSRM.debug.log = function(text) { + OSRM.debug.content.innerHTML += text + "
"; + OSRM.debug.content.scrollTop = OSRM.debug.content.scrollHeight; +}; +OSRM.debug.clear = function() { + OSRM.debug.content.innerHTML = ""; +}; + + // add elements to DOM OSRM.debug.init = function() { //create DOM objects for debug output @@ -53,14 +63,4 @@ OSRM.debug.init = function() { if(document.addEventListener) // FF, CH document.addEventListener("DOMContentLoaded", OSRM.debug.init, false); else // IE - OSRM.debug.init(); - - -// working functions -OSRM.debug.log = function(text) { - OSRM.debug.content.innerHTML += text + "
"; - OSRM.debug.content.scrollTop = OSRM.debug.content.scrollHeight; -}; -OSRM.debug.clear = function() { - OSRM.debug.content.innerHTML = ""; -}; + OSRM.debug.init(); \ No newline at end of file