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('linux_perf_parser'); 9 base.exportTo('tracing', function() { 10 11 var LinuxPerfParser = tracing.LinuxPerfParser; 12 13 /** 14 * Parses linux sched trace events. 15 * @constructor 16 */ 17 function LinuxPerfSchedParser(importer) { 18 LinuxPerfParser.call(this, importer); 19 20 importer.registerEventHandler('sched_switch', 21 LinuxPerfSchedParser.prototype.schedSwitchEvent.bind(this)); 22 importer.registerEventHandler('sched_wakeup', 23 LinuxPerfSchedParser.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 LinuxPerfSchedParser.prototype = { 41 __proto__: LinuxPerfParser.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[5]); 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[5]); 64 if (!event) 65 return false; 66 67 var comm = event[1]; 68 var pid = parseInt(event[2]); 69 var prio = parseInt(event[3]); 70 this.importer.markPidRunnable(ts, pid, comm, prio); 71 return true; 72 } 73 }; 74 75 LinuxPerfParser.registerSubtype(LinuxPerfSchedParser); 76 77 return { 78 LinuxPerfSchedParser: LinuxPerfSchedParser, 79 _LinuxPerfSchedParserTestExports: TestExports 80 }; 81 }); 82