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

/**
 * Generates a generalized profile with some samples.
 */
exports.synthesizeProfile = () => {
  const { CATEGORY_MASK } = require("devtools/client/performance/modules/categories");
  const RecordingUtils = require("devtools/shared/performance/recording-utils");

  return RecordingUtils.deflateProfile({
    meta: { version: 2 },
    threads: [{
      samples: [{
        time: 1,
        frames: [
          { category: CATEGORY_MASK("other"), location: "(root)" },
          { category: CATEGORY_MASK("other"), location: "A (http://foo/bar/baz:12)" },
          { category: CATEGORY_MASK("css"), location: "B (http://foo/bar/baz:34)" },
          { category: CATEGORY_MASK("js"), location: "C (http://foo/bar/baz:56)" }
        ]
      }, {
        time: 1 + 1,
        frames: [
          { category: CATEGORY_MASK("other"), location: "(root)" },
          { category: CATEGORY_MASK("other"), location: "A (http://foo/bar/baz:12)" },
          { category: CATEGORY_MASK("css"), location: "B (http://foo/bar/baz:34)" },
          { category: CATEGORY_MASK("gc", 1), location: "D (http://foo/bar/baz:78:9)" }
        ]
      }, {
        time: 1 + 1 + 2,
        frames: [
          { category: CATEGORY_MASK("other"), location: "(root)" },
          { category: CATEGORY_MASK("other"), location: "A (http://foo/bar/baz:12)" },
          { category: CATEGORY_MASK("css"), location: "B (http://foo/bar/baz:34)" },
          { category: CATEGORY_MASK("gc", 1), location: "D (http://foo/bar/baz:78:9)" }
        ]
      }, {
        time: 1 + 1 + 2 + 3,
        frames: [
          { category: CATEGORY_MASK("other"), location: "(root)" },
          { category: CATEGORY_MASK("other"), location: "A (http://foo/bar/baz:12)" },
          { category: CATEGORY_MASK("gc", 2), location: "E (http://foo/bar/baz:90)" },
          { category: CATEGORY_MASK("network"), location: "F (http://foo/bar/baz:99)" }
        ]
      }]
    }]
  });
};

/**
 * Generates a simple implementation for a tree class.
 */
exports.synthesizeCustomTreeClass = () => {
  const { Cu } = require("chrome");
  const { AbstractTreeItem } = Cu.import("resource://devtools/client/shared/widgets/AbstractTreeItem.jsm", {});
  const { Heritage } = require("devtools/client/shared/widgets/view-helpers");

  function MyCustomTreeItem(dataSrc, properties) {
    AbstractTreeItem.call(this, properties);
    this.itemDataSrc = dataSrc;
  }

  MyCustomTreeItem.prototype = Heritage.extend(AbstractTreeItem.prototype, {
    _displaySelf: function (document, arrowNode) {
      let node = document.createElement("hbox");
      node.style.marginInlineStart = (this.level * 10) + "px";
      node.appendChild(arrowNode);
      node.appendChild(document.createTextNode(this.itemDataSrc.label));
      return node;
    },

    _populateSelf: function (children) {
      for (let childDataSrc of this.itemDataSrc.children) {
        children.push(new MyCustomTreeItem(childDataSrc, {
          parent: this,
          level: this.level + 1
        }));
      }
    }
  });

  const myDataSrc = {
    label: "root",
    children: [{
      label: "foo",
      children: []
    }, {
      label: "bar",
      children: [{
        label: "baz",
        children: []
      }]
    }]
  };

  return { MyCustomTreeItem, myDataSrc };
};