| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/tracing/base/units/units.html"> |
| <link rel="import" href="/tracing/base/units/histogram.html"> |
| <link rel="import" href="/perf_insights/function_handle.html"> |
| <link rel="import" href="/perf_insights/value/value.html"> |
| <link rel="import" href="/perf_insights/mappers/slice_cost.html"> |
| <link rel="import" href="/perf_insights/mappers/thread_grouping.html"> |
| <link rel="import" href="/tracing/base/iteration_helpers.html"> |
| <link rel="import" href="/tracing/extras/chrome/chrome_model_helper.html"> |
| <link rel="import" href="/tracing/extras/rail/rail_interaction_record.html"> |
| <link rel="import" href="/tracing/extras/rail/rail_score.html"> |
| <link rel="import" href="/tracing/model/ir_coverage.html"> |
| |
| <script> |
| tr.exportTo('pi.m', function() { |
| |
| function getWeatherReportFromModel(model) { |
| // Organize all RAIL IRs by type and name in a tree. A node of this tree is |
| // a dict with keys |overallScore|, |scores| and optionally |subTypes|. |
| // |overallScore| and |scores| are mutually exclusive. If |overallScore| is |
| // present it contains the overall rail score of all IRs under the tree. If |
| // |scores| is present it contains an array with the IR scores of all the |
| // IRs under the tree. |subTypes| is a map from a subType (IR type, IR name) |
| // to a node. |
| var irTree = { |
| overallScore: 0 |
| }; |
| var allIRs = []; |
| function addIRToNode(node, ir, path) { |
| if (node.overallScore === undefined) { |
| // For a node without overall rail score keep the individual IR scores. |
| node.irScores = node.irScores || []; |
| node.irScores.push(ir.railScore); |
| } |
| if (path.length === 0) |
| return; |
| var subType = path[0]; |
| node.subTypes = node.subTypes || {}; |
| node.subTypes[subType] = node.subTypes[subType] || {}; |
| addIRToNode(node.subTypes[subType], ir, path.slice(1)); |
| } |
| model.interactionRecords.forEach(function(ir) { |
| if (!(ir instanceof tr.e.rail.RAILInteractionRecord)) |
| return; |
| allIRs.push(ir); |
| var path = [ |
| tr.e.rail.userFriendlyRailTypeName(ir.railTypeName), |
| ir.name || 'Unnamed' |
| ]; |
| addIRToNode(irTree, ir, path); |
| }); |
| irTree.overallScore = (new tr.e.rail.RAILScore(allIRs)).overallScore; |
| |
| var railTypeNameByGUID = getRAILTypeNameForEventsByGUID(model, allIRs); |
| var threadGrouping = new pi.m.ThreadGrouping(); |
| threadGrouping.autoInitUsingHelpers(model); |
| |
| var wr = { |
| irTree: irTree, |
| irCoverage: tr.model.getIRCoverageFromModel(model), |
| sliceCosts: pi.m.getSliceCostReport(model, threadGrouping, |
| railTypeNameByGUID) |
| }; |
| return wr; |
| } |
| |
| function getRAILTypeNameForEventsByGUID(model, railIRs) { |
| var railTypeNameByGUID = {}; |
| railIRs.forEach(function applyAssociatedToRTN(ir) { |
| ir.associatedEvents.forEach(function applyEventToRTN(event) { |
| // Unassociated events have already been assigned to a RTN. |
| if (railTypeNameByGUID[event.guid] !== undefined) |
| return; |
| railTypeNameByGUID[event.guid] = tr.e.rail.userFriendlyRailTypeName( |
| ir.railTypeName); |
| }, this); |
| }, this); |
| |
| model.iterateAllEvents(function storeEventToUnassociatedSet(event) { |
| if (railTypeNameByGUID[event.guid] !== undefined) |
| return; |
| railTypeNameByGUID[event.guid] = 'Unknown'; |
| }); |
| return railTypeNameByGUID; |
| } |
| |
| function weatherReportMapFunction(results, runInfo, model) { |
| var wr = pi.m.getWeatherReportFromModel(model); |
| results.addValue(new pi.v.DictValue(runInfo, 'wr', wr)); |
| } |
| pi.FunctionRegistry.register(weatherReportMapFunction); |
| |
| return { |
| getWeatherReportFromModel: getWeatherReportFromModel, |
| weatherReportMapFunction: weatherReportMapFunction |
| }; |
| }); |
| |
| </script> |