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 scheduler events in the Linux event trace format. 7 */ 8 base.require('importer.linux_perf.parser'); 9 base.exportTo('tracing.importer.linux_perf', function() { 10 11 var Parser = tracing.importer.linux_perf.Parser; 12 13 /** 14 * Parses linux sched trace events. 15 * @constructor 16 */ 17 function SchedParser(importer) { 18 Parser.call(this, importer); 19 20 importer.registerEventHandler('sched_switch', 21 SchedParser.prototype.schedSwitchEvent.bind(this)); 22 importer.registerEventHandler('sched_wakeup', 23 SchedParser.prototype.schedWakeupEvent.bind(this)); 24 } 25 26 TestExports = {}; 27 28 // Matches the sched_switch record 29 var schedSwitchRE = new RegExp( 30 'prev_comm=(.+) prev_pid=(\\d+) prev_prio=(\\d+) ' + 31 'prev_state=(\\S\\+?|\\S\\|\\S) ==> ' + 32 'next_comm=(.+) next_pid=(\\d+) next_prio=(\\d+)'); 33 TestExports.schedSwitchRE = schedSwitchRE; 34 35 // Matches the sched_wakeup record 36 var schedWakeupRE = 37 /comm=(.+) pid=(\d+) prio=(\d+) success=(\d+) target_cpu=(\d+)/; 38 TestExports.schedWakeupRE = schedWakeupRE; 39 40 SchedParser.prototype = { 41 __proto__: Parser.prototype, 42 43 /** 44 * Parses scheduler events and sets up state in the importer. 45 */ 46 schedSwitchEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 47 var event = schedSwitchRE.exec(eventBase.details); 48 if (!event) 49 return false; 50 51 var prevState = event[4]; 52 var nextComm = event[5]; 53 var nextPid = parseInt(event[6]); 54 var nextPrio = parseInt(event[7]); 55 56 var cpuState = this.importer.getOrCreateCpuState(cpuNumber); 57 cpuState.switchRunningLinuxPid(this.importer, 58 prevState, ts, nextPid, nextComm, nextPrio); 59 return true; 60 }, 61 62 schedWakeupEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 63 var event = schedWakeupRE.exec(eventBase.details); 64 if (!event) 65 return false; 66 67 var fromPid = pid; 68 var comm = event[1]; 69 var pid = parseInt(event[2]); 70 var prio = parseInt(event[3]); 71 this.importer.markPidRunnable(ts, pid, comm, prio, fromPid); 72 return true; 73 } 74 }; 75 76 Parser.registerSubtype(SchedParser); 77 78 return { 79 SchedParser: SchedParser, 80 _SchedParserTestExports: TestExports 81 }; 82 }); 83