Skip to content

Add comments to clarify per-frame profiler#1039

Merged
vauduong merged 4 commits intofacebookresearch:masterfrom
vauduong:profiler-comments
Jan 22, 2021
Merged

Add comments to clarify per-frame profiler#1039
vauduong merged 4 commits intofacebookresearch:masterfrom
vauduong:profiler-comments

Conversation

@vauduong
Copy link
Copy Markdown
Contributor

@vauduong vauduong commented Jan 19, 2021

Motivation and Context

We added a per-frame profiler in #1015 to display frame duration, cpu duration, and gpu duration at runtime to be aware of bottlenecks in data processing when running our viewer. This PR adds comments to clarify how to interpret values.

How Has This Been Tested

Build and run

Types of changes

  • [ x] Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x ] My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • [ x] I have read the CONTRIBUTING document.
  • [x ] I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jan 19, 2021
Comment thread src/utils/viewer/viewer.cpp Outdated
Mn::DebugTools::GLFrameProfiler::Value::FrameTime | // Time to render per
// frame frame
Mn::DebugTools::GLFrameProfiler::Value::
CpuDuration | // Time to process action (eg. physics, key presses)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is physics/simulation and UI processing the only two broad categories? Is there anything else?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The profiler currently measures just one scope, that's its limitation, except if more than one profiler instance would be used for more scopes, as i suggested on #1015. That's a possible path for extending this functionality.

(I might be expanding the Magnum functionality eventually as well, depending on what will be interesting to measure for the Vulkan backend.)

Comment thread src/utils/viewer/viewer.cpp Outdated
CpuDuration | // Time to process action (eg. physics, key presses)
// data per frame
Mn::DebugTools::GLFrameProfiler::Value::
GpuDuration; // Time to process graphics data per frame
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Process graphics data" = rendering? Or do we mean something else?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhruvbatra : "GpuDruation" is using asynchronous query such as ARB_timer_query, to record the amount of time that GPU takes to fully complete a set of scoped GL commands.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be an easy enough interpretation of the numbers:

  • FrameTime is an inverse of FPS and should be 16.6 ms or less for smooth interactivity. In my opinion it's better than FPS because you can better measure improvements. "FPS increased by 10" means a totally different thing if it was from 10 to 20 or from 900 to 910, while "frame time decreased by 10 ms" always has a clear meaning.
  • CpuDuration measures how much CPU time was spent doing all work in a frame -- event processing, physics, but also traversing the scenegraph, submitting work for the GPU or the driver overhead. It should be less than GPU duration, if it's not then the GPU is sitting there bored.
  • GpuDuration measured how much time did it take for the GPU to process all work submitted by the CPU. If it's less than the CPU time then if you reduce the CPU / driver overhead you can do / draw more in a frame (or draw frames faster), if it's significantly more than the CPU time then you're GPU-bound -- rendering too dense meshes, having too high texture resolution, or maybe just rendering a lot of objects that end up occluded or out of the view or having inefficient layout of the mesh data. Generally, since the aim here is to render as fast as possible (and not power efficiency for example), the CPU and GPU time should be roughly equal.

@vauduong in case you haven't stumbled upon it yet, there's an article about the geometry pipeline in Magnum, with more info about how to interpret the values and what makes meshes slow or fast to render: https://blog.magnum.graphics/announcements/new-geometry-pipeline/ It's scary long but written hopefully in a general enough way that might give you useful info even if you don't end up using Magnum further in your career ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the helpful comments @mosras! I did stumble upon that article and it was also super informative :)

@vauduong vauduong requested a review from mosra January 21, 2021 17:59
@bigbike
Copy link
Copy Markdown
Contributor

bigbike commented Jan 21, 2021

@mosra : Saw you are in the reviewer list.
Any comments would be highly appreciated. Thanks!

@vauduong
Copy link
Copy Markdown
Contributor Author

@mosra : Yes, would appreciate any feedback on writing more precise comments to help users understand what the GLProfiler is doing!

@mosra
Copy link
Copy Markdown
Contributor

mosra commented Jan 21, 2021

Replied above :)

I'm realizing some of this info could go straight into Magnum docs as well, because the explanation is currently a bit underwhelming.

Comment thread src/utils/viewer/viewer.cpp Outdated
* Uses asynchronous querying to measure the amount of time
* to fully complete a set of GL commands without stalling rendering, 3 frame
* delay
* Asynchronous querying extensions: ARB_timer_query (OpenGL 3.3),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will recommend removing such details (L567 - L570)

Comment thread src/utils/viewer/viewer.cpp Outdated
* CpuDuration: (Units::Nanoseconds) CPU time spent processing events,
* physics, traversing SceneGraph, and submitting data to GPU/drivers per
* frame
* Measured using std::chrono::high_resolution_clock, 1 frame delay
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove details such as L560.

Comment thread src/utils/viewer/viewer.cpp Outdated
* frame
* Measured using std::chrono::high_resolution_clock, 1 frame delay
*
* GpuDuration: (Units::Nanoseconds) GPU time spent rendering data submitted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

measured how much time it takes for the GPU to process all work submitted by the CPU.

Comment thread src/utils/viewer/viewer.cpp Outdated
* GpuDuration: (Units::Nanoseconds) GPU time spent rendering data submitted
* by CPU per frame
* Uses asynchronous querying to measure the amount of time
* to fully complete a set of GL commands without stalling rendering, 3 frame
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove 3 frame delay.

Comment thread src/utils/viewer/viewer.cpp Outdated
Mn::DebugTools::GLFrameProfiler::Value::GpuDuration;

// VertexFetchRatio and PrimitiveClipRatio only supported for GL 4.6
/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this. Undo the change.

@vauduong vauduong merged commit 15ab57f into facebookresearch:master Jan 22, 2021
@vauduong vauduong deleted the profiler-comments branch January 22, 2021 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants