using_cpp_profilers.rst 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Using C++ profilers
  2. ===================
  3. To optimize Godot's performance, you need to know what to optimize first.
  4. To this end, profilers are useful tools.
  5. .. note::
  6. There is a :ref:`built-in GDScript profiler <doc_the_profiler>` in the editor,
  7. but using C++ profiler may be useful in cases where the GDScript profiler
  8. is not accurate enough or is missing information due to bugs in the profiler.
  9. Recommended profilers
  10. ---------------------
  11. - `VerySleepy <http://www.codersnotes.com/sleepy/>`__ (Windows only)
  12. - `HotSpot <https://github.com/KDAB/hotspot>`__ (Linux only)
  13. These profilers may not be the most powerful or flexible options, but their
  14. standalone operation and limited feature set tends to make them easier to use.
  15. Setting up Godot
  16. ----------------
  17. To get useful profiling information, it is **absolutely required** to use a Godot
  18. build that includes debugging symbols. Official binaries do not include debugging
  19. symbols, since these would make the download size significantly larger.
  20. To get profiling data that best matches the production environment, you should
  21. compile binaries with the following SCons options:
  22. - For editor binaries: ``target=release_debug use_lto=yes``
  23. - For debug export templates: ``target=release_debug use_lto=yes``
  24. - For release export templates: ``tools=no target=release debug_symbols=yes``
  25. - ``debug_symbols=yes`` is required as export templates are stripped from debugging symbols by default.
  26. It is possible to run a profiler on less optimized builds (e.g. ``target=debug`` without LTO),
  27. but results will naturally be less representative of real world conditions.
  28. .. warning::
  29. Do *not* strip debugging symbols on the binaries using the ``strip`` command
  30. after compiling the binaries. Otherwise, you will no longer get useful
  31. profiling information when running a profiler.
  32. Benchmarking startup/shutdown times
  33. -----------------------------------
  34. If you're looking into optimizing Godot's startup/shutdown performance,
  35. you can tell the profiler to use the ``--quit`` command line option on the Godot binary.
  36. This will exit Godot just after it finished starting.
  37. The ``--quit`` option works with ``--editor``, ``--project-manager`` or
  38. ``--path <path to project directory>`` (which runs a project directly).
  39. .. seealso::
  40. See :ref:`doc_command_line_tutorial` for more command line arguments
  41. supported by Godot.
  42. Profiler-specific instructions
  43. ------------------------------
  44. VerySleepy
  45. ^^^^^^^^^^
  46. - Start the Godot editor or your project first.
  47. If you start the project manager, make sure to edit or run a project first.
  48. Otherwise, the profiler will not track the child process since the project manager
  49. will spawn a child process for every project edited or run.
  50. - Open VerySleepy and select the Godot executable in the list of processes on the left:
  51. .. image:: img/cpp_profiler_verysleepy_select_process.png
  52. - Click the **Profile All** button on the right to start profiling.
  53. - Perform the actions you wish to profile in the editor or project. When you're done, click **Stop** (*not* Abort).
  54. - Wait for the results window to appear.
  55. - Once the results window appears, filter the view to remove external modules (such as the graphics driver).
  56. You can filter by module by finding a line whose **Module** matches the Godot
  57. executable name, right-clicking that line then choosing
  58. **Filter Module to <Godot executable name>** in the dropdown that appears.
  59. - Your results window should now look something like this:
  60. .. image:: img/cpp_profiler_verysleepy_results_filtered.png
  61. HotSpot
  62. ^^^^^^^
  63. - Open HotSpot. Click **Record Data**:
  64. .. image:: img/cpp_profiler_hotspot_welcome.png
  65. - In the next window, specify the path to the Godot binary that includes debug symbols.
  66. - Specify command line arguments to run a specific project, with or without the editor.
  67. - The path to the working directory can be anything if an absolute path is used
  68. for the ``--path`` command line argument. Otherwise, it must be set to that
  69. the relative path to the project is valid.
  70. - Make sure **Elevate Privileges** is checked if you have administrative privileges.
  71. While not essential for profiling Godot, this will ensure all events can be captured.
  72. Otherwise, some events may be missing in the capture.
  73. Your settings should now look something like this:
  74. .. image:: img/cpp_profiler_hotspot_record.png
  75. - Click **Start Recording** and perform the actions you wish to profile in the editor/project.
  76. - Quit the editor/project normally or use the **Stop Profiling** button in HotSpot
  77. to stop profiling early. Stopping profiling early can result in cleaner profiles
  78. if you're not interested in the engine's quit procedure.
  79. - Click **View Results** and wait for the profiling visualization to be generated:
  80. .. image:: img/cpp_profiler_hotspot_view_results.png
  81. - Use the tabs at the top to navigate between the different views. These views
  82. show the same data, but in different ways. The **Flame Graph** tab is a good
  83. way to see which functions take up the most time at a glance. These functions
  84. are therefore the most important ones to optimize, since optimizing them will
  85. improve performance the most.
  86. - At the bottom of all tabs except **Summary**, you will also see a list of CPU threads
  87. started by the engine among with the CPU utilization for each thread.
  88. This lets you see threads that can be a bottleneck at a given point in time.
  89. .. image:: img/cpp_profiler_hotspot_flame_graph.png
  90. .. note::
  91. If you don't want the startup procedure to be included in the profile, you
  92. can also attach HotSpot to a running process by clicking **Record Data**
  93. then setting the **Launch Application** dropdown option to **Attach To
  94. Process(es)**.
  95. This process attachment-based workflow is similar to the one used by VerySleepy.