MCPcopy Create free account
hub / github.com/google/pprof / pprofUnitText

Function pprofUnitText

internal/driver/html/stacks.js:615–638  ·  view source on GitHub ↗
(value, unit)

Source from the content-addressed store, hash-verified

613
614// pprofUnitText returns a formatted string to display for value in the specified unit.
615function pprofUnitText(value, unit) {
616 const sign = (value < 0) ? "-" : "";
617 let v = Math.abs(value);
618 // Rescale to appropriate display unit.
619 let list = null;
620 for (const def of pprofUnitDefs) {
621 if (def.DefaultUnit.CanonicalName == unit) {
622 list = def.Units;
623 v *= def.DefaultUnit.Factor;
624 break;
625 }
626 }
627 if (list) {
628 // Stop just before entry that is too large.
629 for (let i = 0; i < list.length; i++) {
630 if (i == list.length-1 || list[i+1].Factor > v) {
631 v /= list[i].Factor;
632 unit = list[i].CanonicalName;
633 break;
634 }
635 }
636 }
637 return sign + Number(v.toFixed(2)) + unit;
638}

Callers 2

unitTextFunction · 0.85
checkUnitTextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…