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 Base class for linux perf event parsers. 7 * 8 * The linux perf trace event importer depends on subclasses of 9 * LinuxPerfParser to parse event data. Each subclass corresponds 10 * to a group of trace events; e.g. LinuxPerfSchedParser implements 11 * parsing of sched:* kernel trace events. Parser subclasses must 12 * call LinuxPerfParser.registerSubtype to arrange to be instantiated 13 * and their constructor must register their event handlers with the 14 * importer. For example, 15 * 16 * var LinuxPerfParser = tracing.LinuxPerfParser; 17 * 18 * function LinuxPerfWorkqueueParser(importer) { 19 * LinuxPerfParser.call(this, importer); 20 * 21 * importer.registerEventHandler('workqueue_execute_start', 22 * LinuxPerfWorkqueueParser.prototype.executeStartEvent.bind(this)); 23 * importer.registerEventHandler('workqueue_execute_end', 24 * LinuxPerfWorkqueueParser.prototype.executeEndEvent.bind(this)); 25 * } 26 * 27 * LinuxPerfParser.registerSubtype(LinuxPerfWorkqueueParser); 28 * 29 * When a registered event name is found in the data stream the associated 30 * event handler is invoked: 31 * 32 * executeStartEvent: function(eventName, cpuNumber, ts, eventBase) 33 * 34 * If the routine returns false the caller will generate an import error 35 * saying there was a problem parsing it. Handlers can also emit import 36 * messages using this.importer.importError. If this is done in lieu of 37 * the generic import error it may be desirable for the handler to return 38 * true. 39 * 40 * Trace events generated by writing to the trace_marker file are expected 41 * to have a leading text marker followed by a ':'; e.g. the trace clock 42 * synchronization event is: 43 * 44 * tracing_mark_write: trace_event_clock_sync: parent_ts=0 45 * 46 * To register an event handler for these events, prepend the marker with 47 * 'tracing_mark_write:'; e.g. 48 * 49 * this.registerEventHandler('tracing_mark_write:trace_event_clock_sync', 50 * 51 * All subclasses should depend on linux_perf_parser, e.g. 52 * 53 * base.defineModule('linux_perf_workqueue_parser') 54 * .dependsOn('linux_perf_parser') 55 * .exportsTo('tracing', function() 56 * 57 * and be listed in the dependsOn of LinuxPerfImporter. Beware that after 58 * adding a new subclass you must run build/generate_about_tracing_contents.py 59 * to regenerate about_tracing.*. 60 */ 61 base.exportTo('tracing', function() { 62 63 var subtypeConstructors = []; 64 65 /** 66 * Registers a subclass that will help parse linux perf events. 67 * The importer will call createParsers (below) before importing 68 * data so each subclass can register its handlers. 69 * 70 * @param {Function} subtypeConstructor The subtype's constructor function. 71 */ 72 LinuxPerfParser.registerSubtype = function(subtypeConstructor) { 73 subtypeConstructors.push(subtypeConstructor); 74 }; 75 76 LinuxPerfParser.getSubtypeConstructors = function() { 77 return subtypeConstructors; 78 }; 79 80 /** 81 * Parses linux perf events. 82 * @constructor 83 */ 84 function LinuxPerfParser(importer) { 85 this.importer = importer; 86 } 87 88 LinuxPerfParser.prototype = { 89 __proto__: Object.prototype 90 }; 91 92 return { 93 LinuxPerfParser: LinuxPerfParser 94 }; 95 96 }); 97