github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/util/flamebearer.ts (about)

     1  function deltaDiffWrapper(format: 'single' | 'double', levels: number[][]) {
     2    const mutable_levels = [...levels];
     3  
     4    function deltaDiff(levels: number[][], start: number, step: number) {
     5      for (const level of levels) {
     6        let prev = 0;
     7        for (let i = start; i < level.length; i += step) {
     8          level[i] += prev;
     9          prev = level[i] + level[i + 1];
    10        }
    11      }
    12    }
    13  
    14    if (format === 'double') {
    15      deltaDiff(mutable_levels, 0, 7);
    16      deltaDiff(mutable_levels, 3, 7);
    17    } else {
    18      deltaDiff(mutable_levels, 0, 4);
    19    }
    20  
    21    return mutable_levels;
    22  }
    23  
    24  export { deltaDiffWrapper };