blob: 22220505486115df989f1e79dcf075b11fdbcd2c [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2013 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/base.html">
<link rel="import" href="/base/iteration_helpers.html">
<link rel="import" href="/base/statistics.html">
<script>
'use strict';
tr.exportTo('tr.ui.analysis', function() {
function MultiEventSummary(title, events) {
this.title = title;
this.duration_ = undefined;
this.selfTime_ = undefined;
this.events_ = events;
this.cpuTimesComputed_ = false;
this.cpuSelfTime_ = undefined;
this.cpuDuration_ = undefined;
this.maxDuration_ = undefined;
this.maxCpuDuration_ = undefined;
this.maxSelfTime_ = undefined;
this.maxCpuSelfTime_ = undefined;
this.untotallableArgs_ = [];
this.totalledArgs_ = undefined;
};
MultiEventSummary.prototype = {
set title(title) {
if (title == 'Totals')
this.totalsRow = true;
this.title_ = title;
},
get title() {
return this.title_;
},
get duration() {
if (this.duration_ === undefined) {
this.duration_ = tr.b.Statistics.sum(
this.events_, function(event) {
return event.duration;
});
}
return this.duration_;
},
get cpuSelfTime() {
this.computeCpuTimesIfNeeded_();
return this.cpuSelfTime_;
},
get cpuDuration() {
this.computeCpuTimesIfNeeded_();
return this.cpuDuration_;
},
computeCpuTimesIfNeeded_: function() {
if (this.cpuTimesComputed_)
return;
this.cpuTimesComputed_ = true;
var cpuSelfTime = 0;
var cpuDuration = 0;
var hasCpuData = false;
for (var i = 0; i < this.events_.length; i++) {
var event = this.events_[i];
if (event.cpuDuration !== undefined) {
cpuDuration += event.cpuDuration;
hasCpuData = true;
}
if (event.cpuSelfTime !== undefined) {
cpuSelfTime += event.cpuSelfTime;
hasCpuData = true;
}
}
if (hasCpuData) {
this.cpuDuration_ = cpuDuration;
this.cpuSelfTime_ = cpuSelfTime;
}
},
get selfTime() {
if (this.selfTime_ === undefined) {
this.selfTime_ = 0;
for (var i = 0; i < this.events_.length; i++) {
if (this.events_[i].selfTime !== undefined)
this.selfTime_ += this.events[i].selfTime;
}
}
return this.selfTime_;
},
get events() {
return this.events_;
},
get numEvents() {
return this.events_.length;
},
get numAlerts() {
if (this.numAlerts_ === undefined) {
this.numAlerts_ = tr.b.Statistics.sum(this.events_, function(event) {
return event.associatedAlerts.length;
});
}
return this.numAlerts_;
},
get untotallableArgs() {
this.updateArgsIfNeeded_();
return this.untotallableArgs_;
},
get totalledArgs() {
this.updateArgsIfNeeded_();
return this.totalledArgs_;
},
get maxDuration() {
if (this.maxDuration_ === undefined) {
this.maxDuration_ = tr.b.Statistics.max(
this.events_, function(event) {
return event.duration;
});
}
return this.maxDuration_;
},
get maxCpuDuration() {
if (this.maxCpuDuration_ === undefined) {
this.maxCpuDuration_ = tr.b.Statistics.max(
this.events_, function(event) {
return event.cpuDuration;
});
}
return this.maxCpuDuration_;
},
get maxSelfTime() {
if (this.maxSelfTime_ === undefined) {
this.maxSelfTime_ = tr.b.Statistics.max(
this.events_, function(event) {
return event.selfTime;
});
}
return this.maxSelfTime_;
},
get maxCpuSelfTime() {
if (this.maxCpuSelfTime_ === undefined) {
this.maxCpuSelfTime_ = tr.b.Statistics.max(
this.events_, function(event) {
return event.cpuSelfTime;
});
}
return this.maxCpuSelfTime_;
},
updateArgsIfNeeded_: function() {
if (this.totalledArgs_ !== undefined)
return;
var untotallableArgs = {};
var totalledArgs = {};
for (var i = 0; i < this.events_.length; i++) {
var event = this.events_[i];
for (var argName in event.args) {
var argVal = event.args[argName];
var type = typeof argVal;
if (type !== 'number') {
untotallableArgs[argName] = true;
delete totalledArgs[argName];
continue;
}
if (untotallableArgs[argName]) {
continue;
}
if (totalledArgs[argName] === undefined)
totalledArgs[argName] = 0;
totalledArgs[argName] += argVal;
}
}
this.untotallableArgs_ = tr.b.dictionaryKeys(untotallableArgs);
this.totalledArgs_ = totalledArgs;
}
};
return {
MultiEventSummary: MultiEventSummary
};
});
</script>