Bug 1125398 - Give each test load its own parameters, r=terrence
authorSteve Fink <sfink@mozilla.com>
Mon, 26 Jan 2015 12:53:03 -0800
changeset 239483 b8257c0c97adeb4305c6e762dd741ebae9a124f3
parent 239482 90623a5d6c0cedbeaca6fcaef7fc7f560380c685
child 239484 abe775af80737a557ce1a23ed13e0c439bacc3d1
push id500
push userjoshua.m.grant@gmail.com
push dateThu, 29 Jan 2015 01:48:36 +0000
reviewersterrence
bugs1125398
milestone38.0a1
Bug 1125398 - Give each test load its own parameters, r=terrence
js/src/devtools/gc-ubench/harness.js
js/src/devtools/gc-ubench/index.html
--- a/js/src/devtools/gc-ubench/harness.js
+++ b/js/src/devtools/gc-ubench/harness.js
@@ -7,24 +7,26 @@ var gHistogram = new Map(); // {ms: coun
 
 // Draw state.
 var stopped = 0;
 var start;
 var prev;
 var ctx;
 
 // Current test state.
-var garbagePerFrame = undefined;
-var garbageTotal = undefined;
 var activeTest = undefined;
 var testDuration = undefined; // ms
 var testState = 'idle';  // One of 'idle' or 'running'.
 var testStart = undefined; // ms
 var testQueue = [];
 
+// Global defaults
+var globalDefaultGarbageTotal = "8M";
+var globalDefaultGarbagePerFrame = "8K";
+
 function xpos(index)
 {
     return index * 2;
 }
 
 function ypos(delay)
 {
     var r = 525 - Math.log(delay) * 64;
@@ -82,17 +84,17 @@ function drawGraph()
             worst = delays[i];
             worstpos = i;
         }
     }
     ctx.stroke();
 
     ctx.fillStyle = 'rgb(255,0,0)';
     if (worst)
-        ctx.fillText(''+worst+'ms', xpos(worstpos) - 10, ypos(worst) - 14);
+        ctx.fillText(''+worst.toFixed(2)+'ms', xpos(worstpos) - 10, ypos(worst) - 14);
 
     ctx.beginPath();
     var where = sampleIndex % numSamples;
     ctx.arc(xpos(where), ypos(delays[where]), 5, 0, Math.PI*2, true);
     ctx.fill();
     ctx.fillStyle = 'rgb(0,0,0)';
 
     ctx.fillText('Time', 550, 420);
@@ -119,17 +121,20 @@ function stopstart()
 function handler(timestamp)
 {
     if (stopped)
         return;
 
     if (testState === 'running' && (timestamp - testStart) > testDuration)
         end_test(timestamp);
 
-    activeTest.makeGarbage(garbagePerFrame);
+    if (testState == 'running')
+        document.getElementById("test-progress").textContent = ((testDuration - (timestamp - testStart))/1000).toFixed(1) + " sec";
+
+    activeTest.makeGarbage(activeTest.garbagePerFrame);
 
     var elt = document.getElementById('data');
     var delay = timestamp - prev;
     prev = timestamp;
 
     // Take the histogram at 10us intervals so that we have enough resolution to capture.
     // a 16.66[666] target with adequate accuracy.
     update_histogram(gHistogram, Math.round(delay * 100));
@@ -182,18 +187,17 @@ function onload()
         var option = document.createElement("option");
         option.id = name;
         option.text = name;
         option.title = test.description;
         select.add(option);
     }
 
     // Load the initial test.
-    activeTest = tests.get('noAllocation');
-    activeTest.load(garbageTotal);
+    change_active_test('noAllocation');
 
     // Polyfill rAF.
     var requestAnimationFrame =
         window.requestAnimationFrame || window.mozRequestAnimationFrame ||
         window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
     window.requestAnimationFrame = requestAnimationFrame;
 
     // Acquire our canvas.
@@ -220,44 +224,51 @@ function start_test_cycle(tests_to_run)
     // Convert from an iterable to an array for pop.
     testQueue = [];
     for (var key of tests_to_run)
         testQueue.push(key);
     testState = 'running';
     testStart = performance.now();
     gHistogram.clear();
 
-    change_active_test(testQueue.pop());
-    console.log(`Running test: ${activeTest.name}`);
+    start_test(testQueue.shift());
     reset_draw_state();
 }
 
+function start_test(testName)
+{
+    change_active_test(testName);
+    console.log(`Running test: ${testName}`);
+    document.getElementById("test-selection").value = testName;
+}
+
 function end_test(timestamp)
 {
+    document.getElementById("test-progress").textContent = "(not running)";
     report_test_result(activeTest, gHistogram);
     gHistogram.clear();
     console.log(`Ending test ${activeTest.name}`);
     if (testQueue.length) {
-        change_active_test(testQueue.pop());
-        console.log(`Running test: ${activeTest.name}`);
+        start_test(testQueue.shift());
         testStart = timestamp;
     } else {
         testState = 'idle';
         testStart = 0;
     }
     reset_draw_state();
 }
 
 function report_test_result(test, histogram)
 {
     var resultList = document.getElementById('results-display');
     var resultElem = document.createElement("div");
     var score = compute_test_score(histogram);
     var sparks = compute_test_spark_histogram(histogram);
-    resultElem.innerHTML = `${score} ms/s : ${sparks} : ${test.name} - ${test.description}`;
+    var params = `(${format_units(test.garbagePerFrame)},${format_units(test.garbageTotal)})`;
+    resultElem.innerHTML = `${score.toFixed(3)} ms/s : ${sparks} : ${test.name}${params} - ${test.description}`;
     resultList.appendChild(resultElem);
 }
 
 // Compute a score based on the total ms we missed frames by per second.
 function compute_test_score(histogram)
 {
     var score = 0;
     for (var [delay, count] of histogram) {
@@ -306,34 +317,44 @@ function compute_test_spark_histogram(hi
         line += `<span style="color:${colors[i]}">${spark}</span>`;
     }
     return line;
 }
 
 function reload_active_test()
 {
     activeTest.unload();
-    activeTest.load(garbageTotal);
+    activeTest.load(activeTest.garbageTotal);
 }
 
 function change_active_test(new_test_name)
 {
-    activeTest.unload();
+    if (activeTest)
+        activeTest.unload();
     activeTest = tests.get(new_test_name);
-    activeTest.load(garbageTotal);
+
+    if (!activeTest.garbagePerFrame)
+        activeTest.garbagePerFrame = activeTest.defaultGarbagePerFrame || globalDefaultGarbagePerFrame;
+    if (!activeTest.garbageTotal)
+        activeTest.garbageTotal = activeTest.defaultGarbageTotal || globalDefaultGarbageTotal;
+
+    document.getElementById("garbage-per-frame").value = format_units(activeTest.garbagePerFrame);
+    document.getElementById("garbage-total").value = format_units(activeTest.garbageTotal);
+
+    activeTest.load(activeTest.garbageTotal);
 }
 
 function duration_changed()
 {
     var durationInput = document.getElementById('test-duration');
     testDuration = parseInt(durationInput.value) * 1000;
     console.log(`Updated test duration to: ${testDuration / 1000} seconds`);
 }
 
-function testchanged()
+function test_changed()
 {
     var select = document.getElementById("test-selection");
     console.log(`Switching to test: ${select.value}`);
     change_active_test(select.value);
     gHistogram.clear();
     reset_draw_state();
 }
 
@@ -349,29 +370,45 @@ function parse_units(v)
         return units * 1e3;
     if (lastChar == "m")
         return units * 1e6;
     if (lastChar == "g")
         return units * 1e9;
     return NaN;
 }
 
+function format_units(n)
+{
+    n = String(n);
+    if (n.length > 9 && n.substr(-9) == "000000000")
+        return n.substr(0, n.length - 9) + "G";
+    else if (n.length > 9 && n.substr(-6) == "000000")
+        return n.substr(0, n.length - 6) + "M";
+    else if (n.length > 3 && n.substr(-3) == "000")
+        return n.substr(0, n.length - 3) + "K";
+    else
+        return String(n);
+}
+
 function garbage_total_changed()
 {
     var value = parse_units(document.getElementById('garbage-total').value);
     if (isNaN(value))
         return;
-    garbageTotal = value;
-    console.log(`Updated garbage-total to ${garbageTotal} items`);
-    if (activeTest)
+    if (activeTest) {
+        activeTest.garbageTotal = value;
+        console.log(`Updated garbage-total to ${activeTest.garbageTotal} items`);
         reload_active_test();
+    }
     gHistogram.clear();
     reset_draw_state();
 }
 
 function garbage_per_frame_changed()
 {
     var value = parse_units(document.getElementById('garbage-per-frame').value);
     if (isNaN(value))
         return;
-    garbagePerFrame = value;
-    console.log(`Updated garbage-per-frame to ${garbagePerFrame} items`);
+    if (activeTest) {
+        activeTest.garbagePerFrame = value;
+        console.log(`Updated garbage-per-frame to ${activeTest.garbagePerFrame} items`);
+    }
 }
--- a/js/src/devtools/gc-ubench/index.html
+++ b/js/src/devtools/gc-ubench/index.html
@@ -20,35 +20,39 @@
 
 <canvas id="graph" width="1080" height="550" style="padding-left:10px"></canvas>
 
 <div>
     <input type="button" id="stop" value="Pause" onclick="stopstart()"></input>
 </div>
 
 <div>
-    Duration: <input type="text" id="test-duration" size=3 value="8" oninput="duration_changed()"></input>s
+    Duration: <input type="text" id="test-duration" size="3" value="8" onchange="duration_changed()"></input>s
     <input type="button" id="test-one" value="Run Test" onclick="run_one_test()"></input>
     <input type="button" id="test-all" value="Run All Tests" onclick="run_all_tests()"></input>
 </div>
 
 <div>
-    Currently running test:
-    <select id="test-selection" required onchange="testchanged()"></select>
+    Currently running test load:
+    <select id="test-selection" required onchange="test_changed()"></select>
 </div>
 
 <div>
-    Garbage items per frame:
-    <input type="text" id="garbage-per-frame" size=5 value="8K"
-           oninput="garbage_per_frame_changed()"></input>
+    &nbsp;&nbsp;&nbsp;&nbsp;Time remaining: <span id="test-progress">(not running)</span>
+</div
+
+<div>
+    &nbsp;&nbsp;&nbsp;&nbsp;Garbage items per frame:
+    <input type="text" id="garbage-per-frame" size="5" value="8K"
+           onchange="garbage_per_frame_changed()"></input>
 </div>
 <div>
-    Garbage heap size in items:
-    <input type="text" id="garbage-total" size=5 value="8M"
-           oninput="garbage_total_changed()"></input>
+    &nbsp;&nbsp;&nbsp;&nbsp;Garbage heap size in items:
+    <input type="text" id="garbage-total" size="5" value="8M"
+           onchange="garbage_total_changed()"></input>
 </div>
 
 <div id="results-Area">
     Test Results:
     <div id="results-display" style="padding-left: 10px; border: 1px solid black;"></div>
 </div>
 
 </body>