blob: d3ac9837afbecca5f91ae916e21826bfca520730 [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="/tracing/base/unit_scale.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/parser.html">
<link rel="import" href="/tracing/model/counter_series.html">
<script>
'use strict';
/**
* @fileoverview Parses trace_marker events that were inserted in the trace by
* userland.
*/
tr.exportTo('tr.e.importer.linux_perf', function() {
var ColorScheme = tr.b.ColorScheme;
var Parser = tr.e.importer.linux_perf.Parser;
/**
* Parses linux trace mark events that were inserted in the trace by userland.
* @constructor
*/
function BusParser(importer) {
Parser.call(this, importer);
importer.registerEventHandler('memory_bus_usage',
BusParser.prototype.traceMarkWriteBusEvent.bind(this));
this.model_ = importer.model_;
this.ppids_ = {};
}
BusParser.prototype = {
__proto__: Parser.prototype,
traceMarkWriteBusEvent: function(eventName, cpuNumber, pid, ts,
eventBase, threadName) {
var re = new RegExp('bus=(\\S+) rw_bytes=(\\d+) r_bytes=(\\d+) ' +
'w_bytes=(\\d+) cycles=(\\d+) ns=(\\d+)');
var event = re.exec(eventBase.details);
var name = event[1];
var rwBytes = parseInt(event[2]);
var rBytes = parseInt(event[3]);
var wBytes = parseInt(event[4]);
var cycles = parseInt(event[5]);
var ns = parseInt(event[6]);
// BW in MiB/s.
var sec = tr.b.convertUnit(ns, tr.b.UnitScale.Metric.NANO,
tr.b.UnitScale.Metric.NONE);
var readBandwidthInBps = rBytes / sec;
var readBandwidthInMiBps = tr.b.convertUnit(readBandwidthInBps,
tr.b.UnitScale.Binary.NONE,
tr.b.UnitScale.Binary.MEBI);
var writeBandwidthInBps = wBytes / sec;
var writeBandwidthInMiBps = tr.b.convertUnit(writeBandwidthInBps,
tr.b.UnitScale.Binary.NONE,
tr.b.UnitScale.Binary.MEBI);
var ctr = this.model_.kernel
.getOrCreateCounter(null, 'bus ' + name + ' read');
if (ctr.numSeries === 0) {
ctr.addSeries(new tr.model.CounterSeries('value',
ColorScheme.getColorIdForGeneralPurposeString(
ctr.name + '.' + 'value')));
}
ctr.series.forEach(function(series) {
series.addCounterSample(ts, readBandwidthInMiBps);
});
ctr = this.model_.kernel
.getOrCreateCounter(null, 'bus ' + name + ' write');
if (ctr.numSeries === 0) {
ctr.addSeries(new tr.model.CounterSeries('value',
ColorScheme.getColorIdForGeneralPurposeString(
ctr.name + '.' + 'value')));
}
ctr.series.forEach(function(series) {
series.addCounterSample(ts, writeBandwidthInMiBps);
});
return true;
}
};
Parser.register(BusParser);
return {
BusParser: BusParser
};
});
</script>