2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 WebInspector.RenderingFrameTimelineRecord = class RenderingFrameTimelineRecord extends WebInspector.TimelineRecord
28 constructor(startTime, endTime)
30 super(WebInspector.TimelineRecord.Type.RenderingFrame, startTime, endTime);
32 this._durationByTaskType = new Map;
33 this._frameIndex = WebInspector.RenderingFrameTimelineRecord._nextFrameIndex++;
38 static resetFrameIndex()
40 WebInspector.RenderingFrameTimelineRecord._nextFrameIndex = 0;
43 static displayNameForTaskType(taskType)
46 case WebInspector.RenderingFrameTimelineRecord.TaskType.Script:
47 return WebInspector.UIString("Script");
48 case WebInspector.RenderingFrameTimelineRecord.TaskType.Layout:
49 return WebInspector.UIString("Layout");
50 case WebInspector.RenderingFrameTimelineRecord.TaskType.Paint:
51 return WebInspector.UIString("Paint");
52 case WebInspector.RenderingFrameTimelineRecord.TaskType.Other:
53 return WebInspector.UIString("Other");
57 static taskTypeForTimelineRecord(record)
60 case WebInspector.TimelineRecord.Type.Script:
61 return WebInspector.RenderingFrameTimelineRecord.TaskType.Script;
62 case WebInspector.TimelineRecord.Type.Layout:
63 if (record.eventType === WebInspector.LayoutTimelineRecord.EventType.Paint || record.eventType === WebInspector.LayoutTimelineRecord.EventType.Composite)
64 return WebInspector.RenderingFrameTimelineRecord.TaskType.Paint;
65 return WebInspector.RenderingFrameTimelineRecord.TaskType.Layout;
67 console.error("Unsupported timeline record type: " + record.type);
76 return this._frameIndex;
81 return this._frameIndex + 1;
84 durationForTask(taskType)
86 if (this._durationByTaskType.has(taskType))
87 return this._durationByTaskType.get(taskType);
90 if (taskType === WebInspector.RenderingFrameTimelineRecord.TaskType.Other)
91 duration = this._calculateDurationRemainder();
93 duration = this.children.reduce(function(previousValue, currentValue) {
94 if (taskType !== WebInspector.RenderingFrameTimelineRecord.taskTypeForTimelineRecord(currentValue))
97 var currentDuration = currentValue.duration;
98 if (currentValue.usesActiveStartTime)
99 currentDuration -= currentValue.inactiveDuration;
100 return previousValue + currentDuration;
103 if (taskType === WebInspector.RenderingFrameTimelineRecord.TaskType.Script) {
104 // Layout events synchronously triggered from JavaScript must be subtracted from the total
105 // script time, to prevent the time from being counted twice.
106 duration -= this.children.reduce(function(previousValue, currentValue) {
107 if (currentValue.type === WebInspector.TimelineRecord.Type.Layout && (currentValue.sourceCodeLocation || currentValue.callFrames))
108 return previousValue + currentValue.duration;
109 return previousValue;
114 this._durationByTaskType.set(taskType, duration);
120 _calculateDurationRemainder()
122 return Object.keys(WebInspector.RenderingFrameTimelineRecord.TaskType).reduce(function(previousValue, key) {
123 var taskType = WebInspector.RenderingFrameTimelineRecord.TaskType[key];
124 if (taskType === WebInspector.RenderingFrameTimelineRecord.TaskType.Other)
125 return previousValue;
126 return previousValue - this.durationForTask(taskType);
127 }.bind(this), this.duration);
131 WebInspector.RenderingFrameTimelineRecord.TaskType = {
132 Script: "rendering-frame-timeline-record-script",
133 Layout: "rendering-frame-timeline-record-layout",
134 Paint: "rendering-frame-timeline-record-paint",
135 Other: "rendering-frame-timeline-record-other"
138 WebInspector.RenderingFrameTimelineRecord.TypeIdentifier = "rendering-frame-timeline-record";
140 WebInspector.RenderingFrameTimelineRecord._nextFrameIndex = 0;