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