Skip to content

Commit

Permalink
MOAR stats, docs, fix metrics counter
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed May 29, 2019
1 parent 1a803f1 commit b58cdaa
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/api-reference/deck.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ A map of various performance statistics for the last 60 frames of rendering. Met
- 'layersRedrawn': number of layers drawn
- 'setPropsTime': time spent setting layer properties
- 'drawCount': number of times the scene was rendered
- 'gpuTime': total time spent on GPU processing
- 'gpuTimePerFrame': average time spent on GPU processing per frame
- 'cpuTime': total time spent on CPU processing
- 'cpuTimePerFrame': average time spent on CPU processing per frame
- 'bufferMemory': total GPU memory allocated for buffers
- 'textureMemory': total GPU memory allocated for textures
- 'renderbufferMemory': total GPU memory allocated for renderbuffers
- 'gpuMemory': total allocated GPU memory


## Remarks
Expand Down
65 changes: 60 additions & 5 deletions modules/core/src/lib/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import DeckPicker from './deck-picker';
import log from '../utils/log';

import GL from '@luma.gl/constants';
import {AnimationLoop, createGLContext, trackContextState, setParameters} from '@luma.gl/core';
import {
AnimationLoop,
createGLContext,
trackContextState,
setParameters,
lumaStats
} from '@luma.gl/core';
import {Stats} from 'probe.gl';
import {EventManager} from 'mjolnir.js';

Expand Down Expand Up @@ -162,8 +168,17 @@ export default class Deck {
setPropsTime: 0,
updateAttributesTime: 0,
drawCount: 0,
layersRedrawn: 0
layersRedrawn: 0,
gpuTime: 0,
gpuTimePerFrame: 0,
cpuTime: 0,
cpuTimePerFrame: 0,
bufferMemory: 0,
textureMemory: 0,
renderbufferMemory: 0,
gpuMemory: 0
};
this._metricsCounter = 0;

this.setProps(props);

Expand Down Expand Up @@ -645,11 +660,10 @@ export default class Deck {
}

_onRenderFrame(animationProps) {
this.stats.get('frameRate').timeEnd();
this.stats.get('frameRate').timeStart();
this._getFrameStats();

// Log perf stats every second
if (animationProps.tick % 60 === 0) {
if (this._metricsCounter++ % 60 === 0) {
this._getMetrics();
this.stats.reset();
log.table(3, this.metrics)();
Expand Down Expand Up @@ -766,6 +780,25 @@ export default class Deck {
});
}

_getFrameStats() {
this.stats.get('frameRate').timeEnd();
this.stats.get('frameRate').timeStart();

// Get individual stats from luma.gl so reset works
const animationLoopStats = this.animationLoop.stats;
this.stats
.get('GPU Time')
.addTime(
animationLoopStats.get('GPU Time') ? animationLoopStats.get('GPU Time').lastTiming : 0
);
this.stats
.get('CPU Time')
.addTime(
animationLoopStats.get('CPU Time') ? animationLoopStats.get('CPU Time').lastTiming : 0
);
}

/* eslint-disable complexity */
_getMetrics() {
this.metrics.fps = this.stats.get('frameRate') ? this.stats.get('frameRate').getHz() : 0;
this.metrics.setPropsTime = this.stats.get('setProps Time')
Expand All @@ -780,6 +813,28 @@ export default class Deck {
this.metrics.layersRedrawn = this.stats.get('Redraw Layers')
? this.stats.get('Redraw Layers').count
: 0;
this.metrics.gpuTime = this.stats.get('GPU Time') ? this.stats.get('GPU Time').time : 0;
this.metrics.cpuTime = this.stats.get('CPU Time') ? this.stats.get('CPU Time').time : 0;
this.metrics.gpuTimePerFrame = this.stats.get('GPU Time')
? this.stats.get('GPU Time').getAverageTime()
: 0;
this.metrics.cpuTimePerFrame = this.stats.get('CPU Time')
? this.stats.get('CPU Time').getAverageTime()
: 0;

const memoryStats = lumaStats.get('Memory Usage');
this.metrics.bufferMemory = memoryStats.get('Buffer Memory')
? memoryStats.get('Buffer Memory').count
: 0;
this.metrics.textureMemory = memoryStats.get('Texture Memory')
? memoryStats.get('Texture Memory').count
: 0;
this.metrics.renderbufferMemory = memoryStats.get('Renderbuffer Memory')
? memoryStats.get('Renderbuffer Memory').count
: 0;
this.metrics.gpuMemory = memoryStats.get('Memory Usage')
? memoryStats.get('Memory Usage').count
: 0;
}
}

Expand Down

0 comments on commit b58cdaa

Please sign in to comment.