1<!DOCTYPE html> 2<!-- 3Copyright (c) 2014 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<link rel="import" href="/tracing/base/base.html"> 8 9<script> 10'use strict'; 11 12/** 13 * @fileoverview Utilities for accessing trace data about the Chrome browser. 14 */ 15tr.exportTo('tr.model.helpers', function() { 16 var MAIN_FRAMETIME_TYPE = 'main_frametime_type'; 17 var IMPL_FRAMETIME_TYPE = 'impl_frametime_type'; 18 19 var MAIN_RENDERING_STATS = 20 'BenchmarkInstrumentation::MainThreadRenderingStats'; 21 var IMPL_RENDERING_STATS = 22 'BenchmarkInstrumentation::ImplThreadRenderingStats'; 23 24 25 function getSlicesIntersectingRange(rangeOfInterest, slices) { 26 var slicesInFilterRange = []; 27 for (var i = 0; i < slices.length; i++) { 28 var slice = slices[i]; 29 if (rangeOfInterest.intersectsExplicitRangeInclusive( 30 slice.start, slice.end)) 31 slicesInFilterRange.push(slice); 32 } 33 return slicesInFilterRange; 34 } 35 36 37 function ChromeProcessHelper(modelHelper, process) { 38 this.modelHelper = modelHelper; 39 this.process = process; 40 } 41 42 ChromeProcessHelper.prototype = { 43 get pid() { 44 return this.process.pid; 45 }, 46 47 getFrameEventsInRange: function(frametimeType, range) { 48 var titleToGet; 49 if (frametimeType == MAIN_FRAMETIME_TYPE) 50 titleToGet = MAIN_RENDERING_STATS; 51 else 52 titleToGet = IMPL_RENDERING_STATS; 53 54 var frameEvents = []; 55 this.process.iterateAllEvents(function(event) { 56 if (event.title !== titleToGet) 57 return; 58 if (range.intersectsExplicitRangeInclusive(event.start, event.end)) 59 frameEvents.push(event); 60 }); 61 62 frameEvents.sort(function(a, b) {return a.start - b.start}); 63 return frameEvents; 64 } 65 }; 66 67 function getFrametimeDataFromEvents(frameEvents) { 68 var frametimeData = []; 69 for (var i = 1; i < frameEvents.length; i++) { 70 var diff = frameEvents[i].start - frameEvents[i - 1].start; 71 frametimeData.push({ 72 'x': frameEvents[i].start, 73 'frametime': diff 74 }); 75 } 76 return frametimeData; 77 } 78 79 return { 80 ChromeProcessHelper: ChromeProcessHelper, 81 82 MAIN_FRAMETIME_TYPE: MAIN_FRAMETIME_TYPE, 83 IMPL_FRAMETIME_TYPE: IMPL_FRAMETIME_TYPE, 84 MAIN_RENDERING_STATS: MAIN_RENDERING_STATS, 85 IMPL_RENDERING_STATS: IMPL_RENDERING_STATS, 86 87 getSlicesIntersectingRange: getSlicesIntersectingRange, 88 getFrametimeDataFromEvents: getFrametimeDataFromEvents 89 }; 90}); 91</script> 92