1 var initialize_TimeTracker = function() {
3 InspectorTest.runPerformanceTest = function(perfTest, executeTime, callback)
5 var Timer = function(test, callback)
7 this._callback = callback;
11 this._testStartTime = new Date();
12 this._heapSizeDeltas = [];
13 this._jsHeapSize = this._getJSHeapSize();
19 return {name: name, startTime: new Date()};
22 finish: function(cookie)
24 var endTime = new Date();
25 if (!this._times[cookie.name])
26 this._times[cookie.name] = [];
27 this._times[cookie.name].push(endTime - cookie.startTime);
30 reportSize: function(name, size)
32 if (!this._sizes[name])
33 this._sizes[name] = [];
34 this._sizes[name].push(size);
37 _getJSHeapSize: function()
43 return console.memory.usedJSHeapSize;
46 done: function(groupName)
48 var newJSHeapSize = this._getJSHeapSize();
49 this._heapSizeDeltas.push(newJSHeapSize - this._jsHeapSize);
50 this._jsHeapSize = newJSHeapSize;
52 var time = new Date();
53 if (time - this._testStartTime < executeTime)
58 this._complete = true;
60 this._dump(groupName);
64 InspectorTest.completeTest();
71 setTimeout(this._runTest.bind(this), 0);
76 var safeTest = InspectorTest.safeWrap(this._test);
81 _dump: function(groupName)
83 for (var testName in this._times)
84 InspectorTest.dumpTestStats(groupName, testName, this._times[testName], "ms");
86 for (var testName in this._sizes)
87 InspectorTest.dumpTestStats(groupName, testName, this._sizes[testName], "kB", 1024);
89 var url = WebInspector.inspectedPageURL;
90 var regExp = /([^\/]+)\.html/;
91 var matches = regExp.exec(url);
92 InspectorTest.dumpTestStats("heap-delta", matches[1], this._heapSizeDeltas, "kB", 1024);
96 InspectorTest.timer = new Timer(perfTest, callback);
97 InspectorTest.timer._runTest();
100 InspectorTest.measureFunction = function(object, functionName)
103 var timer = InspectorTest.timer;
106 cookie = timer.start(functionName);
107 var result = func.apply(this, arguments);
110 timer.finish(cookie);
113 var func = object[functionName];
114 object[functionName] = measure;
117 InspectorTest.mark = function(markerName)
119 var timer = InspectorTest.timer;
123 if (InspectorTest.lastMarkCookie)
124 timer.finish(InspectorTest.lastMarkCookie);
126 InspectorTest.lastMarkCookie = markerName ? timer.start(markerName) : null;
129 InspectorTest.dumpTestStats = function(groupName, testName, samples, units, divider)
131 divider = divider || 1;
132 var stripNResults = Math.floor(samples.length / 10);
133 samples.sort(function(a, b) { return a - b; });
135 for (var i = stripNResults; i < samples.length - stripNResults; ++i)
137 InspectorTest.addResult("RESULT " + groupName + ': ' + testName + "= " + Math.floor(sum / (samples.length - stripNResults * 2) / divider) + " " + units);
140 InspectorTest.addBackendResponseSniffer = function(object, methodName, override, opt_sticky)
142 var originalMethod = InspectorTest.override(object, methodName, backendCall, opt_sticky);
143 function backendCall()
145 var args = Array.prototype.slice.call(arguments);
146 var callback = (args.length && typeof args[args.length - 1] === "function") ? args.pop() : 0;
147 args.push(function() {
148 callback.apply(null, arguments);
149 override.apply(null, arguments);
151 originalMethod.apply(object, args);