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 ClockParser(importer) {
     23     Parser.call(this, importer);
     24 
     25     importer.registerEventHandler('clock_set_rate',
     26         ClockParser.prototype.traceMarkWriteClockEvent.bind(this));
     27 
     28     this.model_ = importer.model_;
     29     this.ppids_ = {};
     30   }
     31 
     32   ClockParser.prototype = {
     33     __proto__: Parser.prototype,
     34 
     35     traceMarkWriteClockEvent: function(eventName, cpuNumber, pid, ts,
     36                                        eventBase, threadName) {
     37       var event = /(\S+) state=(\d+) cpu_id=(\d+)/.exec(eventBase.details);
     38 
     39 
     40       var name = event[1];
     41       var rate = parseInt(event[2]);
     42 
     43       var ctr = this.model_.getOrCreateProcess(0)
     44               .getOrCreateCounter(null, name);
     45       // Initialize the counter's series fields if needed.
     46       if (ctr.numSeries === 0) {
     47         ctr.addSeries(new tracing.trace_model.CounterSeries('value',
     48             tracing.getStringColorId(ctr.name + '.' + 'value')));
     49       }
     50       ctr.series.forEach(function(series) {
     51         series.addSample(ts, rate);
     52       });
     53 
     54       return true;
     55     }
     56   };
     57 
     58   Parser.registerSubtype(ClockParser);
     59 
     60   return {
     61     ClockParser: ClockParser
     62   };
     63 });
     64