Home | History | Annotate | Download | only in src
      1 // Copyright (c) 2012 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 /**
      8  * @fileoverview Model is a parsed representation of the
      9  * TraceEvents obtained from base/trace_event in which the begin-end
     10  * tokens are converted into a hierarchy of processes, threads,
     11  * subrows, and slices.
     12  *
     13  * The building block of the model is a slice. A slice is roughly
     14  * equivalent to function call executing on a specific thread. As a
     15  * result, slices may have one or more subslices.
     16  *
     17  * A thread contains one or more subrows of slices. Row 0 corresponds to
     18  * the "root" slices, e.g. the topmost slices. Row 1 contains slices that
     19  * are nested 1 deep in the stack, and so on. We use these subrows to draw
     20  * nesting tasks.
     21  *
     22  */
     23 'use strict';
     24 base.exportTo('base', function() {
     25 
     26   function Range() {
     27     this.isEmpty_ = true;
     28     this.min_ = undefined;
     29     this.max_ = undefined;
     30   };
     31 
     32   Range.prototype = {
     33     __proto__: Object.prototype,
     34 
     35     reset: function() {
     36       this.isEmpty_ = true;
     37       this.min_ = undefined;
     38       this.max_ = undefined;
     39     },
     40 
     41     get isEmpty() {
     42       return this.isEmpty_;
     43     },
     44 
     45     addRange: function(range) {
     46       if (range.isEmpty)
     47         return;
     48       this.addValue(range.min);
     49       this.addValue(range.max);
     50     },
     51 
     52     addValue: function(value) {
     53       if (this.isEmpty_) {
     54         this.max_ = value;
     55         this.min_ = value;
     56         this.isEmpty_ = false;
     57         return;
     58       }
     59       this.max_ = Math.max(this.max_, value);
     60       this.min_ = Math.min(this.min_, value);
     61     },
     62 
     63     get min() {
     64       if (this.isEmpty_)
     65         return undefined;
     66       return this.min_;
     67     },
     68 
     69     get max() {
     70       if (this.isEmpty_)
     71         return undefined;
     72       return this.max_;
     73     },
     74   };
     75 
     76   return {
     77     Range: Range
     78   };
     79 
     80 });
     81