Bug 1272768 - Use mozsystemmonitor for writing JSON; r=chmanchester

We currently have our own system monitor serialization in
building.py. It predates as_dict() from mozsystemmonitor. Let's
use the "upstream" data format so we only have a single format
to consume.

This change required updating the in-tree resource viewer to
be compatible with the new data format.

This commit stops short of getting rid of the existing
data massaging code in building.py. Another day perhaps.

MozReview-Commit-ID: 1OJrSiyJjMX

--HG--
extra : rebase_source : 9782b2164d1735ed0872fe8c1637204d5b3b1313
This commit is contained in:
Gregory Szorc 2016-05-17 13:49:42 -07:00
Родитель 6972973d70
Коммит bb011ff361
3 изменённых файлов: 22 добавлений и 22 удалений

Просмотреть файл

@ -261,7 +261,7 @@ class BuildMonitor(MozbuildObject):
self.log_resource_usage(usage)
with open(self._get_state_filename('build_resources.json'), 'w') as fh:
json.dump(usage, fh, indent=2)
json.dump(self.resources.as_dict(), fh, indent=2)
except Exception as e:
self.log(logging.WARNING, 'build_resources_error',
{'msg': str(e)},

Просмотреть файл

@ -67,10 +67,10 @@ function BuildResources(data) {
var virt_fields = data.virt_fields;
var swap_fields = data.swap_fields;
function convert(dest, source, key, fields) {
function convert(dest, source, sourceKey, destKey, fields) {
var i = 0;
fields.forEach(function (field) {
dest[key][field] = source[key][i];
dest[destKey][field] = source[sourceKey][i];
i++;
});
}
@ -85,16 +85,16 @@ function BuildResources(data) {
this.ioTotal = {};
var i = 0;
io_fields.forEach(function (field) {
this.ioTotal[field] = data.io[i];
this.ioTotal[field] = data.overall.io[i];
i++;
}.bind(this));
data.resources.forEach(function (sample) {
data.samples.forEach(function (sample) {
var entry = {
start: sample.start - offset,
end: sample.end - offset,
duration: sample.duration,
cpu_percent: sample.cpu_percent,
cpu_percent: sample.cpu_percent_mean,
cpu_times: {},
cpu_times_percents: {},
io: {},
@ -102,10 +102,10 @@ function BuildResources(data) {
swap: {},
};
convert(entry, sample, "cpu_times", cpu_fields);
convert(entry, sample, "io", io_fields);
convert(entry, sample, "virt", virt_fields);
convert(entry, sample, "swap", swap_fields);
convert(entry, sample, "cpu_times_sum", "cpu_times", cpu_fields);
convert(entry, sample, "io", "io", io_fields);
convert(entry, sample, "virt", "virt", virt_fields);
convert(entry, sample, "swap", "swap", swap_fields);
var total = 0;
for (var k in entry.cpu_times) {
@ -179,13 +179,13 @@ BuildResources.prototype = Object.freeze({
},
get cpuPercent() {
return this.data.cpu_percent;
return this.data.overall.cpu_percent_mean;
},
get tiers() {
var t = [];
this.data.tiers.forEach(function (e) {
this.data.phases.forEach(function (e) {
t.push(e.name);
});
@ -193,8 +193,8 @@ BuildResources.prototype = Object.freeze({
},
getTier: function (tier) {
for (var i = 0; i < this.data.tiers.length; i++) {
var t = this.data.tiers[i];
for (var i = 0; i < this.data.phases.length; i++) {
var t = this.data.phases[i];
if (t.name == tier) {
return t;
@ -403,7 +403,7 @@ function renderResources(id, resources, what) {
d3.select("#tt_tier").html(entry.tier);
d3.select("#tt_duration").html(entry.duration || "n/a");
d3.select("#tt_cpu_percent").html(entry.cpu_percent || "n/a");
d3.select("#tt_cpu_percent").html(entry.cpu_percent_mean || "n/a");
d3.select("#tooltip").style("display", "");
})

Просмотреть файл

@ -793,18 +793,18 @@ class InfluxRecordingMixin(object):
}
# The top-level data has the overall resource usage, which we record
# under the name 'TOTAL' to separate it from the individual tiers.
# under the name 'TOTAL' to separate it from the individual phases.
data['points'].append(self._get_resource_usage(resources, 'TOTAL', iolen, cpulen))
# Each tier also has the same resource stats as the top-level.
for tier in resources['tiers']:
data['points'].append(self._get_resource_usage(tier, tier['name'], iolen, cpulen))
if 'duration' not in tier:
# Each phases also has the same resource stats as the top-level.
for phase in resources['phases']:
data['points'].append(self._get_resource_usage(phase, phase['name'], iolen, cpulen))
if 'duration' not in phase:
self.build_metrics_summary = None
elif self.build_metrics_summary:
self.build_metrics_summary['subtests'].append({
'name': tier['name'],
'value': tier['duration'],
'name': phase['name'],
'value': phase['duration'],
})
self.record_influx_stat([data])