summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/unit/test_tree-model-11.js
blob: c665dfe32ff09ccb2c4d1848429b2e9f5a0bd556 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/**
 * Tests that the costs for recursive frames does not overcount the collapsed
 * samples.
 */

function run_test() {
  run_next_test();
}

add_task(function () {
  let { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  let thread = new ThreadNode(gThread, { startTime: 0, endTime: 50,
                                         flattenRecursion: true });

  /**
   * Samples
   *
   * A->B->C
   * A->B->B->B->C
   * A->B
   * A->B->B->B
   */

  [
    // total, self, name
    [ 100, 0, "(root)", [
      [ 100, 0, "A", [
        [ 100, 50, "B", [
          [ 50, 50, "C"]
        ]]
      ]],
    ]],
  ].forEach(compareFrameInfo(thread));
});

function compareFrameInfo(root, parent) {
  parent = parent || root;
  return function (def) {
    let [total, self, name, children] = def;
    let node = getFrameNodePath(parent, name);
    let data = node.getInfo({ root });
    equal(total, data.totalPercentage,
          `${name} has correct total percentage: ${data.totalPercentage}`);
    equal(self, data.selfPercentage,
          `${name} has correct self percentage: ${data.selfPercentage}`);
    if (children) {
      children.forEach(compareFrameInfo(root, node));
    }
  };
}

var gThread = synthesizeProfileForTest([{
  time: 5,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "B" },
    { location: "B" },
    { location: "B" },
    { location: "C" }
  ]
}, {
  time: 10,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "B" },
    { location: "C" }
  ]
}, {
  time: 15,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "B" },
    { location: "B" },
    { location: "B" },
  ]
}, {
  time: 20,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "B" },
  ]
}]);