a4d2cb92bdb6ffab5de4b4ad7f68fb1fd67cab5b
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / importer / linux_perf / gesture_parser.js
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.model.importWarning({
50             type: 'title_match_error',
51             message: 'Titles do not match. Title is ' +
52                 slice.title + ' in openSlice, and is ' +
53                 title + ' in endSlice'
54           });
55         } else {
56           thread.sliceGroup.endSlice(ts);
57         }
58       }
59     },
60
61     /**
62      * For log events, events will come in pairs with a tag log:
63      * like this:
64      * tracing_mark_write: log: start: TimerLogOutputs
65      * tracing_mark_write: log: end: TimerLogOutputs
66      * which represent the start and the end time of certain log behavior
67      * Take these logs above for example, they are the start and end time
68      * of logging Output for HandleTimer function
69      */
70     logEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
71       var innerEvent =
72           /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details);
73       switch (innerEvent[1]) {
74         case 'start':
75           this.gestureOpenSlice('GestureLog', ts, {name: innerEvent[2]});
76           break;
77         case 'end':
78           this.gestureCloseSlice('GestureLog', ts);
79       }
80       return true;
81     },
82
83     /**
84      * For SyncInterpret events, events will come in pairs with
85      * a tag SyncInterpret:
86      * like this:
87      * tracing_mark_write: SyncInterpret: start: ClickWiggleFilterInterpreter
88      * tracing_mark_write: SyncInterpret: end: ClickWiggleFilterInterpreter
89      * which represent the start and the end time of SyncInterpret function
90      * inside the certain interpreter in the gesture library.
91      * Take the logs above for example, they are the start and end time
92      * of the SyncInterpret function inside ClickWiggleFilterInterpreter
93      */
94     syncEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
95       var innerEvent = /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details);
96       switch (innerEvent[1]) {
97         case 'start':
98           this.gestureOpenSlice('SyncInterpret', ts,
99                                 {interpreter: innerEvent[2]});
100           break;
101         case 'end':
102           this.gestureCloseSlice('SyncInterpret', ts);
103       }
104       return true;
105     },
106
107     /**
108      * For HandleTimer events, events will come in pairs with
109      * a tag HandleTimer:
110      * like this:
111      * tracing_mark_write: HandleTimer: start: LookaheadFilterInterpreter
112      * tracing_mark_write: HandleTimer: end: LookaheadFilterInterpreter
113      * which represent the start and the end time of HandleTimer function
114      * inside the certain interpreter in the gesture library.
115      * Take the logs above for example, they are the start and end time
116      * of the HandleTimer function inside LookaheadFilterInterpreter
117      */
118     timerEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
119       var innerEvent = /^\s*(\w+):\s*(\w+)$/.exec(eventBase.details);
120       switch (innerEvent[1]) {
121         case 'start':
122           this.gestureOpenSlice('HandleTimer', ts,
123                                 {interpreter: innerEvent[2]});
124           break;
125         case 'end':
126           this.gestureCloseSlice('HandleTimer', ts);
127       }
128       return true;
129     }
130   };
131
132   Parser.registerSubtype(GestureParser);
133
134   return {
135     GestureParser: GestureParser
136   };
137 });