| <!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="/base/iteration_helpers.html"> |
| <link rel="import" href="/model/event_set.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('tr.model', function() { |
| function getAllAssociatedEvents(irs) { |
| var allAssociatedEvents = new tr.model.EventSet(); |
| irs.forEach(function(ir) { |
| ir.associatedEvents.forEach(function(event) { |
| // FlowEvents don't have parentContainers or cpuDurations, and it's |
| // annoying to highlight them. |
| if (event instanceof tr.model.FlowEvent) |
| return; |
| allAssociatedEvents.push(event); |
| }); |
| }); |
| return allAssociatedEvents; |
| } |
| |
| function getUnassociatedEvents(model, associatedEvents) { |
| var unassociatedEvents = new tr.model.EventSet(); |
| model.getAllProcesses().forEach(function(process) { |
| for (var tid in process.threads) { |
| var thread = process.threads[tid]; |
| thread.sliceGroup.iterateAllEvents(function(event) { |
| // The set of unassociated events contains only events that are not in |
| // the set of associated events. |
| // Only add event to the set of unassociated events if it is not in |
| // the set of associated events. |
| if (!associatedEvents.contains(event)) |
| unassociatedEvents.push(event); |
| }); |
| } |
| }); |
| return unassociatedEvents; |
| } |
| |
| function getTotalCpuDuration(events) { |
| var cpuMs = 0; |
| events.forEach(function(event) { |
| // Add up events' cpu duration if they have any. |
| // Avoid double-counting cpu duration by only counting top-level events. |
| if (event.cpuDuration && event.isTopLevel) |
| cpuMs += event.cpuDuration; |
| }); |
| return cpuMs; |
| } |
| |
| function getIRCoverageFromModel(model) { |
| var associatedEvents = getAllAssociatedEvents(model.interaction_records); |
| |
| if (!associatedEvents.length) |
| return undefined; |
| |
| var unassociatedEvents = getUnassociatedEvents( |
| model, associatedEvents); |
| |
| var associatedCpuMs = getTotalCpuDuration(associatedEvents); |
| var unassociatedCpuMs = getTotalCpuDuration(unassociatedEvents); |
| |
| var totalEventCount = associatedEvents.length + unassociatedEvents.length; |
| var totalCpuMs = associatedCpuMs + unassociatedCpuMs; |
| var coveredCpuRatio = undefined; |
| var uncoveredCpuRatio = undefined; |
| if (totalCpuMs) { |
| coveredCpuRatio = associatedCpuMs / totalCpuMs; |
| uncoveredCpuRatio = 1 - coveredCpuRatio; |
| } |
| |
| return { |
| associatedEvents: associatedEvents, |
| unassociatedEvents: unassociatedEvents, |
| associatedCpuMs: associatedCpuMs, |
| unassociatedCpuMs: unassociatedCpuMs, |
| coveredEventsRatio: associatedEvents.length / totalEventCount, |
| uncoveredEventsRatio: unassociatedEvents.length / totalEventCount, |
| coveredCpuRatio: coveredCpuRatio, |
| uncoveredCpuRatio: uncoveredCpuRatio |
| }; |
| } |
| |
| return { |
| getIRCoverageFromModel: getIRCoverageFromModel |
| }; |
| }); |
| </script> |