1 var initialize_TimeTracker = function() {
3 InspectorTest.runPerformanceTest = function(perfTest, executeTime, callback)
5 var Timer = function(test, callback)
7 this._callback = callback;
10 this._testStartTime = new Date();
11 this._heapSizeDeltas = [];
12 this._jsHeapSize = this._getJSHeapSize();
18 return {name: name, startTime: new Date()};
21 finish: function(cookie)
23 var endTime = new Date();
24 if (!this._times[cookie.name])
25 this._times[cookie.name] = [];
26 this._times[cookie.name].push(endTime - cookie.startTime);
29 _getJSHeapSize: function()
33 return console.memory.usedJSHeapSize;
38 var newJSHeapSize = this._getJSHeapSize();
39 this._heapSizeDeltas.push(newJSHeapSize - this._jsHeapSize);
40 this._jsHeapSize = newJSHeapSize;
42 var time = new Date();
43 if (time - this._testStartTime < executeTime)
48 this._complete = true;
54 InspectorTest.completeTest();
61 setTimeout(this._runTest.bind(this), 0);
66 var safeTest = InspectorTest.safeWrap(this._test);
73 for (var testName in this._times)
74 InspectorTest.dumpTestStats(testName, this._times[testName]);
76 var url = WebInspector.inspectedPageURL;
77 var regExp = /([^\/]+)\.html/;
78 var matches = regExp.exec(url);
79 InspectorTest.dumpTestStats("heap-delta-kb-" + matches[1], this._heapSizeDeltas, 1024);
84 InspectorTest.timer = new Timer(perfTest, callback);
85 InspectorTest.timer._runTest();
88 InspectorTest.mark = function(markerName)
90 var timer = InspectorTest.timer;
94 if (InspectorTest.lastMarkCookie)
95 timer.finish(InspectorTest.lastMarkCookie);
97 InspectorTest.lastMarkCookie = markerName ? timer.start(markerName) : null;
100 InspectorTest.dumpTestStats = function(testName, samples, divider)
102 divider = divider || 1;
103 var stripNResults = Math.floor(samples.length / 10);
104 samples.sort(function(a, b) { return a - b; });
106 for (var i = stripNResults; i < samples.length - stripNResults; ++i)
108 InspectorTest.addResult("* " + testName + ": " + Math.floor(sum / (samples.length - stripNResults * 2) / divider));
109 InspectorTest.addResult(testName + " min/max/count: " + Math.floor(samples[0] / divider) + "/" + Math.floor(samples[samples.length-1] / divider) + "/" + samples.length);
112 InspectorTest.addBackendResponseSniffer = function(object, methodName, override, opt_sticky)
114 var originalMethod = InspectorTest.override(object, methodName, backendCall, opt_sticky);
115 function backendCall()
117 var args = Array.prototype.slice.call(arguments);
118 var callback = (args.length && typeof args[args.length - 1] === "function") ? args.pop() : 0;
119 args.push(function() {
120 callback.apply(null, arguments);
121 override.apply(null, arguments);
123 originalMethod.apply(object, args);