summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/ui/analysis/container_memory_dump_sub_view_test.html
blob: 92be2bedc27327d1da16072c841fe7bfc4e6504c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/model/event_set.html">
<link rel="import"
    href="/tracing/ui/analysis/container_memory_dump_sub_view.html">
<link rel="import"
    href="/tracing/ui/analysis/memory_dump_sub_view_test_utils.html">
<link rel="import" href="/tracing/ui/base/deep_utils.html">
<link rel="import" href="/tracing/ui/brushing_state_controller.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const EventSet = tr.model.EventSet;
  const extractVmRegions = tr.ui.analysis.extractVmRegions;
  const extractMemoryAllocatorDumps =
    tr.ui.analysis.extractMemoryAllocatorDumps;
  const extractHeapDumps = tr.ui.analysis.extractHeapDumps;

  function createViewWithSelection(selection, opt_parentElement) {
    const viewEl = document.createElement(
        'tr-ui-a-container-memory-dump-sub-view');
    if (opt_parentElement) {
      Polymer.dom(opt_parentElement).appendChild(viewEl);
    }
    if (selection === undefined) {
      viewEl.selection = undefined;
    } else {
      // Rotate the list of selected dumps to check that the sub-view sorts
      // them properly.
      const length = selection.length;
      viewEl.selection = new tr.model.EventSet(
          selection.slice(length / 2, length).concat(
              selection.slice(0, length / 2)));
    }
    return viewEl;
  }

  function createAndCheckContainerMemoryDumpView(
      test, containerMemoryDumps, detailsCheckCallback, opt_parentElement) {
    const viewEl =
        createViewWithSelection(containerMemoryDumps, opt_parentElement);
    if (!opt_parentElement) {
      test.addHTMLOutput(viewEl);
    }

    // The view should contain a stacked pane view with memory dump header and
    // overview panes.
    const stackedPaneViewEl = tr.ui.b.findDeepElementMatching(
        viewEl, 'tr-ui-a-stacked-pane-view');
    const headerPaneEl = tr.ui.b.findDeepElementMatching(
        stackedPaneViewEl, 'tr-ui-a-memory-dump-header-pane');
    const overviewPaneEl = tr.ui.b.findDeepElementMatching(
        stackedPaneViewEl, 'tr-ui-a-memory-dump-overview-pane');

    // Check that the header pane and overview pane are correctly set up.
    const processMemoryDumps = containerMemoryDumps.map(
        containerDump => containerDump.processMemoryDumps);
    assert.deepEqual(
        Array.from(headerPaneEl.containerMemoryDumps), containerMemoryDumps);
    assert.deepEqual(overviewPaneEl.processMemoryDumps, processMemoryDumps);
    assert.strictEqual(
        overviewPaneEl.aggregationMode, headerPaneEl.aggregationMode);

    // Get the overview pane table to drive the details pane checks.
    const overviewTableEl = tr.ui.b.findDeepElementMatching(
        overviewPaneEl, 'tr-ui-b-table');

    function checkVmRegionsPane(pid) {
      const detailsPaneEl = tr.ui.b.findDeepElementMatching(
          stackedPaneViewEl, 'tr-ui-a-memory-dump-vm-regions-details-pane');
      if (pid === undefined) {
        assert.isUndefined(detailsPaneEl);
      } else {
        assert.deepEqual(Array.from(detailsPaneEl.vmRegions),
            extractVmRegions(processMemoryDumps, pid));
        assert.strictEqual(
            detailsPaneEl.aggregationMode, headerPaneEl.aggregationMode);
      }
    }

    function checkAllocatorPane(pid, allocatorName, withHeapDetailsPane) {
      const allocatorDetailsPaneEl = tr.ui.b.findDeepElementMatching(
          stackedPaneViewEl, 'tr-ui-a-memory-dump-allocator-details-pane');
      if (pid === undefined) {
        assert.isUndefined(allocatorDetailsPaneEl);
        assert.isUndefined(allocatorName);  // Test sanity check.
        assert.isUndefined(withHeapDetailsPane);  // Test sanity check.
        return;
      }

      assert.deepEqual(
          Array.from(allocatorDetailsPaneEl.memoryAllocatorDumps),
          extractMemoryAllocatorDumps(processMemoryDumps, pid, allocatorName));
      assert.strictEqual(
          allocatorDetailsPaneEl.aggregationMode, headerPaneEl.aggregationMode);

      const heapDetailsPaneEl = tr.ui.b.findDeepElementMatching(
          stackedPaneViewEl, 'tr-ui-a-memory-dump-heap-details-pane');
      if (!withHeapDetailsPane) {
        assert.isUndefined(heapDetailsPaneEl);
        return;
      }

      assert.deepEqual(Array.from(heapDetailsPaneEl.heapDumps),
          extractHeapDumps(processMemoryDumps, pid, allocatorName));
      assert.strictEqual(
          heapDetailsPaneEl.aggregationMode, headerPaneEl.aggregationMode);
    }

    detailsCheckCallback(
        overviewTableEl, checkVmRegionsPane, checkAllocatorPane);
  }

  test('instantiate_empty', function() {
    // All these views should be completely empty.
    const unsetViewEl = document.createElement(
        'tr-ui-a-container-memory-dump-sub-view');
    this.addHTMLOutput(unsetViewEl);
    assert.strictEqual(unsetViewEl.getBoundingClientRect().width, 0);
    assert.strictEqual(unsetViewEl.getBoundingClientRect().height, 0);

    const undefinedViewEl = createViewWithSelection(undefined);
    this.addHTMLOutput(undefinedViewEl);
    assert.strictEqual(undefinedViewEl.getBoundingClientRect().width, 0);
    assert.strictEqual(undefinedViewEl.getBoundingClientRect().height, 0);

    const emptyViewEl = createViewWithSelection([]);
    this.addHTMLOutput(emptyViewEl);
    assert.strictEqual(emptyViewEl.getBoundingClientRect().width, 0);
    assert.strictEqual(emptyViewEl.getBoundingClientRect().height, 0);
  });

  test('instantiate_singleGlobalMemoryDump', function() {
    createAndCheckContainerMemoryDumpView(this,
        [tr.ui.analysis.createSingleTestGlobalMemoryDump()],
        function(overviewTableEl, checkVmRegionsPane, checkAllocatorPane) {
          // Nothing should be selected initially.
          assert.isUndefined(overviewTableEl.selectedTableRow);
          assert.isUndefined(overviewTableEl.selectedColumnIndex);
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Total resident of Process 1.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[0];
          overviewTableEl.selectedColumnIndex = 1;
          checkVmRegionsPane(1 /* PID */);
          checkAllocatorPane(undefined);

          // PSS of process 4.
          overviewTableEl.selectedColumnIndex = 3;
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[2];
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Malloc of process 2.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[1];
          overviewTableEl.selectedColumnIndex = 10;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'malloc',
              false /* no heap details pane */);
        });
  });

  test('instantiate_multipleGlobalMemoryDumps', function() {
    createAndCheckContainerMemoryDumpView(this,
        tr.ui.analysis.createMultipleTestGlobalMemoryDumps(),
        function(overviewTableEl, checkVmRegionsPane, checkAllocatorPane) {
          // Nothing should be selected initially.
          assert.isUndefined(overviewTableEl.selectedTableRow);
          assert.isUndefined(overviewTableEl.selectedColumnIndex);
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Blink of Process 1.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[0];
          overviewTableEl.selectedColumnIndex = 8;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Peak total resident of Process 4.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[3];
          overviewTableEl.selectedColumnIndex = 2;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // V8 of Process 3.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[2];
          overviewTableEl.selectedColumnIndex = 12;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(3 /* PID */, 'v8', true /* heap details pane */);
        });
  });

  test('instantiate_singleProcessMemoryDump', function() {
    createAndCheckContainerMemoryDumpView(this,
        [tr.ui.analysis.createSingleTestProcessMemoryDump()],
        function(overviewTableEl, checkVmRegionsPane, checkAllocatorPane) {
          // Nothing should be selected initially.
          assert.isUndefined(overviewTableEl.selectedTableRow);
          assert.isUndefined(overviewTableEl.selectedColumnIndex);
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Tracing of Process 2.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[0];
          overviewTableEl.selectedColumnIndex = 13;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'tracing',
              false /* no heap details pane */);

          // Blink of Process 2.
          overviewTableEl.selectedColumnIndex = 8;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'blink',
              false /* no heap details pane */);

          // Total resident of Process 2.
          overviewTableEl.selectedColumnIndex = 1;
          checkVmRegionsPane(2 /* PID */);
          checkAllocatorPane(undefined);
        });
  });

  test('instantiate_multipleProcessMemoryDumps', function() {
    createAndCheckContainerMemoryDumpView(this,
        tr.ui.analysis.createMultipleTestProcessMemoryDumps(),
        function(overviewTableEl, checkVmRegionsPane, checkAllocatorPane) {
          // Nothing should be selected initially.
          assert.isUndefined(overviewTableEl.selectedTableRow);
          assert.isUndefined(overviewTableEl.selectedColumnIndex);
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Tracing of Process 2.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[0];
          overviewTableEl.selectedColumnIndex = 13;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'tracing',
              false /* no heap details pane */);

          // V8 of Process 2.
          overviewTableEl.selectedColumnIndex = 12;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'v8',
              false /* no heap details pane */);

          // PSS of Process 2.
          overviewTableEl.selectedColumnIndex = 3;
          checkVmRegionsPane(2 /* PID */);
          checkAllocatorPane(undefined);
        });
  });

  test('memory', function() {
    const containerEl = document.createElement('div');
    containerEl.brushingStateController =
        new tr.c.BrushingStateController(undefined);

    // Create the first container memory view.
    createAndCheckContainerMemoryDumpView(this,
        [tr.ui.analysis.createSingleTestProcessMemoryDump()],
        function(overviewTableEl, checkVmRegionsPane, checkAllocatorPane) {
          // Nothing should be selected initially.
          assert.isUndefined(overviewTableEl.selectedTableRow);
          assert.isUndefined(overviewTableEl.selectedColumnIndex);
          checkVmRegionsPane(undefined);
          checkAllocatorPane(undefined);

          // Select V8 of Process 2.
          overviewTableEl.selectedTableRow = overviewTableEl.tableRows[0];
          overviewTableEl.selectedColumnIndex = 12;
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'v8',
              false /* no heap details pane */);
        }, containerEl);

    // Destroy the first container memory view.
    Polymer.dom(containerEl).textContent = '';

    // Create the second container memory view.
    createAndCheckContainerMemoryDumpView(this,
        tr.ui.analysis.createMultipleTestGlobalMemoryDumps(),
        function(overviewTableEl, checkVmRegionsPane, checkAllocatorPane) {
          // V8 of Process 2 should still be selected (even though the selection
          // changed).
          assert.strictEqual(
              overviewTableEl.selectedTableRow, overviewTableEl.tableRows[1]);
          assert.strictEqual(overviewTableEl.selectedColumnIndex, 12);
          checkVmRegionsPane(undefined);
          checkAllocatorPane(2 /* PID */, 'v8',
              false /* no heap details pane */);
        }, containerEl);
  });

  // See https://crbug.com/1143376.
  skipTest('instantiate_differentProcessMemoryDumps', function() {
    const globalMemoryDumps =
        tr.ui.analysis.createMultipleTestGlobalMemoryDumps();
    // 2 dumps in Process 1, 3 dumps in Process 2, and 1 dump in Process 4
    // (intentionally shuffled to check sorting).
    const differentProcessDumps = [
      globalMemoryDumps[1].processMemoryDumps[2],
      globalMemoryDumps[0].processMemoryDumps[1],
      globalMemoryDumps[0].processMemoryDumps[2],
      globalMemoryDumps[1].processMemoryDumps[4],
      globalMemoryDumps[1].processMemoryDumps[1],
      globalMemoryDumps[2].processMemoryDumps[2]
    ];

    const viewEl = createViewWithSelection(differentProcessDumps);
    this.addHTMLOutput(viewEl);

    const tableEl = tr.ui.b.findDeepElementMatching(viewEl, 'tr-ui-b-table');
    assert.lengthOf(tableEl.tableRows, 3);
    assert.lengthOf(tableEl.tableColumns, 1);
    const rows = tableEl.tableRows;
    const col = tableEl.tableColumns[0];

    assert.strictEqual(Polymer.dom(col.value(rows[0])).textContent,
        '2 memory dumps in Process 1');
    assert.strictEqual(Polymer.dom(col.value(rows[1])).textContent,
        '3 memory dumps in Process 2');
    assert.strictEqual(Polymer.dom(col.value(rows[2])).textContent,
        '1 memory dump in Process 4');

    // Check that the analysis link is associated with the right dumps.
    assert.isTrue(col.value(rows[1]).selection.equals(new tr.model.EventSet([
      globalMemoryDumps[0].processMemoryDumps[2],
      globalMemoryDumps[1].processMemoryDumps[2],
      globalMemoryDumps[2].processMemoryDumps[2]
    ])));

    assert.lengthOf(rows[1].subRows, 3);
    const subRow = rows[1].subRows[0];

    // Check the timestamp.
    assert.strictEqual(col.value(subRow).children[0].value, 42);

    // Check that the analysis link is associated with the right dump.
    assert.isTrue(col.value(subRow).selection.equals(
        new tr.model.EventSet(globalMemoryDumps[0].processMemoryDumps[2])));
  });
});
</script>