From f72ea82146b366e9f5f9b3ca12d102684e11f654 Mon Sep 17 00:00:00 2001 From: Jamie Wong Date: Sat, 6 Jan 2018 20:04:54 -0500 Subject: [PATCH] Tweaks to value formatting --- flamechart-minimap-view.tsx | 3 +++ flamechart-view.tsx | 9 ++++++++- import/chrome.ts | 2 +- import/stackprof.ts | 2 +- profile.ts | 14 +++++++------- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/flamechart-minimap-view.tsx b/flamechart-minimap-view.tsx index 76074a0..63c064d 100644 --- a/flamechart-minimap-view.tsx +++ b/flamechart-minimap-view.tsx @@ -91,6 +91,9 @@ export class FlamechartMinimapView extends Component 99) formattedPercent = '>99%' + else if (percent < 1) formattedPercent = `${percent.toFixed(2)}%` + else if (percent < 10) formattedPercent = `${percent.toFixed(1)}%` + + return `${this.props.flamechart.formatValue(weight)} (${formattedPercent})` } renderTooltip() { diff --git a/import/chrome.ts b/import/chrome.ts index d12e6ea..64599b6 100644 --- a/import/chrome.ts +++ b/import/chrome.ts @@ -107,6 +107,6 @@ export function importFromChrome(events: TimelineEvent[]) { profile.appendSample(stack, timeDelta) } - profile.setValueFormatter(new TimeFormatter('us')) + profile.setValueFormatter(new TimeFormatter('microseconds')) return profile } \ No newline at end of file diff --git a/import/stackprof.ts b/import/stackprof.ts index 509ac0c..7cabeeb 100644 --- a/import/stackprof.ts +++ b/import/stackprof.ts @@ -41,6 +41,6 @@ export function importFromStackprof(stackprofProfile: StackprofProfile): Profile profile.appendSample(stack, sampleDuration) } - profile.setValueFormatter(new TimeFormatter('us')) + profile.setValueFormatter(new TimeFormatter('microseconds')) return profile } \ No newline at end of file diff --git a/profile.ts b/profile.ts index c4af00e..ff739f2 100644 --- a/profile.ts +++ b/profile.ts @@ -84,19 +84,19 @@ export class RawValueFormatter implements ValueFormatter { export class TimeFormatter implements ValueFormatter { private multiplier : number - constructor(unit: 'ns' | 'us' | 'ms' | 's' = 'ns') { - if (unit === 'ns') this.multiplier = 1e-9 - else if (unit === 'us') this.multiplier = 1e-6 - else if (unit === 'ms') this.multiplier = 1e-3 + constructor(unit: 'nanoseconds' | 'microseconds' | 'milliseconds' | 'seconds') { + if (unit === 'nanoseconds') this.multiplier = 1e-9 + else if (unit === 'microseconds') this.multiplier = 1e-6 + else if (unit === 'milliseconds') this.multiplier = 1e-3 else this.multiplier = 1 } format(v: number) { const s = v * this.multiplier - if (s / 1e0 > 1) return `${s.toFixed(2)}s` - if (s / 1e-3 > 1) return `${(s / 1e-3).toFixed(2)}ms` - if (s / 1e-6 > 1) return `${(s / 1e-6).toFixed(2)}us` + if (s / 1e0 >= 1) return `${s.toFixed(2)}s` + if (s / 1e-3 >= 1) return `${(s / 1e-3).toFixed(2)}ms` + if (s / 1e-6 >= 1) return `${(s / 1e-6).toFixed(2)}µs` else return `${(s / 1e-9).toFixed(2)}ms` } }