Home | History | Annotate | Download | only in linux_perf
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 /**
      8  * @fileoverview Parses trace_marker events that were inserted in the trace by
      9  * userland.
     10  */
     11 base.require('tracing.importer.linux_perf.parser');
     12 base.require('tracing.trace_model.counter_series');
     13 
     14 base.exportTo('tracing.importer.linux_perf', function() {
     15 
     16   var Parser = tracing.importer.linux_perf.Parser;
     17 
     18   /**
     19    * Parses linux trace mark events that were inserted in the trace by userland.
     20    * @constructor
     21    */
     22   function BusParser(importer) {
     23     Parser.call(this, importer);
     24 
     25     importer.registerEventHandler('memory_bus_usage',
     26         BusParser.prototype.traceMarkWriteBusEvent.bind(this));
     27 
     28     this.model_ = importer.model_;
     29     this.ppids_ = {};
     30   }
     31 
     32   BusParser.prototype = {
     33     __proto__: Parser.prototype,
     34 
     35     traceMarkWriteBusEvent: function(eventName, cpuNumber, pid, ts,
     36                                   eventBase, threadName) {
     37       var re = new RegExp('bus=(\\S+) rw_bytes=(\\d+) r_bytes=(\\d+) ' +
     38                             'w_bytes=(\\d+) cycles=(\\d+) ns=(\\d+)');
     39       var event = re.exec(eventBase.details);
     40 
     41       var name = event[1];
     42       var rw_bytes = parseInt(event[2]);
     43       var r_bytes = parseInt(event[3]);
     44       var w_bytes = parseInt(event[4]);
     45       var cycles = parseInt(event[5]);
     46       var ns = parseInt(event[6]);
     47 
     48       // BW in MB/s
     49       var r_bw = r_bytes * 1000000000 / ns;
     50       r_bw /= 1024 * 1024;
     51       var w_bw = w_bytes * 1000000000 / ns;
     52       w_bw /= 1024 * 1024;
     53 
     54       var ctr = this.model_.getOrCreateProcess(0)
     55               .getOrCreateCounter(null, 'bus ' + name + ' read');
     56       if (ctr.numSeries === 0) {
     57         ctr.addSeries(new tracing.trace_model.CounterSeries('value',
     58             tracing.getStringColorId(ctr.name + '.' + 'value')));
     59       }
     60       ctr.series.forEach(function(series) {
     61         series.addSample(ts, r_bw);
     62       });
     63 
     64       ctr = this.model_.getOrCreateProcess(0)
     65               .getOrCreateCounter(null, 'bus ' + name + ' write');
     66       if (ctr.numSeries === 0) {
     67         ctr.addSeries(new tracing.trace_model.CounterSeries('value',
     68             tracing.getStringColorId(ctr.name + '.' + 'value')));
     69       }
     70       ctr.series.forEach(function(series) {
     71         series.addSample(ts, r_bw);
     72       });
     73 
     74       return true;
     75     }
     76   };
     77 
     78   Parser.registerSubtype(BusParser);
     79 
     80   return {
     81     BusParser: BusParser
     82   };
     83 });
     84