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/linux_perf/parser.html">
9
10<script>
11'use strict';
12
13/**
14 * @fileoverview Parses drm driver events in the Linux event trace format.
15 */
16tr.exportTo('tr.e.importer.linux_perf', function() {
17
18  var ColorScheme = tr.b.ColorScheme;
19  var Parser = tr.e.importer.linux_perf.Parser;
20
21  /**
22   * Parses linux irq trace events.
23   * @constructor
24   */
25  function IrqParser(importer) {
26    Parser.call(this, importer);
27
28    importer.registerEventHandler('irq_handler_entry',
29        IrqParser.prototype.irqHandlerEntryEvent.bind(this));
30    importer.registerEventHandler('irq_handler_exit',
31        IrqParser.prototype.irqHandlerExitEvent.bind(this));
32    importer.registerEventHandler('softirq_raise',
33        IrqParser.prototype.softirqRaiseEvent.bind(this));
34    importer.registerEventHandler('softirq_entry',
35        IrqParser.prototype.softirqEntryEvent.bind(this));
36    importer.registerEventHandler('softirq_exit',
37        IrqParser.prototype.softirqExitEvent.bind(this));
38    importer.registerEventHandler('ipi_entry',
39        IrqParser.prototype.ipiEntryEvent.bind(this));
40    importer.registerEventHandler('ipi_exit',
41        IrqParser.prototype.ipiExitEvent.bind(this));
42  }
43
44  // Matches the irq_handler_entry record
45  var irqHandlerEntryRE = /irq=(\d+) name=(.+)/;
46
47  // Matches the irq_handler_exit record
48  var irqHandlerExitRE = /irq=(\d+) ret=(.+)/;
49
50  // Matches the softirq_raise record
51  var softirqRE = /vec=(\d+) \[action=(.+)\]/;
52
53  // Matches the ipi_exit_
54  var ipiHandlerExitRE = /\((.+)\)/;
55
56  IrqParser.prototype = {
57    __proto__: Parser.prototype,
58
59    /**
60     * Parses irq events and sets up state in the mporter.
61     */
62    irqHandlerEntryEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
63      var event = irqHandlerEntryRE.exec(eventBase.details);
64      if (!event)
65        return false;
66
67      var irq = parseInt(event[1]);
68      var name = event[2];
69
70      var thread = this.importer.getOrCreatePseudoThread(
71          'irqs cpu ' + cpuNumber);
72      thread.lastEntryTs = ts;
73      thread.irqName = name;
74
75      return true;
76    },
77
78    irqHandlerExitEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
79      var event = irqHandlerExitRE.exec(eventBase.details);
80      if (!event)
81        return false;
82
83      var irq = parseInt(event[1]);
84      var ret = event[2];
85      var thread = this.importer.getOrCreatePseudoThread(
86          'irqs cpu ' + cpuNumber);
87
88      if (thread.lastEntryTs !== undefined) {
89        var duration = ts - thread.lastEntryTs;
90        var slice = new tr.model.Slice(
91            '',
92            'IRQ (' + thread.irqName + ')',
93            ColorScheme.getColorIdForGeneralPurposeString(event[1]),
94            thread.lastEntryTs, { ret: ret },
95            duration);
96        thread.thread.sliceGroup.pushSlice(slice);
97      }
98      thread.lastEntryTs = undefined;
99      thread.irqName = undefined;
100      return true;
101    },
102
103    softirqRaiseEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
104      return true;
105    },
106
107    softirqEntryEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
108      var event = softirqRE.exec(eventBase.details);
109      if (!event)
110        return false;
111
112      var action = event[2];
113      var thread = this.importer.getOrCreatePseudoThread(
114          'softirq cpu ' + cpuNumber);
115      thread.lastEntryTs = ts;
116
117      return true;
118    },
119
120    softirqExitEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
121      var event = softirqRE.exec(eventBase.details);
122      if (!event)
123        return false;
124
125      var vec = parseInt(event[1]);
126      var action = event[2];
127      var thread = this.importer.getOrCreatePseudoThread(
128          'softirq cpu ' + cpuNumber);
129
130      if (thread.lastEntryTs !== undefined) {
131        var duration = ts - thread.lastEntryTs;
132        var slice = new tr.model.Slice(
133            '', action,
134            ColorScheme.getColorIdForGeneralPurposeString(event[1]),
135            thread.lastEntryTs, { vec: vec },
136            duration);
137        thread.thread.sliceGroup.pushSlice(slice);
138      }
139      thread.lastEntryTs = undefined;
140      return true;
141    },
142    /**
143     * Parses ipi events and sets up state in the mporter.
144     */
145    ipiEntryEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
146      var thread = this.importer.getOrCreatePseudoThread(
147          'irqs cpu ' + cpuNumber);
148      thread.lastEntryTs = ts;
149
150      return true;
151    },
152
153    ipiExitEvent: function(eventName, cpuNumber, pid, ts, eventBase) {
154      var event = ipiHandlerExitRE.exec(eventBase.details);
155      if (!event)
156        return false;
157
158      var ipiName = event[1];
159      var thread = this.importer.getOrCreatePseudoThread(
160          'irqs cpu ' + cpuNumber);
161
162      if (thread.lastEntryTs !== undefined) {
163        var duration = ts - thread.lastEntryTs;
164        var slice = new tr.model.Slice(
165            '',
166            'IPI (' + ipiName + ')',
167            ColorScheme.getColorIdForGeneralPurposeString(ipiName),
168            thread.lastEntryTs,
169            {},
170            duration);
171        thread.thread.sliceGroup.pushSlice(slice);
172      }
173      thread.lastEntryTs = undefined;
174      return true;
175    }
176  };
177
178  Parser.register(IrqParser);
179
180  return {
181    IrqParser: IrqParser
182  };
183});
184</script>
185