blob: 80cdd387a3cb5d1af1f5d26ab63b70496c1f6b75 [file] [log] [blame]
<!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/iteration_helpers.html">
<link rel="import" href="/tracing/model/event_set.html">
<script>
'use strict';
tr.exportTo('tr.model', function() {
function getAssociatedEvents(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();
// 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.
for (var proc of model.getAllProcesses())
for (var thread of tr.b.dictionaryValues(proc.threads))
for (var event of thread.sliceGroup.getDescendantEvents())
if (!associatedEvents.contains(event))
unassociatedEvents.push(event);
return unassociatedEvents;
}
function getTotalCpuDuration(events) {
var cpuMs = 0;
events.forEach(function(event) {
// Add up events' cpu self time if they have any.
if (event.cpuSelfTime)
cpuMs += event.cpuSelfTime;
});
return cpuMs;
}
function getIRCoverageFromModel(model) {
var associatedEvents = getAssociatedEvents(model.userModel.expectations);
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 coveredEventsCpuTimeRatio = undefined;
if (totalCpuMs !== 0)
coveredEventsCpuTimeRatio = associatedCpuMs / totalCpuMs;
return {
associatedEventsCount: associatedEvents.length,
unassociatedEventsCount: unassociatedEvents.length,
associatedEventsCpuTimeMs: associatedCpuMs,
unassociatedEventsCpuTimeMs: unassociatedCpuMs,
coveredEventsCountRatio: associatedEvents.length / totalEventCount,
coveredEventsCpuTimeRatio: coveredEventsCpuTimeRatio
};
}
return {
getIRCoverageFromModel: getIRCoverageFromModel,
getAssociatedEvents: getAssociatedEvents,
getUnassociatedEvents: getUnassociatedEvents
};
});
</script>