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 cpufreq events in the Linux event trace format.
      7  */
      8 base.require('linux_perf_parser');
      9 base.exportTo('tracing', function() {
     10 
     11   var LinuxPerfParser = tracing.LinuxPerfParser;
     12 
     13   /**
     14    * Parses linux cpufreq trace events.
     15    * @constructor
     16    */
     17   function LinuxPerfCpufreqParser(importer) {
     18     LinuxPerfParser.call(this, importer);
     19 
     20     importer.registerEventHandler('cpufreq_interactive_up',
     21         LinuxPerfCpufreqParser.prototype.cpufreqUpDownEvent.bind(this));
     22     importer.registerEventHandler('cpufreq_interactive_down',
     23         LinuxPerfCpufreqParser.prototype.cpufreqUpDownEvent.bind(this));
     24     importer.registerEventHandler('cpufreq_interactive_already',
     25         LinuxPerfCpufreqParser.prototype.cpufreqTargetEvent.bind(this));
     26     importer.registerEventHandler('cpufreq_interactive_notyet',
     27         LinuxPerfCpufreqParser.prototype.cpufreqTargetEvent.bind(this));
     28     importer.registerEventHandler('cpufreq_interactive_target',
     29         LinuxPerfCpufreqParser.prototype.cpufreqTargetEvent.bind(this));
     30     importer.registerEventHandler('cpufreq_interactive_boost',
     31         LinuxPerfCpufreqParser.prototype.cpufreqBoostUnboostEvent.bind(this));
     32     importer.registerEventHandler('cpufreq_interactive_unboost',
     33         LinuxPerfCpufreqParser.prototype.cpufreqBoostUnboostEvent.bind(this));
     34   }
     35 
     36   LinuxPerfCpufreqParser.prototype = {
     37     __proto__: LinuxPerfParser.prototype,
     38 
     39     cpufreqSlice: function(ts, eventName, cpu, args) {
     40       // TODO(sleffler) should be per-cpu
     41       var kthread = this.importer.getOrCreatePseudoThread('cpufreq');
     42       kthread.openSlice = eventName;
     43       var slice = new tracing.TimelineSlice('', kthread.openSlice,
     44           tracing.getStringColorId(kthread.openSlice), ts, args, 0);
     45 
     46       kthread.thread.pushSlice(slice);
     47     },
     48 
     49     cpufreqBoostSlice: function(ts, eventName, args) {
     50       var kthread = this.importer.getOrCreatePseudoThread('cpufreq_boost');
     51       kthread.openSlice = eventName;
     52       var slice = new tracing.TimelineSlice('', kthread.openSlice,
     53           tracing.getStringColorId(kthread.openSlice), ts, args, 0);
     54 
     55       kthread.thread.pushSlice(slice);
     56     },
     57 
     58     /**
     59      * Parses cpufreq events and sets up state in the importer.
     60      */
     61     cpufreqUpDownEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
     62       var event = /cpu=(\d+) targ=(\d+) actual=(\d+)/.exec(eventBase[5]);
     63       if (!event)
     64         return false;
     65 
     66       // TODO(sleffler) split by cpu
     67       var cpu = parseInt(event[1]);
     68       var targ = parseInt(event[2]);
     69       var actual = parseInt(event[3]);
     70       this.cpufreqSlice(ts, eventName, cpu,
     71           {
     72             cpu: cpu,
     73             targ: targ,
     74             actual: actual
     75           });
     76       return true;
     77     },
     78 
     79     cpufreqTargetEvent: function(eventName, cpuNumber, pid, ts,
     80                                  eventBase) {
     81       var event = /cpu=(\d+) load=(\d+) cur=(\d+) targ=(\d+)/
     82           .exec(eventBase[5]);
     83       if (!event)
     84         return false;
     85 
     86       // TODO(sleffler) split by cpu
     87       var cpu = parseInt(event[1]);
     88       var load = parseInt(event[2]);
     89       var cur = parseInt(event[3]);
     90       var targ = parseInt(event[4]);
     91       this.cpufreqSlice(ts, eventName, cpu,
     92           {
     93             cpu: cpu,
     94             load: load,
     95             cur: cur,
     96             targ: targ
     97           });
     98       return true;
     99     },
    100 
    101     cpufreqBoostUnboostEvent: function(eventName, cpuNumber, pid, ts,
    102                                        eventBase) {
    103       this.cpufreqBoostSlice(ts, eventName,
    104           {
    105             type: eventBase[5]
    106           });
    107       return true;
    108     }
    109   };
    110 
    111   LinuxPerfParser.registerSubtype(LinuxPerfCpufreqParser);
    112 
    113   return {
    114     LinuxPerfCpufreqParser: LinuxPerfCpufreqParser
    115   };
    116 });
    117