| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <!-- | |
| 3 Copyright (c) 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/mappers/thread_grouping.html"> | |
| 9 <link rel="import" href="/perf_insights/mre/function_handle.html"> | |
| 10 <link rel="import" href="/tracing/model/flow_event.html"> | |
| 11 <link rel="import" href="/tracing/model/slice.html"> | |
| 12 <link rel="import" href="/tracing/value/numeric.html"> | |
| 13 <link rel="import" href="/tracing/value/unit.html"> | |
| 14 | |
| 15 <script> | |
| 16 'use strict'; | |
| 17 | |
| 18 tr.exportTo('pi.m', function() { | |
| 19 var DURATION_NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear( | |
| 20 tr.v.Unit.byName.timeDurationInMs, | |
| 21 tr.b.Range.fromExplicitRange(0, 250), 50); | |
| 22 | |
| 23 function taskInfoMapFunction(result, model) { | |
| 24 var canonicalUrl = model.canonicalUrl; | |
| 25 var threadGrouping = new pi.m.ThreadGrouping(); | |
| 26 threadGrouping.autoInitUsingHelpers(model); | |
| 27 addTimeInQueue(result, canonicalUrl, model, threadGrouping); | |
| 28 addTopLevelTasksDuration(result, canonicalUrl, model, threadGrouping); | |
| 29 } | |
| 30 | |
| 31 function eatTrailingDigits(str) { | |
| 32 return str && str.replace(/[\d/]*$/, ''); | |
| 33 } | |
| 34 | |
| 35 function histogramsToDict(dict) { | |
| 36 for (var process in dict) { | |
| 37 for (var thread in dict[process]) { | |
| 38 dict[process][thread] = dict[process][thread].asDict(); | |
| 39 } | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 function addTimeInQueue(result, canonicalUrl, model, threadGrouping) { | |
| 44 var timeInQueue = {}; | |
| 45 model.flowEvents.forEach(function(flowEvent) { | |
| 46 if (!flowEvent.endSlice instanceof tr.model.Slice) | |
| 47 return; | |
| 48 var thread = flowEvent.endSlice && flowEvent.endSlice.parentContainer; | |
| 49 if (!thread) | |
| 50 return; | |
| 51 var process = thread.getProcess(); | |
| 52 if (!process) | |
| 53 return; | |
| 54 var threadName = eatTrailingDigits(thread.name) || 'Unknown'; | |
| 55 var processName = threadGrouping.getGroupNameForThread(thread); | |
| 56 addToHistogram(timeInQueue, processName, threadName, flowEvent.duration, | |
| 57 canonicalUrl); | |
| 58 }); | |
| 59 histogramsToDict(timeInQueue); | |
| 60 result.addPair('time_spent_in_queue', timeInQueue); | |
| 61 } | |
| 62 | |
| 63 function addTopLevelTasksDuration(result, canonicalUrl, model, | |
| 64 threadGrouping) { | |
| 65 var timeInTask = {}; | |
| 66 var cpuTimeInTask = {}; | |
| 67 model.getAllThreads().forEach(function(thread) { | |
| 68 var process = thread.getProcess(); | |
| 69 if (!process) | |
| 70 return; | |
| 71 var threadName = eatTrailingDigits(thread.name) || thread.tid; | |
| 72 var processName = threadGrouping.getGroupNameForThread(thread); | |
| 73 if (!thread.sliceGroup.length) | |
| 74 return; | |
| 75 thread.sliceGroup.slices.forEach(function(slice) { | |
| 76 if (!isTopLevelTask(slice)) | |
| 77 return; | |
| 78 addToHistogram(timeInTask, processName, threadName, slice.duration, | |
| 79 canonicalUrl); | |
| 80 addToHistogram(cpuTimeInTask, processName, threadName, | |
| 81 slice.cpuDuration, canonicalUrl); | |
| 82 }); | |
| 83 }); | |
| 84 histogramsToDict(timeInTask); | |
| 85 result.addPair('time_spent_in_top_level_task', timeInTask); | |
| 86 histogramsToDict(cpuTimeInTask); | |
| 87 result.addPair('cpu_time_spent_in_top_level_task', cpuTimeInTask); | |
| 88 } | |
| 89 | |
| 90 // A slice is top level if it's on the receiving end of a post task and no | |
| 91 // slice above it is. | |
| 92 function isTopLevelTask(slice) { | |
| 93 if (!slice.inFlowEvents.length) | |
| 94 return false; | |
| 95 return !slice.parentSlice || !isTopLevelTask(slice.parentSlice); | |
| 96 } | |
| 97 | |
| 98 function addToHistogram(dict, processName, threadName, value, url) { | |
| 99 dict[processName] = dict[processName] || {}; | |
| 100 dict[processName][threadName] = dict[processName][threadName] || | |
| 101 DURATION_NUMERIC_BUILDER.build(); | |
| 102 dict[processName][threadName].add(value, url); | |
| 103 } | |
| 104 | |
| 105 pi.FunctionRegistry.register(taskInfoMapFunction); | |
| 106 | |
| 107 // Exporting for tests. | |
| 108 return { | |
| 109 taskInfoMapFunctionForTest: taskInfoMapFunction | |
| 110 }; | |
| 111 }); | |
| 112 </script> | |
| OLD | NEW |