1<!DOCTYPE html>
2<!--
3Copyright (c) 2014 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<link rel="import" href="/tracing/base/base.html">
8<link rel="import" href="/tracing/base/extension_registry.html">
9<script>
10'use strict';
11
12/**
13 * @fileoverview Base class for Windows ETW event parsers.
14 *
15 * The ETW trace event importer depends on subclasses of
16 * Parser to parse event data.  Each subclass corresponds
17 * to a group of trace events; e.g. Thread and Process implements
18 * decoding of scheduling events.  Parser subclasses must
19 * call Parser.register to arrange to be instantiated
20 * and their constructor must register their event handlers with the
21 * importer.  For example,
22 *
23 * var Parser = tr.e.importer.etw.Parser;
24 *
25 * function ThreadParser(importer) {
26 *   Parser.call(this, importer);
27 *
28 *   importer.registerEventHandler(guid, kThreadStartOpcode,
29 *       ThreadParser.prototype.decodeStart.bind(this));
30 *   importer.registerEventHandler(guid, kThreadEndOpcode,
31 *       ThreadParser.prototype.decodeEnd.bind(this));
32 * }
33 *
34 * Parser.register(ThreadParser);
35 *
36 * When a registered event is found, the associated event handler is invoked:
37 *
38 *   decodeStart: function(header, decoder) {
39 *     [...]
40 *     return true;
41 *   },
42 *
43 * If the routine returns false the caller will generate an import error
44 * saying there was a problem parsing it.  Handlers can also emit import
45 * messages using this.importer.model.importWarning.  If this is done in lieu of
46 * the generic import error it may be desirable for the handler to return
47 * true.
48 *
49 */
50tr.exportTo('tr.e.importer.etw', function() {
51  /**
52   * Parses Windows ETW events.
53   * @constructor
54   */
55  function Parser(importer) {
56    this.importer = importer;
57    this.model = importer.model;
58  }
59
60  Parser.prototype = {
61    __proto__: Object.prototype
62  };
63
64  var options = new tr.b.ExtensionRegistryOptions(tr.b.BASIC_REGISTRY_MODE);
65  options.mandatoryBaseClass = Parser;
66  tr.b.decorateExtensionRegistry(Parser, options);
67
68
69  return {
70    Parser: Parser
71  };
72});
73</script>
74