Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / timed_event.js
1 // Copyright (c) 2013 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 tvcm.require('tvcm.guid');
8 tvcm.require('tracing.trace_model.event');
9
10 /**
11  * @fileoverview Provides the TimedEvent class.
12  */
13 tvcm.exportTo('tracing.trace_model', function() {
14   /**
15    * A TimedEvent is the base type for any piece of data in the trace model with
16    * a specific start and duration.
17    *
18    * @constructor
19    */
20   function TimedEvent(start) {
21     tracing.trace_model.Event.call(this);
22     this.start = start;
23     this.duration = 0;
24   }
25
26   TimedEvent.prototype = {
27     __proto__: tracing.trace_model.Event.prototype,
28
29     get end() {
30       return this.start + this.duration;
31     },
32
33     addBoundsToRange: function(range) {
34       range.addValue(this.start);
35       range.addValue(this.end);
36     },
37
38     bounds: function(that) {
39       // Due to inaccuracy of floating-point calculation, the end times of
40       // slices from a B/E pair (whose end = start + original_end - start)
41       // and an X event (whose end = start + duration) at the same time may
42       // become not equal. Round back to micros (which is the source data
43       // precision) to ensure equality below.
44       var this_end_micros = Math.round(this.end * 1000);
45       var that_end_micros = Math.round(that.end * 1000);
46       return this.start <= that.start && this_end_micros >= that_end_micros;
47     }
48   };
49
50   return {
51     TimedEvent: TimedEvent
52   };
53 });