1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/extras/importer/linux_perf/parser.html"> 9 10<script> 11'use strict'; 12 13/** 14 * @fileoverview Parses regulator events in the Linux event trace format. 15 */ 16tr.exportTo('tr.e.importer.linux_perf', function() { 17 18 var ColorScheme = tr.b.ColorScheme; 19 var Parser = tr.e.importer.linux_perf.Parser; 20 21 /** 22 * Parses linux regulator trace events. 23 * @constructor 24 */ 25 function RegulatorParser(importer) { 26 Parser.call(this, importer); 27 28 importer.registerEventHandler('regulator_enable', 29 RegulatorParser.prototype.regulatorEnableEvent.bind(this)); 30 importer.registerEventHandler('regulator_enable_delay', 31 RegulatorParser.prototype.regulatorEnableDelayEvent.bind(this)); 32 importer.registerEventHandler('regulator_enable_complete', 33 RegulatorParser.prototype.regulatorEnableCompleteEvent.bind(this)); 34 importer.registerEventHandler('regulator_disable', 35 RegulatorParser.prototype.regulatorDisableEvent.bind(this)); 36 importer.registerEventHandler('regulator_disable_complete', 37 RegulatorParser.prototype.regulatorDisableCompleteEvent.bind(this)); 38 importer.registerEventHandler('regulator_set_voltage', 39 RegulatorParser.prototype.regulatorSetVoltageEvent.bind(this)); 40 importer.registerEventHandler('regulator_set_voltage_complete', 41 RegulatorParser.prototype.regulatorSetVoltageCompleteEvent.bind(this)); 42 43 this.model_ = importer.model_; 44 } 45 46 // Matches the regulator_enable record 47 var regulatorEnableRE = /name=(.+)/; 48 49 // Matches the regulator_disable record 50 var regulatorDisableRE = /name=(.+)/; 51 52 // Matches the regulator_set_voltage_complete record 53 var regulatorSetVoltageCompleteRE = /name=(\S+), val=(\d+)/; 54 55 RegulatorParser.prototype = { 56 __proto__: Parser.prototype, 57 58 /** 59 * Get or create a counter with one series. 60 */ 61 getCtr_: function(ctrName, valueName) { 62 var ctr = this.model_.kernel 63 .getOrCreateCounter(null, 'vreg ' + ctrName + ' ' + valueName); 64 // Initialize the counter's series fields if needed. 65 if (ctr.series[0] === undefined) { 66 ctr.addSeries(new tr.model.CounterSeries(valueName, 67 ColorScheme.getColorIdForGeneralPurposeString( 68 ctrName + '.' + valueName))); 69 } 70 return ctr; 71 }, 72 73 /** 74 * Parses regulator events and sets up state in the importer. 75 */ 76 regulatorEnableEvent: function(eventName, cpuNum, pid, ts, eventBase) { 77 var event = regulatorEnableRE.exec(eventBase.details); 78 if (!event) 79 return false; 80 81 var name = event[1]; 82 83 var ctr = this.getCtr_(name, 'enabled'); 84 ctr.series[0].addCounterSample(ts, 1); 85 86 return true; 87 }, 88 89 regulatorEnableDelayEvent: function(eventName, cpuNum, pid, ts, eventBase) { 90 return true; 91 }, 92 93 regulatorEnableCompleteEvent: function(eventName, cpuNum, pid, ts, 94 eventBase) { 95 return true; 96 }, 97 98 regulatorDisableEvent: function(eventName, cpuNum, pid, ts, eventBase) { 99 var event = regulatorDisableRE.exec(eventBase.details); 100 if (!event) 101 return false; 102 103 var name = event[1]; 104 105 var ctr = this.getCtr_(name, 'enabled'); 106 ctr.series[0].addCounterSample(ts, 0); 107 108 return true; 109 }, 110 111 regulatorDisableCompleteEvent: function(eventName, cpuNum, pid, ts, 112 eventBase) { 113 return true; 114 }, 115 116 regulatorSetVoltageEvent: function(eventName, cpuNum, pid, ts, eventBase) { 117 return true; 118 }, 119 120 regulatorSetVoltageCompleteEvent: function(eventName, cpuNum, pid, ts, 121 eventBase) { 122 var event = regulatorSetVoltageCompleteRE.exec(eventBase.details); 123 if (!event) 124 return false; 125 126 var name = event[1]; 127 var voltage = parseInt(event[2]); 128 129 var ctr = this.getCtr_(name, 'voltage'); 130 ctr.series[0].addCounterSample(ts, voltage); 131 132 return true; 133 } 134 135 }; 136 137 Parser.register(RegulatorParser); 138 139 return { 140 RegulatorParser: RegulatorParser 141 }; 142}); 143</script> 144