drawing_container_perf_test.html revision edfe2194ee8a857cc1e78b4e4020f9b5e7210029
1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/core/test_utils.html"> 9<link rel="import" href="/tracing/ui/extras/full_config.html"> 10<link rel="import" href="/tracing/model/model.html"> 11<link rel="import" href="/tracing/base/xhr.html"> 12 13<script> 14'use strict'; 15 16tr.b.unittest.testSuite(function() { // @suppress longLineCheck 17 var generalModel; 18 function getOrCreateGeneralModel() { 19 if (generalModel !== undefined) 20 generalModel; 21 var fileUrl = '/test_data/thread_time_visualisation.json.gz'; 22 var events = tr.b.getSync(fileUrl); 23 generalModel = tr.c.test_utils.newModelWithEvents([events]); 24 return generalModel; 25 } 26 27 function DCPerfTestCase(testName, opt_options) { 28 tr.b.unittest.PerfTestCase.call(this, testName, undefined, opt_options); 29 this.viewportDiv = undefined; 30 this.drawingContainer = undefined; 31 this.viewport = undefined; 32 } 33 DCPerfTestCase.prototype = { 34 __proto__: tr.b.unittest.PerfTestCase.prototype, 35 36 setUp: function(model) { 37 this.viewportDiv = document.createElement('div'); 38 39 this.viewport = new tr.ui.TimelineViewport(this.viewportDiv); 40 41 this.drawingContainer = new tr.ui.tracks.DrawingContainer(this.viewport); 42 this.viewport.modelTrackContainer = this.drawingContainer; 43 44 var modelTrack = new tr.ui.tracks.ModelTrack(this.viewport); 45 this.drawingContainer.appendChild(modelTrack); 46 47 modelTrack.model = model; 48 49 this.viewportDiv.appendChild(this.drawingContainer); 50 51 this.addHTMLOutput(this.viewportDiv); 52 53 // Size the canvas. 54 this.drawingContainer.updateCanvasSizeIfNeeded_(); 55 56 // Size the viewport. 57 var w = this.drawingContainer.canvas.width; 58 var min = model.bounds.min; 59 var range = model.bounds.range; 60 61 var boost = range * 0.15; 62 var dt = new tr.ui.TimelineDisplayTransform(); 63 dt.xSetWorldBounds(min - boost, min + range + boost, w); 64 this.viewport.setDisplayTransformImmediately(dt); 65 }, 66 67 runOneIteration: function() { 68 this.drawingContainer.draw_(); 69 }, 70 71 tearDown: function() { 72 } 73 }; 74 75 76 function GeneralDCPerfTestCase(testName, opt_options) { 77 DCPerfTestCase.call(this, testName, opt_options); 78 } 79 80 GeneralDCPerfTestCase.prototype = { 81 __proto__: DCPerfTestCase.prototype, 82 83 setUp: function() { 84 var model = getOrCreateGeneralModel(); 85 DCPerfTestCase.prototype.setUp.call(this, model); 86 } 87 }; 88 89 test(new GeneralDCPerfTestCase('draw_softwareCanvas_One', 90 {iterations: 1})); 91 test(new GeneralDCPerfTestCase('draw_softwareCanvas_Ten', 92 {iterations: 10})); 93 test(new GeneralDCPerfTestCase('draw_softwareCanvas_AHundred', 94 {iterations: 100})); 95 96 97 function AsyncDCPerfTestCase(testName, opt_options) { 98 DCPerfTestCase.call(this, testName, opt_options); 99 } 100 101 AsyncDCPerfTestCase.prototype = { 102 __proto__: DCPerfTestCase.prototype, 103 104 setUp: function() { 105 var model = tr.c.test_utils.newModel(function(m) { 106 var proc = m.getOrCreateProcess(1); 107 for (var tid = 1; tid <= 5; tid++) { 108 var thread = proc.getOrCreateThread(tid); 109 for (var i = 0; i < 5000; i++) { 110 var mod = Math.floor(i / 100) % 4; 111 var slice = tr.c.test_utils.newAsyncSliceEx({ 112 name: 'Test' + i, 113 colorId: tid + mod, 114 id: tr.b.GUID.allocate(), 115 start: i * 10, 116 duration: 9, 117 isTopLevel: true 118 }); 119 thread.asyncSliceGroup.push(slice); 120 } 121 } 122 }); 123 DCPerfTestCase.prototype.setUp.call(this, model); 124 125 var w = this.drawingContainer.canvas.width; 126 127 var dt = new tr.ui.TimelineDisplayTransform(); 128 dt.xSetWorldBounds(-2000, 54000, w); 129 this.viewport.setDisplayTransformImmediately(dt); 130 } 131 }; 132 test(new AsyncDCPerfTestCase('draw_asyncSliceHeavy_Twenty', 133 {iterations: 20})); 134}); 135</script> 136 137