<commit_before><!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/importer/importer.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/model/power_series.html">

<script>
/**
 * @fileoverview Imports text files in the BattOr format into the
 * Model. This format is output by the battor_agent executable and library.
 *
 * This importer assumes the events arrive as a string. The unit tests provide
 * examples of the trace format.
 */
'use strict';

tr.exportTo('tr.e.importer.battor', function() {
  /**
   * Imports a BattOr power trace into a specified model.
   * @constructor
   */
  function BattorImporter(model, events) {
    this.importPriority = 3; // runs after the linux_perf importer
    this.model_ = model;
    this.samples_ = this.linesToSamples_(events.split('\n'));
  }

  var battorDataLineRE = new RegExp(
      '^(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)' +
      '(?:\\s+<(\\S+)>)?$'
  );
  var battorHeaderLineRE = /^# BattOr/;

  /**
   * Guesses whether the provided events is a BattOr string.
   * Looks for the magic string "# BattOr" at the start of the file,
   *
   * @return {boolean} True when events is a BattOr array.
   */
  BattorImporter.canImport = function(events) {
    if (!(typeof(events) === 'string' || events instanceof String))
      return false;

    return battorHeaderLineRE.test(events);
  };

  BattorImporter.prototype = {
    __proto__: tr.importer.Importer.prototype,

    get importerName() {
      return 'BattorImporter';
    },

    get model() {
      return this.model_;
    },

    /**
     * Imports clock sync markers in this.events_ into 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);
        }
      }
    },

    /**
     * Imports the data in this.events_ into model_.
     */
    importEvents: function() {
      if (this.model_.device.powerSeries) {
        this.model_.importWarning({
          type: 'import_error',
          message: 'Power counter exists, can not import BattOr power trace.'
        });
        return;
      }

      var modelTimeTransformer =
          this.model_.clockSyncManager.getModelTimeTransformer(
              tr.model.ClockDomainId.BATTOR);

      var powerSeries = this.model_.device.powerSeries =
          new tr.model.PowerSeries(this.model_.device);
      for (var i = 0; i < this.samples_.length; i++) {
        var sample = this.samples_[i];
        powerSeries.addPowerSample(
            modelTimeTransformer(sample.ts), sample.power);
      }
    },

    /**
     * Given an array of strings that make up the lines of a BattOr trace,
     * returns an array of samples contained within those lines.
     */
    linesToSamples_: function(lines) {
      var samples = [];

      for (var i = 0; i < lines.length; i++) {
        var line = lines[i];
        line = line.trim();

        if (line.length === 0)
          continue;

        if (line.startsWith('#'))
          continue;

        // Parse power sample.
        var groups = battorDataLineRE.exec(line);
        if (!groups) {
          this.model_.importWarning({
            type: 'parse_error',
            message: 'Unrecognized line: ' + line
          });
          continue;
        }

        var ts = parseFloat(groups[1]);
        var voltage = parseFloat(groups[2]) / 1000;
        var current = parseFloat(groups[3]);
        var syncId = groups[4];

        samples.push(new Sample(ts, voltage, current, syncId));
      }

      return samples;
    }
  };<commit_msg>Convert mA to A correctly in BattOr data.<commit_after><!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/importer/importer.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/model/power_series.html">

<script>
/**
 * @fileoverview Imports text files in the BattOr format into the
 * Model. This format is output by the battor_agent executable and library.
 *
 * This importer assumes the events arrive as a string. The unit tests provide
 * examples of the trace format.
 */
'use strict';

tr.exportTo('tr.e.importer.battor', function() {
  /**
   * Imports a BattOr power trace into a specified model.
   * @constructor
   */
  function BattorImporter(model, events) {
    this.importPriority = 3; // runs after the linux_perf importer
    this.model_ = model;
    this.samples_ = this.linesToSamples_(events.split('\n'));
  }

  var battorDataLineRE = new RegExp(
      '^(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)' +
      '(?:\\s+<(\\S+)>)?$'
  );
  var battorHeaderLineRE = /^# BattOr/;

  /**
   * Guesses whether the provided events is a BattOr string.
   * Looks for the magic string "# BattOr" at the start of the file,
   *
   * @return {boolean} True when events is a BattOr array.
   */
  BattorImporter.canImport = function(events) {
    if (!(typeof(events) === 'string' || events instanceof String))
      return false;

    return battorHeaderLineRE.test(events);
  };

  BattorImporter.prototype = {
    __proto__: tr.importer.Importer.prototype,

    get importerName() {
      return 'BattorImporter';
    },

    get model() {
      return this.model_;
    },

    /**
     * Imports clock sync markers in this.events_ into 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);
        }
      }
    },

    /**
     * Imports the data in this.events_ into model_.
     */
    importEvents: function() {
      if (this.model_.device.powerSeries) {
        this.model_.importWarning({
          type: 'import_error',
          message: 'Power counter exists, can not import BattOr power trace.'
        });
        return;
      }

      var modelTimeTransformer =
          this.model_.clockSyncManager.getModelTimeTransformer(
              tr.model.ClockDomainId.BATTOR);

      var powerSeries = this.model_.device.powerSeries =
          new tr.model.PowerSeries(this.model_.device);
      for (var i = 0; i < this.samples_.length; i++) {
        var sample = this.samples_[i];
        powerSeries.addPowerSample(
            modelTimeTransformer(sample.ts), sample.power);
      }
    },

    /**
     * Given an array of strings that make up the lines of a BattOr trace,
     * returns an array of samples contained within those lines.
     */
    linesToSamples_: function(lines) {
      var samples = [];

      for (var i = 0; i < lines.length; i++) {
        var line = lines[i];
        line = line.trim();

        if (line.length === 0)
          continue;

        if (line.startsWith('#'))
          continue;

        // Parse power sample.
        var groups = battorDataLineRE.exec(line);
        if (!groups) {
          this.model_.importWarning({
            type: 'parse_error',
            message: 'Unrecognized line: ' + line
          });
          continue;
        }

        var ts = parseFloat(groups[1]);
        var voltage = parseFloat(groups[2]) / 1000;
        var current = parseFloat(groups[3]) / 1000;
        var syncId = groups[4];

        samples.push(new Sample(ts, voltage, current, syncId));
      }

      return samples;
    }
  };
{'fraction_non_alphanumeric': 0.1296928327645051, 'fraction_numerical': 0.0048034382505372265, 'mean_word_length': 2.327165685449958, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7482548', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2348, 'n_words': 656}