1 // Copyright (c) 2013 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 graph_ent and graph_ret events that were inserted by 9 * the Linux kernel's function graph trace. 10 */ 11 base.require('tracing.importer.linux_perf.parser'); 12 base.exportTo('tracing.importer.linux_perf', function() { 13 14 var LinuxPerfParser = tracing.importer.linux_perf.Parser; 15 16 /** 17 * Parses graph_ent and graph_ret events that were inserted by the Linux 18 * kernel's function graph trace. 19 * @constructor 20 */ 21 function KernelFuncParser(importer) { 22 LinuxPerfParser.call(this, importer); 23 24 importer.registerEventHandler('graph_ent', 25 KernelFuncParser.prototype.traceKernelFuncEnterEvent. 26 bind(this)); 27 importer.registerEventHandler('graph_ret', 28 KernelFuncParser.prototype.traceKernelFuncReturnEvent. 29 bind(this)); 30 31 this.model_ = importer.model_; 32 this.ppids_ = {}; 33 } 34 35 var TestExports = {}; 36 37 var funcEnterRE = new RegExp('func=(.+)'); 38 TestExports.funcEnterRE = funcEnterRE; 39 40 KernelFuncParser.prototype = { 41 __proto__: LinuxPerfParser.prototype, 42 43 traceKernelFuncEnterEvent: function(eventName, cpuNumber, pid, ts, 44 eventBase) { 45 var eventData = funcEnterRE.exec(eventBase.details); 46 if (!eventData) 47 return false; 48 49 if (eventBase.tgid === undefined) { 50 return false; 51 } 52 53 var tgid = parseInt(eventBase.tgid); 54 var name = eventData[1]; 55 var thread = this.model_.getOrCreateProcess(tgid) 56 .getOrCreateThread(pid); 57 thread.name = eventBase.threadName; 58 59 var slices = thread.kernelSliceGroup; 60 if (!slices.isTimestampValidForBeginOrEnd(ts)) { 61 this.model_.importErrors.push('Timestamps are moving backward.'); 62 return false; 63 } 64 65 var slice = slices.beginSlice(null, name, ts, {}); 66 67 return true; 68 }, 69 70 traceKernelFuncReturnEvent: function(eventName, cpuNumber, pid, ts, 71 eventBase) { 72 if (eventBase.tgid === undefined) { 73 return false; 74 } 75 76 var tgid = parseInt(eventBase.tgid); 77 var thread = this.model_.getOrCreateProcess(tgid) 78 .getOrCreateThread(pid); 79 thread.name = eventBase.threadName; 80 81 var slices = thread.kernelSliceGroup; 82 if (!slices.isTimestampValidForBeginOrEnd(ts)) { 83 this.model_.importErrors.push('Timestamps are moving backward.'); 84 return false; 85 } 86 87 if (slices.openSliceCount > 0) { 88 slices.endSlice(ts); 89 } 90 91 return true; 92 } 93 }; 94 95 LinuxPerfParser.registerSubtype(KernelFuncParser); 96 97 return { 98 KernelFuncParser: KernelFuncParser 99 }; 100 }); 101