Skip to content

Commit

Permalink
Add placementTime metric (#11043)
Browse files Browse the repository at this point in the history
* Add basic placementTime metric

* Move to using total placement time

* Fix lint errors

* simplify placement time tracking

* Undo changes to frameTime measurements
  • Loading branch information
Arindam Bose committed Sep 30, 2021
1 parent c9a462c commit 2452af7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/style/pauseable_placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import browser from '../util/browser.js';

import {Placement} from '../symbol/placement.js';
import {PerformanceUtils} from '../util/performance.js';

import type Transform from '../geo/transform.js';
import type StyleLayer from './style_layer.js';
Expand All @@ -29,7 +30,6 @@ class LayerPlacement {
}

continuePlacement(tiles: Array<Tile>, placement: Placement, showCollisionBoxes: boolean, styleLayer: StyleLayer, shouldPausePlacement: () => boolean) {

const bucketParts = this._bucketParts;

while (this._currentTileIndex < tiles.length) {
Expand Down Expand Up @@ -109,6 +109,7 @@ class PauseablePlacement {
const pausePlacement = this._inProgressLayer.continuePlacement(layerTiles[layer.source], this.placement, this._showCollisionBoxes, layer, shouldPausePlacement);

if (pausePlacement) {
PerformanceUtils.recordPlacementTime(browser.now() - startTime);
// We didn't finish placing all layers within 2ms,
// but we can keep rendering with a partial placement
// We'll resume here on the next frame
Expand All @@ -120,7 +121,7 @@ class PauseablePlacement {

this._currentPlacementIndex--;
}

PerformanceUtils.recordPlacementTime(browser.now() - startTime);
this._done = true;
}

Expand Down
22 changes: 21 additions & 1 deletion src/util/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type PerformanceMetrics = {
workerInitialization: number,
workerEvaluateScript: number,
workerIdle: number,
workerIdlePercent: number
workerIdlePercent: number,
placementTime: number
};

export const PerformanceMarkers = {
Expand All @@ -27,7 +28,9 @@ export const PerformanceMarkers = {
};

let lastFrameTime = null;
let fullLoadFinished = false;
let frameTimes = [];
let placementTime = 0;
const frameSequences = [frameTimes];
let i = 0;

Expand All @@ -45,6 +48,10 @@ const frameTimeTarget = 1000 / framerateTarget;
export const PerformanceUtils = {
mark(marker: $Keys<typeof PerformanceMarkers>) {
performance.mark(marker);

if (marker === PerformanceMarkers.fullLoad) {
fullLoadFinished = true;
}
},
measure(name: string, begin?: string, end?: string) {
performance.measure(name, begin, end);
Expand All @@ -60,6 +67,14 @@ export const PerformanceUtils = {
endMeasure(m: { name: string, mark: string }) {
performance.measure(m.name, m.mark);
},
recordPlacementTime(time: number) {
// Ignore placementTimes during loading
if (!fullLoadFinished) {
return;
}

placementTime += time;
},
frame(timestamp: number, isRenderFrame: boolean) {
const currTimestamp = timestamp;
if (lastFrameTime != null) {
Expand All @@ -78,6 +93,9 @@ export const PerformanceUtils = {
clearMetrics() {
lastFrameTime = null;
frameTimes = [];
placementTime = 0;
fullLoadFinished = false;

performance.clearMeasures('loadTime');
performance.clearMeasures('fullLoadTime');

Expand Down Expand Up @@ -149,6 +167,8 @@ export const PerformanceUtils = {
metrics.cpuFrameBudgetExceeded += Math.max(0, renderFrame.duration - CPU_FRAME_BUDGET);
}

metrics.placementTime = placementTime;

return metrics;
},

Expand Down

0 comments on commit 2452af7

Please sign in to comment.