debugger_panel.rst 10 KB

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