diff options
Diffstat (limited to 'ui/src/controller/track_controller.ts')
-rw-r--r-- | ui/src/controller/track_controller.ts | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/ui/src/controller/track_controller.ts b/ui/src/controller/track_controller.ts index 46d1f1f26..73b98969e 100644 --- a/ui/src/controller/track_controller.ts +++ b/ui/src/controller/track_controller.ts @@ -12,11 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +import {BigintMath} from '../base/bigint_math'; import {assertExists, assertTrue} from '../base/logging'; import {Engine} from '../common/engine'; import {Registry} from '../common/registry'; import {TraceTime, TrackState} from '../common/state'; -import {fromNs, toNs} from '../common/time'; +import { + TPDuration, + TPTime, + tpTimeFromSeconds, + TPTimeSpan, +} from '../common/time'; import {LIMIT, TrackData} from '../common/track_data'; import {globals} from '../frontend/globals'; import {publishTrackData} from '../frontend/publish'; @@ -70,7 +76,7 @@ export abstract class TrackController< // Must be overridden by the track implementation. Is invoked when the track // frontend runs out of cached data. The derived track controller is expected // to publish new track data in response to this call. - abstract onBoundsChange(start: number, end: number, resolution: number): + abstract onBoundsChange(start: TPTime, end: TPTime, resolution: TPDuration): Promise<Data>; get trackState(): TrackState { @@ -129,6 +135,7 @@ export abstract class TrackController< } shouldRequestData(traceTime: TraceTime): boolean { + const tspan = new TPTimeSpan(traceTime.start, traceTime.end); if (this.data === undefined) return true; if (this.shouldReload()) return true; @@ -137,15 +144,14 @@ export abstract class TrackController< if (atLimit) { // We request more data than the window, so add window duration to find // the previous window. - const prevWindowStart = - this.data.start + (traceTime.startSec - traceTime.endSec); - return traceTime.startSec !== prevWindowStart; + const prevWindowStart = this.data.start + tspan.duration; + return tspan.start !== prevWindowStart; } // Otherwise request more data only when out of range of current data or // resolution has changed. - const inRange = traceTime.startSec >= this.data.start && - traceTime.endSec <= this.data.end; + const inRange = + tspan.start >= this.data.start && tspan.end <= this.data.end; return !inRange || this.data.resolution !== globals.state.frontendLocalState.visibleState.resolution; @@ -162,8 +168,7 @@ export abstract class TrackController< return undefined; } - const bounds = globals.state.traceTime; - const traceDurNs = toNs(bounds.endSec - bounds.startSec); + const traceDuration = globals.stateTraceTime().duration; // For large traces, going through the raw table in the most zoomed-out // states can be very expensive as this can involve going through O(millions @@ -198,7 +203,7 @@ export abstract class TrackController< // Compute the outermost bucket size. This acts as a starting point for // computing the cached size. const outermostResolutionLevel = - Math.ceil(Math.log2(traceDurNs / approxWidthPx)); + Math.ceil(Math.log2(traceDuration.nanos / approxWidthPx)); const outermostBucketNs = Math.pow(2, outermostResolutionLevel); // This constant decides how many resolution levels down from our outermost @@ -232,11 +237,11 @@ export abstract class TrackController< run() { const visibleState = globals.state.frontendLocalState.visibleState; - if (visibleState === undefined || visibleState.resolution === undefined || - visibleState.resolution === Infinity) { + if (visibleState === undefined) { return; } - const dur = visibleState.endSec - visibleState.startSec; + const visibleTimeSpan = globals.stateVisibleTime(); + const dur = visibleTimeSpan.duration; if (globals.state.visibleTracks.includes(this.trackId) && this.shouldRequestData(visibleState)) { if (this.requestingData) { @@ -253,16 +258,14 @@ export abstract class TrackController< .then(() => { this.isSetup = true; let resolution = visibleState.resolution; - // TODO(hjd): We shouldn't have to be so defensive here. - if (Math.log2(toNs(resolution)) % 1 !== 0) { - // resolution is in pixels per second so 1000 means - // 1px = 1ms. - resolution = - fromNs(Math.pow(2, Math.floor(Math.log2(toNs(1000))))); + + if (BigintMath.popcount(resolution) !== 1) { + resolution = BigintMath.bitFloor(tpTimeFromSeconds(1000)); } + return this.onBoundsChange( - visibleState.startSec - dur, - visibleState.endSec + dur, + visibleTimeSpan.start - dur, + visibleTimeSpan.end + dur, resolution); }) .then((data) => { |