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 gesture 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 trace events generated by gesture library for touchpad. 17 * @constructor 18 */ 19 function GestureParser(importer) { 20 Parser.call(this, importer); 21 importer.registerEventHandler('tracing_mark_write:log', 22 GestureParser.prototype.logEvent.bind(this)); 23 importer.registerEventHandler('tracing_mark_write:SyncInterpret', 24 GestureParser.prototype.syncEvent.bind(this)); 25 importer.registerEventHandler('tracing_mark_write:HandleTimer', 26 GestureParser.prototype.timerEvent.bind(this)); 27 } 28 29 GestureParser.prototype = { 30 __proto__: Parser.prototype, 31 32 /** 33 * Parse events generate by gesture library. 34 * gestureOpenSlice and gestureCloseSlice are two common 35 * functions to store the begin time and end time for all 36 * events in gesture library 37 */ 38 gestureOpenSlice: function(title, ts, opt_args) { 39 var thread = this.importer.getOrCreatePseudoThread('gesture').thread; 40 thread.sliceGroup.beginSlice( 41 'touchpad_gesture', title, ts, opt_args); 42 }, 43 44 gestureCloseSlice: function(title, ts) { 45 var thread = this.importer.getOrCreatePseudoThread('gesture').thread; 46 if (thread.sliceGroup.openSliceCount) { 47 var slice = thread.sliceGroup.mostRecentlyOpenedPartialSlice; 48 if (slice.title != title) { 49 this.importer.importError('Titles do not match. Title is ' + 50 slice.title + ' in openSlice, and is ' + 51 title + ' in endSlice'); 52 } else { 53 thread.sliceGroup.endSlice(ts); 54 } 55 } 56 }, 57 58 /** 59 * For log events, events will come in pairs with a tag log: 60 * like this: 61 * tracing_mark_write: log: start: TimerLogOutputs 62 * tracing_mark_write: log: end: TimerLogOutputs 63 * which represent the start and the end time of certain log behavior 64 * Take these logs above for example, they are the start and end time 65 * of logging Output for HandleTimer function 66 */ 67 logEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 68 var innerEvent = 69 /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details); 70 switch (innerEvent[1]) { 71 case 'start': 72 this.gestureOpenSlice('GestureLog', ts, {name: innerEvent[2]}); 73 break; 74 case 'end': 75 this.gestureCloseSlice('GestureLog', ts); 76 } 77 return true; 78 }, 79 80 /** 81 * For SyncInterpret events, events will come in pairs with 82 * a tag SyncInterpret: 83 * like this: 84 * tracing_mark_write: SyncInterpret: start: ClickWiggleFilterInterpreter 85 * tracing_mark_write: SyncInterpret: end: ClickWiggleFilterInterpreter 86 * which represent the start and the end time of SyncInterpret function 87 * inside the certain interpreter in the gesture library. 88 * Take the logs above for example, they are the start and end time 89 * of the SyncInterpret function inside ClickWiggleFilterInterpreter 90 */ 91 syncEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 92 var innerEvent = /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details); 93 switch (innerEvent[1]) { 94 case 'start': 95 this.gestureOpenSlice('SyncInterpret', ts, 96 {interpreter: innerEvent[2]}); 97 break; 98 case 'end': 99 this.gestureCloseSlice('SyncInterpret', ts); 100 } 101 return true; 102 }, 103 104 /** 105 * For HandleTimer events, events will come in pairs with 106 * a tag HandleTimer: 107 * like this: 108 * tracing_mark_write: HandleTimer: start: LookaheadFilterInterpreter 109 * tracing_mark_write: HandleTimer: end: LookaheadFilterInterpreter 110 * which represent the start and the end time of HandleTimer function 111 * inside the certain interpreter in the gesture library. 112 * Take the logs above for example, they are the start and end time 113 * of the HandleTimer function inside LookaheadFilterInterpreter 114 */ 115 timerEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 116 var innerEvent = /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details); 117 switch (innerEvent[1]) { 118 case 'start': 119 this.gestureOpenSlice('HandleTimer', ts, 120 {interpreter: innerEvent[2]}); 121 break; 122 case 'end': 123 this.gestureCloseSlice('HandleTimer', ts); 124 } 125 return true; 126 } 127 }; 128 129 Parser.registerSubtype(GestureParser); 130 131 return { 132 GestureParser: GestureParser 133 }; 134 }); 135