regl-project / regl

👑 Functional WebGL
MIT License
5.19k stars 320 forks source link

Application wide profiling #383

Open vorg opened 7 years ago

vorg commented 7 years ago

As the application grows so is the number of components that create regl commands and relaying on regl.stats and reglCommand.stats is not enough. Some issues:

  1. Currently there is no way to get list of all regl commands, not even their count. Regl commands are one of the most expensive resources especially on init due to code compilation and reducing their number is critical. That would also allow me to iterate over stats of all commands in one place.
  2. List of all buffers, textures etc. could be useful for debugging
  3. Execution time measurement of update calls e.g. texture.subimage can take significant time of run every frame. Any ideas how to handle that? Currently I rely on wrapping update code with console.time/timeEnd and regl._gl.finish()

This is connected to Debugging helper tools

mikolalysenko commented 7 years ago

This makes sense and internally regl tracks all this info anyway. Exposing it would be an easy win.

Do you want to take a shot at this?

vorg commented 7 years ago

Yes, i'll have more time next week and probably start with exposing total counts.

There is also a question of how much of that should be in core? Below is a screenshot of what hopefully will become regl-profiler similar to PerfMeter. It currently depends on wrapping regl.frame, regl.texture, gl.useProgram, gl.drawArrays etc. I had to drill down to gl.* calls as one regl resource can create multiple dependent resources (eg. FBO creates dept buffer by default). Again, total counts currently used for resource ids would help.

screen shot 2016-11-23 at 22 42 59

Sections from the top:

API:

const regl = require('regl')({ profile: true })
const profiler = require('regl-profiler')(regl)

const drawMesh = regl({ .... })

// start measuring CPU and GPU timings for the  given command
profiler.addCommand('drawMesh', drawMesh)

// measure some timespan
profiler.time('init')
...
profiler.timeEnd('init')

// whole frame call back will be measured automatically
regl.frame(() => {
   // draw will attach fixed canvas element in the top right corner and draw stats
   profiler.draw() 
})
dcposch commented 7 years ago
  1. List of all buffers, textures etc. could be useful for debugging

You can get this and more with the excellent WebGL Inspector extension.

vorg commented 7 years ago

@dcposch I was big fan of WebGL inspector but there is number of issues:

kevzettler commented 6 years ago

As of late, I have found Spector.js to be incredibly helpful. It is available as a standalone module you can integrate into your project and also has browser extensions.