nfengine icon indicating copy to clipboard operation
nfengine copied to clipboard

Implement profiler

Open Witek902 opened this issue 10 years ago • 0 comments

We need a tool to measure engine subsystem performance at the runtime. This will be very helpfull for game developers and engine developers as well.

Key features:

  • Hierarichcal design. For example: in the root (frame delta time) there are renderer, physics, network, etc. nodes. Render node will contain shadows, lights, culling, etc.
  • Time measurement and call counters (for example to track meshes drawn, entities updated, etc.).
  • Easy use. Adding a new node should not require modifying profiler source files (maybe initialize new nodes via static variables initialization?)
  • Multithreading. Some parts of the code will be executed on multiple threads. It would be nice to measure total CPU time (sum of time intervals of all the threads). For example: shadows are renderer on 8 threads, what takes 1ms from user point of view, but from CPU point of view it takes almost 8ms in total.
  • Readable display. The measurements should be displayed in realtime in form of a tree. Highlight most time consuming sections. The displayed measurements should be smoothed, so they don't change very fast and can be read easly. Good approach would be to display min/avg/max/std.dev. from last second or two.

Checklist of basic features (preferably in order of implementation):

  • [x] Basic structure/skeleton: Profiler singleton, macros/calls/etc which inserts new node, basic tests
  • [ ] Performance tests for profiler. These will help with further features to minimize Profiler overhead. Test both simple (a few nodes), heavy (multiple nested nodes) and mixed conditions.
  • [ ] Data collection with smart allocation. Probably data chunks would be a good idea here - experiment with different chunk sizes, maybe doubling the size each reallocation would help. Try to keep as much data as possible on stack.
  • [ ] Total CPU/GPU/Memory usage/etc.. This data should be kept in root node only.
  • [ ] Summary and statistics. Exiting the engine should gather all collected data in a text file in hierarchical form with calculated statistics - percentage of all frame time, summarized time taken (summarized from all threads), realtime taken, percentage/number of all calls, It should be easy to add new fields for further statistics.
  • [ ] Triggering profiling on single frames, or within a specific timespan. In both situations, profiler should remember when on the timeline the "capture" or "begin/end capture" key will be pressed. In this mode all profiler traces should be recorded into a buffer for further analysis. Executing thread ID should be included.

Advanced features for the future & ideas:

  • [ ] Representing variables history in a form of a plot:
    • [ ] Output in SVG form to view on external tools
    • [ ] Live plotting inside one of nfEngine windows, using ImGUI. Take a look at this: https://cloud.githubusercontent.com/assets/153526/10033356/50ffccde-6189-11e5-87a5-261684c3d479.png and https://cloud.githubusercontent.com/assets/4952023/10412539/b3f0bfb2-6f3d-11e5-9e26-a782e8bad330.png
    • [ ] Possibility to measure specific timespan (triggering profiling by key) and analysis afterwards (selecting a part of the graph, or a specific frame)
    • [ ] Single-frame analysis for insepcting which task takes how much time and what are dependencies between them. Look at Uniti's profiler: https://unity3d.com/sites/default/files/styles/original/public/editor-1.jpg?itok=RVgx3bAM

Witek902 avatar Oct 16 '14 21:10 Witek902