genFramesFromTreeData()

in frontend/src/components/jfr/flame-graph.js [1315:1372]


    genFramesFromTreeData() {
      const queue = [];
      let dataSource = this.$dataSource;

      const process = (parent, frame) => {
        let child = parent.addChild(frame);

        let weights = this.$$weightsExtractor(dataSource, frame);
        let selfWeight,
          weight,
          selfWeightOfBaseline1,
          weightOfBaseline1,
          selfWeightOfBaseline2,
          weightOfBaseline2;
        if (this.$$diff) {
          [selfWeightOfBaseline1, weightOfBaseline1, selfWeightOfBaseline2, weightOfBaseline2] =
            weights;

          child.addSelfWeightOfBaselines(selfWeightOfBaseline1, selfWeightOfBaseline2);
          child.addWeightOfBaselines(weightOfBaseline1, weightOfBaseline2);

          selfWeight = selfWeightOfBaseline1 + selfWeightOfBaseline2;
          weight = weightOfBaseline1 + weightOfBaseline2;
        } else {
          [selfWeight, weight] = weights;
        }

        child.addSelfWeight(selfWeight);
        child.addWeight(weight);

        this.$stackTraceMaxDepth = Math.max(this.$stackTraceMaxDepth, child.depth);

        if (this.$$childFramesCounter(dataSource, frame) > 0) {
          queue.push(child);
        }
        return child;
      };

      const rootFramesCount = this.$$rootFramesCounter(dataSource);
      for (let i = 0; i < rootFramesCount; i++) {
        const rootFrame = process(this.$root, this.$$rootFrameExtractor(dataSource, i));
        this.$totalWeight += rootFrame.weight;
        if (this.$$diff) {
          this.$totalWeightOfBaseline1 += rootFrame.weightOfBaseline1;
          this.$totalWeightOfBaseline2 += rootFrame.weightOfBaseline2;
        }
      }

      this.$root.addWeight(this.$totalWeight);

      while (queue.length > 0) {
        const frame = queue.shift();
        const childrenCount = this.$$childFramesCounter(dataSource, frame.raw);
        for (let i = 0; i < childrenCount; i++) {
          process(frame, this.$$childFrameExtractor(dataSource, frame.raw, i));
        }
      }
    }