(value, unit)
| 613 | |
| 614 | // pprofUnitText returns a formatted string to display for value in the specified unit. |
| 615 | function 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…