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