debugger_panel.rst 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. .. _doc_debugger_panel:
  2. Debugger panel
  3. ==============
  4. Many of Godot's debugging tools, including the debugger, can be found in the
  5. debugger panel at the bottom of the screen. Click on **Debugger** to open it.
  6. .. image:: img/overview_debugger.webp
  7. The debugger panel is split into several tabs, each focusing on a specific task.
  8. Stack Trace
  9. -----------
  10. The Stack Trace tab opens automatically when the GDScript compiler reaches
  11. a breakpoint in your code.
  12. It gives you a `stack trace <https://en.wikipedia.org/wiki/Stack_trace>`__,
  13. information about the state of the object, and buttons to control the program's
  14. execution. When the debugger breaks on a breakpoint, a green triangle arrow is
  15. visible in the script editor's gutter. This arrow indicates the line of code the
  16. debugger broke on.
  17. .. tip::
  18. You can create a breakpoint by clicking the gutter in the left of the script
  19. editor (on the left of the line numbers). When hovering this gutter, you
  20. will see a transparent red dot appearing, which turns into an opaque red dot
  21. after the breakpoint is placed by clicking. Click the red dot again to
  22. remove the breakpoint. Breakpoints created this way persist across editor
  23. restarts, even if the script wasn't saved when exiting the editor.
  24. You can also use the ``breakpoint`` keyword in GDScript to create a
  25. breakpoint that is stored in the script itself. Unlike breakpoints created by
  26. clicking in the gutter, this keyword-based breakpoint is persistent across
  27. different machines when using version control.
  28. You can use the buttons in the top-right corner to:
  29. - Skip all breakpoints. That way, you can save breakpoints for future
  30. debugging sessions.
  31. - Copy the current error message.
  32. - **Step Into** the code. This button takes you to the next line of code,
  33. and if it's a function, it steps line-by-line through the function.
  34. - **Step Over** the code. This button goes to the next line of code,
  35. but it doesn't step line-by-line through functions.
  36. - **Break**. This button pauses the game's execution.
  37. - **Continue**. This button resumes the game after a breakpoint or pause.
  38. Errors
  39. ------
  40. This is where error and warning messages are printed while running the game.
  41. You can disable specific warnings in **Project Settings > Debug > GDScript**.
  42. Evaluator
  43. ----------
  44. This tab contains an expression evaluator, also known as a :abbr:`REPL (Read-Eval-Print Loop)`.
  45. This is a more powerful complement to the Stack Variables tree available in the Stack Trace tab.
  46. When the project is interrupted in the debugger (due to a breakpoint or script
  47. error), you can enter an expression in the text field at the top. If the project
  48. is running, the expression field won't be editable, so you will need to set a
  49. breakpoint first. Expressions can be persisted across runs by unchecking **Clear on Run**,
  50. although they will be lost when the editor quits.
  51. Expressions are evaluated using :ref:`Godot's expression language
  52. <doc_evaluating_expressions>`, which allows you to perform arithmetic and call
  53. some functions within the expression. Expressions can refer to member variables,
  54. or local variables within the same scope as the line the breakpoint is on. You
  55. can also enter constant values, which makes it usable as a built-in calculator.
  56. Consider the following script:
  57. ::
  58. var counter = 0
  59. func _process(delta):
  60. counter += 1
  61. if counter == 5:
  62. var text = "Some text"
  63. breakpoint
  64. elif counter >= 6:
  65. var other_text = "Some other text"
  66. breakpoint
  67. If the debugger breaks on the **first** line containing ``breakpoint``, the following
  68. expressions return non-null values:
  69. - **Constant expression:** ``2 * PI + 5``
  70. - **Member variable:** ``counter``, ``counter ** 2``, ``sqrt(counter)``
  71. - **Local variable or function parameter:** ``delta``, ``text``, ``text.to_upper()``
  72. If the debugger breaks on the **second** line containing ``breakpoint``, the following
  73. expressions return non-null values:
  74. - **Constant expression:** ``2 * PI + 5``
  75. - **Member variable:** ``counter``, ``counter ** 2``, ``sqrt(counter)``
  76. - **Local variable or function parameter:** ``delta``, ``other_text``, ``other_text.to_upper()``
  77. Profiler
  78. --------
  79. The profiler is used to see what code is running while your project is in use,
  80. and how that effects performance.
  81. .. seealso::
  82. A detailed explanation of how to use the profiler can be found in the
  83. dedicated :ref:`doc_the_profiler` page.
  84. Visual Profiler
  85. ---------------
  86. The Visual Profiler can be used to monitor what is taking the most time when
  87. rendering a frame on the CPU and GPU respectively. This allows tracking sources
  88. of potential CPU and GPU bottlenecks caused by rendering.
  89. .. warning::
  90. The Visual Profiler only measures CPU time taken for rendering tasks, such
  91. as performing draw calls. The Visual Profiler does **not** include CPU time
  92. taken for other tasks such as scripting and physics. Use the standard
  93. Profiler tab to track non-rendering-related CPU tasks.
  94. To use the visual profiler, run the project, switch to the **Visual Profiler**
  95. tab within the Debugger bottom panel, then click **Start**:
  96. .. figure:: img/debugger_visual_profiler_results.webp
  97. :alt: Visual Profiler tab after clicking Start, waiting for a few seconds, then clicking Stop
  98. Visual Profiler tab after clicking **Start**, waiting for a few seconds, then clicking **Stop**
  99. .. tip::
  100. You can also check **Autostart**, which will make the visual profiler automatically
  101. start when the project is run the next time. Note that the **Autostart**
  102. checkbox's state is not preserved across editor sessions.
  103. You will see categories and results appearing as the profiler is running. Graph
  104. lines also appear, with the left side being a CPU framegraph and the right side
  105. being a GPU framegraph.
  106. Click **Stop** to finish profiling, which will keep the results visible but
  107. frozen in place. Results remain visible after stopping the running project, but
  108. not after exiting the editor.
  109. Click on result categories on the left to highlight them in the CPU and GPU
  110. graphs on the right. You can also click on the graph to move the cursor to a
  111. specific frame number and highlight the selected data type in the result
  112. categories on the left.
  113. You can switch the result display between a time value (in milliseconds per
  114. frame) or a percentage of the target frametime (which is currently hardcoded to
  115. 16.67 milliseconds, or 60 FPS).
  116. If framerate spikes occur during profiling, this can cause the graph to be
  117. poorly scaled. Disable **Fit to Frame** so that the graph will zoom onto the 60
  118. FPS+ portion.
  119. .. note::
  120. Remember that Visual Profiler results can vary **heavily** based on
  121. viewport resolution, which is determined by the window size if using the
  122. ``disabled`` or ``canvas_items`` :ref:`stretch modes
  123. <doc_multiple_resolutions>`.
  124. When comparing results across different runs, make sure to use the same
  125. viewport size for all runs.
  126. Visual Profiler is supported when using any rendering method (Forward+, Mobile
  127. or Compatibility), but the reported categories will vary depending on the
  128. current rendering method as well as the enabled graphics features. For example,
  129. when using Forward+, a simple 2D scene with shadow-casting lights will result in
  130. the following categories appearing:
  131. .. figure:: img/debugger_visual_profiler_2d_example.webp
  132. :alt: Example results from a 2D scene in the Visual Profiler
  133. Example results from a 2D scene in the Visual Profiler
  134. To give another example with Forward+, a 3D scene with shadow-casting lights and
  135. various effects enabled will result in the following categories enabled:
  136. .. figure:: img/debugger_visual_profiler_3d_example.webp
  137. :alt: Example results from a 3D scene in the Visual Profiler
  138. Example results from a 3D scene in the Visual Profiler
  139. Notice how in the 3D example, several of the categories have **(Parallel)**
  140. appended to their name. This hints that multiple tasks are being performed in
  141. parallel on the GPU. This generally means that disabling only one of the
  142. features involved won't improve performance as much as anticipated, as the other
  143. task still needs to be performed sequentially.
  144. Network Profiler
  145. ----------------
  146. The Network Profiler contains a list of all the nodes that communicate over the
  147. multiplayer API and, for each one, some counters on the amount of incoming and
  148. outgoing network interactions. It also features a bandwidth meter that displays
  149. the total bandwidth usage at any given moment.
  150. .. note::
  151. The bandwidth meter does **not** take the :ref:`doc_high_level_multiplayer`
  152. API's own compression system into account. This means that changing the
  153. compression algorithm used will not change the metrics reported by the
  154. bandwidth meter.
  155. Monitors
  156. --------
  157. The monitors are graphs of several aspects of the game while its running such as
  158. FPS, memory usage, how many nodes are in a scene and more. All monitors keep
  159. track of stats automatically, so even if one monitor isn't open while the game
  160. is running, you can open it later and see how the values changed.
  161. .. seealso::
  162. In addition to the default performance monitors, you can also create
  163. :ref:`custom performance monitors <doc_custom_performance_monitors>`
  164. to track arbitrary values in your project.
  165. Video RAM
  166. ---------
  167. The **Video RAM** tab shows the video RAM usage of the game while it is running.
  168. It provides a list of every resource using video RAM by resource path, the type
  169. of resource it is, what format it is in, and how much Video RAM that resource is
  170. using. There is also a total video RAM usage number at the top right of the panel.
  171. .. image:: img/video_ram.png
  172. Misc
  173. ----
  174. The **Misc** tab contains tools to identify the control nodes you are clicking
  175. at runtime:
  176. - **Clicked Control** tells you where the clicked node is in the scene tree.
  177. - **Clicked Control Type** tells you the type of the node you clicked is.