1<!DOCTYPE html>
2<!--
3Copyright (c) 2015 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/ui/tracks/chart_track.html">
9<link rel="import" href="/tracing/ui/tracks/container_track.html">
10<link rel="import" href="/tracing/ui/tracks/memory_dump_track_util.html">
11
12<script>
13'use strict';
14
15tr.exportTo('tr.ui.tracks', function() {
16
17  var ALLOCATED_MEMORY_TRACK_HEIGHT = 50;
18
19  /**
20   * A track that displays an array of ProcessMemoryDump objects.
21   * @constructor
22   * @extends {ContainerTrack}
23   */
24  var ProcessMemoryDumpTrack = tr.ui.b.define(
25      'process-memory-dump-track', tr.ui.tracks.ContainerTrack);
26
27  ProcessMemoryDumpTrack.prototype = {
28    __proto__: tr.ui.tracks.ContainerTrack.prototype,
29
30    decorate: function(viewport) {
31      tr.ui.tracks.ContainerTrack.prototype.decorate.call(this, viewport);
32      this.memoryDumps_ = undefined;
33    },
34
35    get memoryDumps() {
36      return this.memoryDumps_;
37    },
38
39    set memoryDumps(memoryDumps) {
40      this.memoryDumps_ = memoryDumps;
41      this.updateContents_();
42    },
43
44    updateContents_: function() {
45      this.clearTracks_();
46
47      // Show no tracks if there are no dumps.
48      if (!this.memoryDumps_ || !this.memoryDumps_.length)
49        return;
50
51      this.appendAllocatedMemoryTrack_();
52    },
53
54    appendAllocatedMemoryTrack_: function() {
55      var series = tr.ui.tracks.buildProcessAllocatedMemoryChartSeries(
56          this.memoryDumps_);
57      if (!series)
58        return;
59
60      var track = new tr.ui.tracks.ChartTrack(this.viewport);
61      track.heading = 'Memory per component';
62      track.height = ALLOCATED_MEMORY_TRACK_HEIGHT + 'px';
63      track.series = series;
64      track.autoSetAllAxes({expandMax: true});
65      this.appendChild(track);
66    }
67  };
68
69  return {
70    ProcessMemoryDumpTrack: ProcessMemoryDumpTrack
71  };
72});
73</script>
74