Home | History | Annotate | Download | only in src
      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 /**
      6  * @fileoverview Parses trace_marker events that were inserted in the trace by
      7  * userland.
      8  */
      9 base.require('linux_perf_parser');
     10 base.exportTo('tracing', function() {
     11 
     12   var LinuxPerfParser = tracing.LinuxPerfParser;
     13 
     14   /**
     15    * Parses linux trace mark events that were inserted in the trace by userland.
     16    * @constructor
     17    */
     18   function LinuxPerfBusParser(importer) {
     19     LinuxPerfParser.call(this, importer);
     20 
     21     importer.registerEventHandler('memory_bus_usage',
     22         LinuxPerfBusParser.prototype.traceMarkWriteBusEvent.bind(this));
     23 
     24     this.model_ = importer.model_;
     25     this.ppids_ = {};
     26   }
     27 
     28   LinuxPerfBusParser.prototype = {
     29     __proto__: LinuxPerfParser.prototype,
     30 
     31     traceMarkWriteBusEvent: function(eventName, cpuNumber, pid, ts,
     32                                   eventBase, threadName) {
     33         var re = new RegExp('bus=(\\S+) rw_bytes=(\\d+) r_bytes=(\\d+) ' +
     34                             'w_bytes=(\\d+) cycles=(\\d+) ns=(\\d+)');
     35         var event = re.exec(eventBase[5]);
     36 
     37         var name = event[1];
     38         var rw_bytes = parseInt(event[2]);
     39         var r_bytes = parseInt(event[3]);
     40         var w_bytes = parseInt(event[4]);
     41         var cycles = parseInt(event[5]);
     42         var ns = parseInt(event[6]);
     43 
     44         // BW in MB/s
     45         var r_bw = r_bytes * 1000000000 / ns;
     46         r_bw /= 1024 * 1024;
     47         var w_bw = w_bytes * 1000000000 / ns;
     48         w_bw /= 1024 * 1024;
     49 
     50         var ctr = this.model_.getOrCreateProcess(0)
     51               .getOrCreateCounter(null, 'bus ' + name + ' read');
     52         // Initialize the counter's series fields if needed.
     53         if (ctr.numSeries == 0) {
     54             ctr.seriesNames.push('value');
     55             ctr.seriesColors.push(
     56                 tracing.getStringColorId(ctr.name + '.' + 'value'));
     57         }
     58 
     59         // Add the sample value.
     60         ctr.timestamps.push(ts);
     61         ctr.samples.push(r_bw);
     62 
     63         ctr = this.model_.getOrCreateProcess(0)
     64               .getOrCreateCounter(null, 'bus ' + name + ' write');
     65         // Initialize the counter's series fields if needed.
     66         if (ctr.numSeries == 0) {
     67             ctr.seriesNames.push('value');
     68             ctr.seriesColors.push(
     69                 tracing.getStringColorId(ctr.name + '.' + 'value'));
     70         }
     71 
     72         // Add the sample value.
     73         ctr.timestamps.push(ts);
     74         ctr.samples.push(w_bw);
     75 
     76         return true;
     77     },
     78   };
     79 
     80   LinuxPerfParser.registerSubtype(LinuxPerfBusParser);
     81 
     82   return {
     83     LinuxPerfBusParser: LinuxPerfBusParser
     84   };
     85 });
     86