Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / importer / etw / parser.js
1 // Copyright (c) 2014 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 Base class for Windows ETW event parsers.
9  *
10  * The ETW trace event importer depends on subclasses of
11  * Parser to parse event data.  Each subclass corresponds
12  * to a group of trace events; e.g. Thread and Process implements
13  * decoding of scheduling events.  Parser subclasses must
14  * call Parser.registerSubtype to arrange to be instantiated
15  * and their constructor must register their event handlers with the
16  * importer.  For example,
17  *
18  * var Parser = tracing.importer.etw.Parser;
19  *
20  * function ThreadParser(importer) {
21  *   Parser.call(this, importer);
22  *
23  *   importer.registerEventHandler(guid, kThreadStartOpcode,
24  *       ThreadParser.prototype.decodeStart.bind(this));
25  *   importer.registerEventHandler(guid, kThreadEndOpcode,
26  *       ThreadParser.prototype.decodeEnd.bind(this));
27  * }
28  *
29  * Parser.registerSubtype(ThreadParser);
30  *
31  * When a registered event is found, the associated event handler is invoked:
32  *
33  *   decodeStart: function(header, decoder) {
34  *     [...]
35  *     return true;
36  *   },
37  *
38  * If the routine returns false the caller will generate an import error
39  * saying there was a problem parsing it.  Handlers can also emit import
40  * messages using this.importer.model.importWarning.  If this is done in lieu of
41  * the generic import error it may be desirable for the handler to return
42  * true.
43  *
44  */
45 tvcm.exportTo('tracing.importer.etw', function() {
46
47   var subtypeConstructors = [];
48
49   /**
50    * Registers a subclass that will help parse Windows ETW events.
51    * The importer will call createParsers (below) before importing
52    * data so each subclass can register its handlers.
53    *
54    * @param {Function} subtypeConstructor The subtype's constructor function.
55    */
56   Parser.registerSubtype = function(subtypeConstructor) {
57     subtypeConstructors.push(subtypeConstructor);
58   };
59
60   Parser.getSubtypeConstructors = function() {
61     return subtypeConstructors;
62   };
63
64   /**
65    * Parses Windows ETW events.
66    * @constructor
67    */
68   function Parser(importer) {
69     this.importer = importer;
70     this.model = importer.model;
71   }
72
73   Parser.prototype = {
74     __proto__: Object.prototype
75   };
76
77   return {
78     Parser: Parser
79   };
80
81 });