1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 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/color_scheme.html"> 8<link rel="import" href="/tracing/base/statistics.html"> 9<link rel="import" href="/tracing/model/event.html"> 10<link rel="import" href="/tracing/model/event_set.html"> 11 12<script> 13'use strict'; 14 15/** 16 * @fileoverview Class describing rendered frames. 17 * 18 * Because a frame is produced by multiple threads, it does not inherit from 19 * TimedEvent, and has no duration. 20 */ 21tr.exportTo('tr.model', function() { 22 var ColorScheme = tr.b.ColorScheme; 23 var Statistics = tr.b.Statistics; 24 25 var FRAME_PERF_CLASS = { 26 GOOD: 'good', 27 BAD: 'bad', 28 TERRIBLE: 'terrible', 29 NEUTRAL: 'generic_work' 30 }; 31 32 /** 33 * @constructor 34 * @param {Array} associatedEvents Selection of events composing the frame. 35 * @param {Array} threadTimeRanges Array of {thread, start, end} 36 * for each thread, describing the critical path of the frame. 37 */ 38 function Frame(associatedEvents, threadTimeRanges, opt_args) { 39 tr.model.Event.call(this); 40 41 this.threadTimeRanges = threadTimeRanges; 42 this.associatedEvents = new tr.model.EventSet(associatedEvents); 43 this.args = opt_args || {}; 44 45 this.title = 'Frame'; 46 this.start = Statistics.min( 47 threadTimeRanges, function(x) { return x.start; }); 48 this.end = Statistics.max( 49 threadTimeRanges, function(x) { return x.end; }); 50 this.totalDuration = Statistics.sum( 51 threadTimeRanges, function(x) { return x.end - x.start; }); 52 53 this.perfClass = FRAME_PERF_CLASS.NEUTRAL; 54 }; 55 56 Frame.prototype = { 57 __proto__: tr.model.Event.prototype, 58 59 set perfClass(perfClass) { 60 this.colorId = ColorScheme.getColorIdForReservedName(perfClass); 61 this.perfClass_ = perfClass; 62 }, 63 64 get perfClass() { 65 return this.perfClass_; 66 }, 67 68 shiftTimestampsForward: function(amount) { 69 this.start += amount; 70 this.end += amount; 71 72 for (var i = 0; i < this.threadTimeRanges.length; i++) { 73 this.threadTimeRanges[i].start += amount; 74 this.threadTimeRanges[i].end += amount; 75 } 76 }, 77 78 addBoundsToRange: function(range) { 79 range.addValue(this.start); 80 range.addValue(this.end); 81 } 82 }; 83 84 tr.model.EventRegistry.register( 85 Frame, 86 { 87 name: 'frame', 88 pluralName: 'frames', 89 singleViewElementName: 'tr-ui-a-single-frame-sub-view', 90 multiViewElementName: 'tr-ui-a-multi-frame-sub-view' 91 }); 92 93 return { 94 Frame: Frame, 95 FRAME_PERF_CLASS: FRAME_PERF_CLASS 96 }; 97}); 98</script> 99