github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/packages/pyroscope-flamegraph/src/FlameGraph/FlameGraphComponent/utils.ts (about) 1 /* eslint-disable import/prefer-default-export */ 2 import { doubleFF } from '@pyroscope/models/src'; 3 4 // not entirely sure where this should fit 5 function getRatios( 6 level: number[], 7 j: number, 8 leftTicks: number, 9 rightTicks: number 10 ) { 11 const ff = doubleFF; 12 13 // throw an error 14 // since otherwise there's no way to calculate a diff 15 if (!leftTicks || !rightTicks) { 16 // ideally this should never happen 17 // however there must be a race condition caught in CI 18 // https://github.com/pyroscope-io/pyroscope/pull/439/checks?check_run_id=3808581168 19 console.error( 20 "Properties 'rightTicks' and 'leftTicks' are required. Can't calculate ratio." 21 ); 22 return { leftRatio: 0, rightRatio: 0 }; 23 } 24 25 const leftRatio = ff.getBarTotalLeft(level, j) / leftTicks; 26 const rightRatio = ff.getBarTotalRght(level, j) / rightTicks; 27 28 return { leftRatio, rightRatio }; 29 } 30 31 export { getRatios };