1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 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/model/timed_event.html">
9<link rel="import" href="/tracing/value/unit.html">
10
11<script>
12'use strict';
13
14tr.exportTo('tr.model', function() {
15  var InstantEventType = {
16    GLOBAL: 1,
17    PROCESS: 2
18  };
19
20  /**
21   * An InstantEvent is a zero-duration event.
22   *
23   * @constructor
24   */
25  function InstantEvent(category, title, colorId, start, args) {
26    tr.model.TimedEvent.call(this, start);
27
28    this.category = category || '';
29    this.title = title;
30    this.colorId = colorId;
31    this.args = args;
32
33    this.type = undefined;
34  };
35
36  InstantEvent.prototype = {
37    __proto__: tr.model.TimedEvent.prototype
38  };
39
40  /**
41   * A GlobalInstantEvent is a zero-duration event that's not tied to any
42   * particular process.
43   *
44   * An example is a trace event that's issued when a new USB device is plugged
45   * into the machine.
46   *
47   * @constructor
48   */
49  function GlobalInstantEvent(category, title, colorId, start, args) {
50    InstantEvent.apply(this, arguments);
51    this.type = InstantEventType.GLOBAL;
52  };
53
54  GlobalInstantEvent.prototype = {
55    __proto__: InstantEvent.prototype,
56    get userFriendlyName() {
57      return 'Global instant event ' + this.title + ' @ ' +
58          tr.v.Unit.byName.timeStampInMs.format(start);
59    }
60  };
61
62  /**
63   * A ProcessInstantEvent is a zero-duration event that's tied to a
64   * particular process.
65   *
66   * An example is a trace event that's issued when a kill signal is received.
67   *
68   * @constructor
69   */
70  function ProcessInstantEvent(category, title, colorId, start, args) {
71    InstantEvent.apply(this, arguments);
72    this.type = InstantEventType.PROCESS;
73  };
74
75  ProcessInstantEvent.prototype = {
76    __proto__: InstantEvent.prototype,
77
78    get userFriendlyName() {
79      return 'Process-level instant event ' + this.title + ' @ ' +
80          tr.v.Unit.byName.timeStampInMs.format(start);
81    }
82  };
83
84  tr.model.EventRegistry.register(
85      InstantEvent,
86      {
87        name: 'instantEvent',
88        pluralName: 'instantEvents',
89        singleViewElementName: 'tr-ui-a-single-instant-event-sub-view',
90        multiViewElementName: 'tr-ui-a-multi-instant-event-sub-view'
91      });
92
93  return {
94    GlobalInstantEvent: GlobalInstantEvent,
95    ProcessInstantEvent: ProcessInstantEvent,
96
97    InstantEventType: InstantEventType,
98    InstantEvent: InstantEvent
99  };
100});
101</script>
102
103