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