| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <!-- | |
| 3 Copyright 2015 The Chromium Authors. All rights reserved. | |
| 4 Use of this source code is governed by a BSD-style license that can be | |
| 5 found in the LICENSE file. | |
| 6 --> | |
| 7 | |
| 8 <link rel="import" href="/perf_insights/mre/function_handle.html"> | |
| 9 <link rel="import" href="/tracing/model/helpers/chrome_browser_helper.html"> | |
| 10 <link rel="import" href="/tracing/model/helpers/chrome_model_helper.html"> | |
| 11 | |
| 12 <script> | |
| 13 'use strict'; | |
| 14 | |
| 15 tr.exportTo('pie', function() { | |
| 16 function eventCost(event) { | |
| 17 if (event.cpuDuration !== undefined) | |
| 18 return event.cpuDuration; | |
| 19 return event.duration; | |
| 20 } | |
| 21 | |
| 22 // Computes the thread time spent in BeginMainFrame during the loading phase | |
| 23 // as a ratio of the overall main thread utilization during that time. | |
| 24 // See https://goo.gl/l7V5xg. | |
| 25 function mapRenderingCost(result, model) { | |
| 26 var modelHelper = model.getOrCreateHelper( | |
| 27 tr.model.helpers.ChromeModelHelper); | |
| 28 var browserHelper = modelHelper.browserHelper; | |
| 29 var rendererHelpers = modelHelper.rendererHelpers; | |
| 30 | |
| 31 if (!browserHelper || !rendererHelpers) { | |
| 32 // If we couldn't find both a browser and a renderer process, bail out. | |
| 33 result.addPair('renderingCost', null); | |
| 34 return; | |
| 35 } | |
| 36 | |
| 37 var loadingEvents = browserHelper.getLoadingEventsInRange(model.bounds); | |
| 38 var loadingDurations = new Array(loadingEvents.length); | |
| 39 var loadingTotalCost = new Array(loadingEvents.length); | |
| 40 var loadingBeginMainFrameCost = new Array(loadingEvents.length); | |
| 41 var loadingBeginMainFrameRelativeCost = new Array(loadingEvents.length); | |
| 42 var beginMainFrameCount = 0; | |
| 43 loadingEvents.forEach(function(loadingEvent, index) { | |
| 44 loadingDurations[index] = loadingEvent.duration; | |
| 45 | |
| 46 var totalCost = 0; | |
| 47 var beginMainFrameCost = 0; | |
| 48 for (var pid in rendererHelpers) { | |
| 49 var rendererHelper = rendererHelpers[pid]; | |
| 50 var mainThread = rendererHelper.mainThread; | |
| 51 mainThread.iterateAllEvents(function(event) { | |
| 52 // Look for tasks executed by the scheduler. Note that this only | |
| 53 // includes slices that are *completely* inside the loading phase. | |
| 54 if (event.title !== 'TaskQueueManager::RunTask' || | |
| 55 event.start < loadingEvent.start || | |
| 56 event.start + event.duration > | |
| 57 loadingEvent.start + loadingEvent.duration) { | |
| 58 return; | |
| 59 } | |
| 60 totalCost += eventCost(event); | |
| 61 | |
| 62 var beginMainFrame = | |
| 63 event.findDescendentSlice('ThreadProxy::BeginMainFrame'); | |
| 64 if (beginMainFrame) { | |
| 65 beginMainFrameCount++; | |
| 66 beginMainFrameCost += eventCost(beginMainFrame); | |
| 67 } | |
| 68 }); | |
| 69 } | |
| 70 | |
| 71 loadingTotalCost[index] = totalCost; | |
| 72 loadingBeginMainFrameCost[index] = beginMainFrameCost; | |
| 73 loadingBeginMainFrameRelativeCost[index] = beginMainFrameCost / totalCost; | |
| 74 }); | |
| 75 | |
| 76 if (loadingDurations.length === 0) { | |
| 77 result.addValue('renderingCost', null); | |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 result.addPair('renderingCost', { | |
| 82 loadingDuration: loadingDurations, | |
| 83 loadingTotalCost: loadingTotalCost, | |
| 84 loadingBeginMainFrameCost: loadingBeginMainFrameCost, | |
| 85 loadingBeginMainFrameRelativeCost: loadingBeginMainFrameRelativeCost, | |
| 86 beginMainFramesPerLoad: beginMainFrameCount / loadingDurations.length | |
| 87 }); | |
| 88 } | |
| 89 | |
| 90 pi.FunctionRegistry.register(mapRenderingCost); | |
| 91 | |
| 92 return { | |
| 93 mapRenderingCostForTest: mapRenderingCost | |
| 94 }; | |
| 95 }); | |
| 96 </script> | |
| OLD | NEW |