| Index: tracing/tracing/extras/importer/battor_importer.html
|
| diff --git a/tracing/tracing/extras/importer/battor_importer.html b/tracing/tracing/extras/importer/battor_importer.html
|
| index 381bf0f86872c86e3ac014ddec1ba372ce689b16..8dfc999cb2f3ba281f104d223a3ba5343fdb4d0f 100644
|
| --- a/tracing/tracing/extras/importer/battor_importer.html
|
| +++ b/tracing/tracing/extras/importer/battor_importer.html
|
| @@ -27,7 +27,13 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| function BattorImporter(model, events) {
|
| this.importPriority = 3; // runs after the linux_perf importer
|
| this.model_ = model;
|
| - this.samples_ = this.linesToSamples_(events.split('\n'));
|
| +
|
| + // The list of power samples contained within the trace.
|
| + this.samples_ = [];
|
| + // The clock sync markers contained within the trace.
|
| + this.syncTimestampsById_ = new Map();
|
| +
|
| + this.parseTrace_(events);
|
| }
|
|
|
| var battorDataLineRE = new RegExp(
|
| @@ -61,20 +67,17 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| },
|
|
|
| /**
|
| - * Imports clock sync markers in this.events_ into model_.
|
| + * Imports clock sync markers from the trace into into this.model_.
|
| */
|
| importClockSyncMarkers: function() {
|
| - for (var i = 0; i < this.samples_.length; i++) {
|
| - var sample = this.samples_[i];
|
| - if (sample.syncId) {
|
| - this.model_.clockSyncManager.addClockSyncMarker(
|
| - tr.model.ClockDomainId.BATTOR, sample.syncId, sample.ts);
|
| - }
|
| + for (var [syncId, ts] of this.syncTimestampsById_) {
|
| + this.model_.clockSyncManager.addClockSyncMarker(
|
| + tr.model.ClockDomainId.BATTOR, syncId, ts);
|
| }
|
| },
|
|
|
| /**
|
| - * Imports the data in this.events_ into model_.
|
| + * Imports the events from the trace into this.model_.
|
| */
|
| importEvents: function() {
|
| if (this.model_.device.powerSeries) {
|
| @@ -99,14 +102,13 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| },
|
|
|
| /**
|
| - * Given an array of strings that make up the lines of a BattOr trace,
|
| - * returns an array of samples contained within those lines.
|
| + * Given the BattOr trace as a string, parse it and store the results in
|
| + * this.samples_ and this.syncTimestampsById_.
|
| */
|
| - linesToSamples_: function(lines) {
|
| - var samples = [];
|
| + parseTrace_: function(trace) {
|
| + var lines = trace.split('\n');
|
|
|
| - for (var i = 0; i < lines.length; i++) {
|
| - var line = lines[i];
|
| + for (var line of lines) {
|
| line = line.trim();
|
|
|
| if (line.length === 0)
|
| @@ -130,6 +132,9 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| var current = parseFloat(groups[3]) / 1000;
|
| var syncId = groups[4];
|
|
|
| + if (syncId)
|
| + this.syncTimestampsById_.set(syncId, ts);
|
| +
|
| if (voltage < 0 || current < 0) {
|
| this.model_.importWarning({
|
| type: 'parse_error',
|
| @@ -141,10 +146,8 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| continue;
|
| }
|
|
|
| - samples.push(new Sample(ts, voltage, current, syncId));
|
| + this.samples_.push(new Sample(ts, voltage, current));
|
| }
|
| -
|
| - return samples;
|
| }
|
| };
|
|
|
| @@ -154,16 +157,13 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| * @param {number} ts The timestamp (in milliseconds) of the sample.
|
| * @param {number} voltage The voltage (in volts) at the specified time.
|
| * @param {number} current The current (in amps) at the specified time.
|
| - * @param {string=} opt_syncId The sync ID of the sync that happened at this
|
| - * sample.
|
| *
|
| * @constructor
|
| */
|
| - function Sample(ts, voltage, current, opt_syncId) {
|
| + function Sample(ts, voltage, current) {
|
| this.ts = ts;
|
| this.voltage = voltage;
|
| this.current = current;
|
| - this.syncId = opt_syncId;
|
| }
|
|
|
| Sample.prototype = {
|
| @@ -174,7 +174,7 @@ tr.exportTo('tr.e.importer.battor', function() {
|
| tr.importer.Importer.register(BattorImporter);
|
|
|
| return {
|
| - BattorImporter: BattorImporter,
|
| + BattorImporter: BattorImporter
|
| };
|
| });
|
|
|
|
|