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
8<link rel="import" href="/tracing/extras/importer/etw/parser.html">
9
10<script>
11'use strict';
12
13/**
14 * @fileoverview Parses EventTrace events in the Windows event trace format.
15 */
16
17tr.exportTo('tr.e.importer.etw', function() {
18  var Parser = tr.e.importer.etw.Parser;
19
20  // Constants for EventTrace events.
21  var guid = '68FDD900-4A3E-11D1-84F4-0000F80464E3';
22  var kEventTraceHeaderOpcode = 0;
23
24  /**
25   * Parses Windows EventTrace trace events.
26   * @constructor
27   */
28  function EventTraceParser(importer) {
29    Parser.call(this, importer);
30
31    // Register handlers.
32    importer.registerEventHandler(guid, kEventTraceHeaderOpcode,
33        EventTraceParser.prototype.decodeHeader.bind(this));
34  }
35
36  EventTraceParser.prototype = {
37    __proto__: Parser.prototype,
38
39    decodeFields: function(header, decoder) {
40      if (header.version != 2)
41        throw new Error('Incompatible EventTrace event version.');
42
43      var bufferSize = decoder.decodeUInt32();
44      var version = decoder.decodeUInt32();
45      var providerVersion = decoder.decodeUInt32();
46      var numberOfProcessors = decoder.decodeUInt32();
47      var endTime = decoder.decodeUInt64ToString();
48      var timerResolution = decoder.decodeUInt32();
49      var maxFileSize = decoder.decodeUInt32();
50      var logFileMode = decoder.decodeUInt32();
51      var buffersWritten = decoder.decodeUInt32();
52      var startBuffers = decoder.decodeUInt32();
53      var pointerSize = decoder.decodeUInt32();
54      var eventsLost = decoder.decodeUInt32();
55      var cpuSpeed = decoder.decodeUInt32();
56      var loggerName = decoder.decodeUInteger(header.is64);
57      var logFileName = decoder.decodeUInteger(header.is64);
58      var timeZoneInformation = decoder.decodeTimeZoneInformation();
59      var padding = decoder.decodeUInt32();
60      var bootTime = decoder.decodeUInt64ToString();
61      var perfFreq = decoder.decodeUInt64ToString();
62      var startTime = decoder.decodeUInt64ToString();
63      var reservedFlags = decoder.decodeUInt32();
64      var buffersLost = decoder.decodeUInt32();
65      var sessionNameString = decoder.decodeW16String();
66      var logFileNameString = decoder.decodeW16String();
67
68      return {
69        bufferSize: bufferSize,
70        version: version,
71        providerVersion: providerVersion,
72        numberOfProcessors: numberOfProcessors,
73        endTime: endTime,
74        timerResolution: timerResolution,
75        maxFileSize: maxFileSize,
76        logFileMode: logFileMode,
77        buffersWritten: buffersWritten,
78        startBuffers: startBuffers,
79        pointerSize: pointerSize,
80        eventsLost: eventsLost,
81        cpuSpeed: cpuSpeed,
82        loggerName: loggerName,
83        logFileName: logFileName,
84        timeZoneInformation: timeZoneInformation,
85        bootTime: bootTime,
86        perfFreq: perfFreq,
87        startTime: startTime,
88        reservedFlags: reservedFlags,
89        buffersLost: buffersLost,
90        sessionNameString: sessionNameString,
91        logFileNameString: logFileNameString
92      };
93    },
94
95    decodeHeader: function(header, decoder) {
96      var fields = this.decodeFields(header, decoder);
97      // TODO(etienneb): Update the Model with |fields|.
98      return true;
99    }
100
101  };
102
103  Parser.register(EventTraceParser);
104
105  return {
106    EventTraceParser: EventTraceParser
107  };
108});
109</script>
110
111