1<!DOCTYPE html> 2<!-- 3Copyright (c) 2012 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/extras/importer/linux_perf/parser.html"> 9 10<script> 11'use strict'; 12 13/** 14 * @fileoverview Parses gesture events in the Linux event trace format. 15 */ 16tr.exportTo('tr.e.importer.linux_perf', function() { 17 18 var Parser = tr.e.importer.linux_perf.Parser; 19 20 /** 21 * Parses trace events generated by gesture library for touchpad. 22 * @constructor 23 */ 24 function GestureParser(importer) { 25 Parser.call(this, importer); 26 importer.registerEventHandler('tracing_mark_write:log', 27 GestureParser.prototype.logEvent.bind(this)); 28 importer.registerEventHandler('tracing_mark_write:SyncInterpret', 29 GestureParser.prototype.syncEvent.bind(this)); 30 importer.registerEventHandler('tracing_mark_write:HandleTimer', 31 GestureParser.prototype.timerEvent.bind(this)); 32 } 33 34 GestureParser.prototype = { 35 __proto__: Parser.prototype, 36 37 /** 38 * Parse events generate by gesture library. 39 * gestureOpenSlice and gestureCloseSlice are two common 40 * functions to store the begin time and end time for all 41 * events in gesture library 42 */ 43 gestureOpenSlice: function(title, ts, opt_args) { 44 var thread = this.importer.getOrCreatePseudoThread('gesture').thread; 45 thread.sliceGroup.beginSlice( 46 'touchpad_gesture', title, ts, opt_args); 47 }, 48 49 gestureCloseSlice: function(title, ts) { 50 var thread = this.importer.getOrCreatePseudoThread('gesture').thread; 51 if (thread.sliceGroup.openSliceCount) { 52 var slice = thread.sliceGroup.mostRecentlyOpenedPartialSlice; 53 if (slice.title != title) { 54 this.importer.model.importWarning({ 55 type: 'title_match_error', 56 message: 'Titles do not match. Title is ' + 57 slice.title + ' in openSlice, and is ' + 58 title + ' in endSlice' 59 }); 60 } else { 61 thread.sliceGroup.endSlice(ts); 62 } 63 } 64 }, 65 66 /** 67 * For log events, events will come in pairs with a tag log: 68 * like this: 69 * tracing_mark_write: log: start: TimerLogOutputs 70 * tracing_mark_write: log: end: TimerLogOutputs 71 * which represent the start and the end time of certain log behavior 72 * Take these logs above for example, they are the start and end time 73 * of logging Output for HandleTimer function 74 */ 75 logEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 76 var innerEvent = 77 /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details); 78 switch (innerEvent[1]) { 79 case 'start': 80 this.gestureOpenSlice('GestureLog', ts, {name: innerEvent[2]}); 81 break; 82 case 'end': 83 this.gestureCloseSlice('GestureLog', ts); 84 } 85 return true; 86 }, 87 88 /** 89 * For SyncInterpret events, events will come in pairs with 90 * a tag SyncInterpret: 91 * like this: 92 * tracing_mark_write: SyncInterpret: start: ClickWiggleFilterInterpreter 93 * tracing_mark_write: SyncInterpret: end: ClickWiggleFilterInterpreter 94 * which represent the start and the end time of SyncInterpret function 95 * inside the certain interpreter in the gesture library. 96 * Take the logs above for example, they are the start and end time 97 * of the SyncInterpret function inside ClickWiggleFilterInterpreter 98 */ 99 syncEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 100 var innerEvent = /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details); 101 switch (innerEvent[1]) { 102 case 'start': 103 this.gestureOpenSlice('SyncInterpret', ts, 104 {interpreter: innerEvent[2]}); 105 break; 106 case 'end': 107 this.gestureCloseSlice('SyncInterpret', ts); 108 } 109 return true; 110 }, 111 112 /** 113 * For HandleTimer events, events will come in pairs with 114 * a tag HandleTimer: 115 * like this: 116 * tracing_mark_write: HandleTimer: start: LookaheadFilterInterpreter 117 * tracing_mark_write: HandleTimer: end: LookaheadFilterInterpreter 118 * which represent the start and the end time of HandleTimer function 119 * inside the certain interpreter in the gesture library. 120 * Take the logs above for example, they are the start and end time 121 * of the HandleTimer function inside LookaheadFilterInterpreter 122 */ 123 timerEvent: function(eventName, cpuNumber, pid, ts, eventBase) { 124 var innerEvent = /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details); 125 switch (innerEvent[1]) { 126 case 'start': 127 this.gestureOpenSlice('HandleTimer', ts, 128 {interpreter: innerEvent[2]}); 129 break; 130 case 'end': 131 this.gestureCloseSlice('HandleTimer', ts); 132 } 133 return true; 134 } 135 }; 136 137 Parser.register(GestureParser); 138 139 return { 140 GestureParser: GestureParser 141 }; 142}); 143</script> 144 145