Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Performance

繼承: Object

公開與性能相關的資料。

說明

該類提供對許多與性能相關的不同監視器的存取,例如記憶體使用情況、繪製呼叫、和 FPS。這些值與編輯器的除錯器面板中的監視分頁中顯示的值相同。通過使用該類的 get_monitor() 方法,你可以從程式碼中存取該資料。

可以使用 add_custom_monitor() 方法新增自訂監視器。在編輯器的除錯器面板的監視分頁中,自訂監視器可以與內建監視器一起使用。

注意:某些內建監視器僅在除錯模式下可用,並且在以發行模式匯出的專案中使用時,將始終返回 0

注意:出於性能原因,某些內建監視器不會即時更新,所以在更改之間可能會有長達 1 秒的延遲。

注意:自訂監視器不支援負值。負值被鉗制為 0。

方法

void

add_custom_monitor(id: StringName, callable: Callable, arguments: Array = [], type: MonitorType = 0)

Variant

get_custom_monitor(id: StringName)

Array[StringName]

get_custom_monitor_names()

PackedInt32Array

get_custom_monitor_types()

float

get_monitor(monitor: Monitor) const

int

get_monitor_modification_time()

bool

has_custom_monitor(id: StringName)

void

remove_custom_monitor(id: StringName)


列舉

enum Monitor: 🔗

Monitor TIME_FPS = 0

上一秒算繪的影格數。該指標每秒僅更新一次,與查詢頻率無關。越高越好。

Monitor TIME_PROCESS = 1

完成一影格所需的時間,單位為秒。越低越好。

Monitor TIME_PHYSICS_PROCESS = 2

完成一個物理影格所需的時間,單位為秒。越低越好。

Monitor TIME_NAVIGATION_PROCESS = 3

完成一個導覽步驟的時間,單位為秒。包括導覽地圖的更新以及代理避障的計算。越低越好。

Monitor MEMORY_STATIC = 4

目前使用的靜態記憶體,單位為位元組。在發行版本中不可用。越低越好。

Monitor MEMORY_STATIC_MAX = 5

可用的靜態記憶體。在發行版本中不可用。越低越好。

Monitor MEMORY_MESSAGE_BUFFER_MAX = 6

訊息佇列緩衝區已使用的最大記憶體量,單位為位元組。訊息佇列用於延遲函式呼叫和通知。越低越好。

Monitor OBJECT_COUNT = 7

目前產生實體的對象數(包括節點)。越低越好。

Monitor OBJECT_RESOURCE_COUNT = 8

目前使用的資源數。越低越好。

Monitor OBJECT_NODE_COUNT = 9

目前在場景樹中產生實體的節點數。也包括根節點。越低越好。

Monitor OBJECT_ORPHAN_NODE_COUNT = 10

Number of orphan nodes, i.e. nodes which are not parented to a node of the scene tree. Lower is better.

Note: This is only available in debug mode and will always return 0 when used in a project exported in release mode.

Monitor RENDER_TOTAL_OBJECTS_IN_FRAME = 11

在上一個算繪影格中的物件總數。該指標不包括剔除的對象(通過隱藏節點、視錐剔除、或遮擋剔除)。越低越好。

Monitor RENDER_TOTAL_PRIMITIVES_IN_FRAME = 12

在上一個算繪影格中算繪的頂點或索引的總數。該指標不包括來自被剔除對象的圖元(通過隱藏節點、視錐剔除、或遮擋剔除)。由於預深度階段和陰影階段,圖元的數量總是高於場景中的實際頂點數量(通常是原始頂點數量的兩倍或三倍)。越低越好。

Monitor RENDER_TOTAL_DRAW_CALLS_IN_FRAME = 13

在上一個算繪影格中執行的繪製呼叫的總數。該指標不包括剔除對象(通過隱藏節點、視錐剔除、或遮擋剔除),因為它們不會導致繪製呼叫。越低越好。

Monitor RENDER_VIDEO_MEM_USED = 14

顯存的使用量(紋理和頂點記憶體之和,單位為位元組)。由於該指標還包括其他雜項分配,因此該值始終大於 RENDER_TEXTURE_MEM_USEDRENDER_BUFFER_MEM_USED 的總和。越低越好。

Monitor RENDER_TEXTURE_MEM_USED = 15

紋理記憶體的使用量(單位為位元組)。越低越好。

Monitor RENDER_BUFFER_MEM_USED = 16

算繪緩衝區記憶體的使用量(單位為位元組)。越低越好。

Monitor PHYSICS_2D_ACTIVE_OBJECTS = 17

遊戲中活躍的 RigidBody2D 節點數。越低越好。

Monitor PHYSICS_2D_COLLISION_PAIRS = 18

2D 物理引擎中碰撞對的數量。越低越好。

Monitor PHYSICS_2D_ISLAND_COUNT = 19

2D 物理引擎中孤島的數量。越低越好。

Monitor PHYSICS_3D_ACTIVE_OBJECTS = 20

遊戲中活躍的 RigidBody3DVehicleBody3D 節點數。越低越好。

Monitor PHYSICS_3D_COLLISION_PAIRS = 21

3D 物理引擎中碰撞對的數量。越低越好。

Monitor PHYSICS_3D_ISLAND_COUNT = 22

3D 物理引擎中孤島的數量。越低越好。

Monitor AUDIO_OUTPUT_LATENCY = 23

AudioServer的輸出延遲。相當於呼叫AudioServer.get_output_latency(),不建議每影格呼叫方法。

Monitor NAVIGATION_ACTIVE_MAPS = 24

Number of active navigation maps in NavigationServer2D and NavigationServer3D. This also includes the empty default navigation maps created by World2D and World3D instances.

Monitor NAVIGATION_REGION_COUNT = 25

Number of active navigation regions in NavigationServer2D and NavigationServer3D.

Monitor NAVIGATION_AGENT_COUNT = 26

Number of active navigation agents processing avoidance in NavigationServer2D and NavigationServer3D.

Number of active navigation links in NavigationServer2D and NavigationServer3D.

Monitor NAVIGATION_POLYGON_COUNT = 28

Number of navigation mesh polygons in NavigationServer2D and NavigationServer3D.

Monitor NAVIGATION_EDGE_COUNT = 29

Number of navigation mesh polygon edges in NavigationServer2D and NavigationServer3D.

Monitor NAVIGATION_EDGE_MERGE_COUNT = 30

Number of navigation mesh polygon edges that were merged due to edge key overlap in NavigationServer2D and NavigationServer3D.

Monitor NAVIGATION_EDGE_CONNECTION_COUNT = 31

Number of polygon edges that are considered connected by edge proximity NavigationServer2D and NavigationServer3D.

Monitor NAVIGATION_EDGE_FREE_COUNT = 32

Number of navigation mesh polygon edges that could not be merged in NavigationServer2D and NavigationServer3D. The edges still may be connected by edge proximity or with links.

Monitor NAVIGATION_OBSTACLE_COUNT = 33

Number of active navigation obstacles in the NavigationServer2D and NavigationServer3D.

Monitor PIPELINE_COMPILATIONS_CANVAS = 34

Number of pipeline compilations that were triggered by the 2D canvas renderer.

Monitor PIPELINE_COMPILATIONS_MESH = 35

Number of pipeline compilations that were triggered by loading meshes. These compilations will show up as longer loading times the first time a user runs the game and the pipeline is required.

Monitor PIPELINE_COMPILATIONS_SURFACE = 36

Number of pipeline compilations that were triggered by building the surface cache before rendering the scene. These compilations will show up as a stutter when loading a scene the first time a user runs the game and the pipeline is required.

Monitor PIPELINE_COMPILATIONS_DRAW = 37

Number of pipeline compilations that were triggered while drawing the scene. These compilations will show up as stutters during gameplay the first time a user runs the game and the pipeline is required.

Monitor PIPELINE_COMPILATIONS_SPECIALIZATION = 38

Number of pipeline compilations that were triggered to optimize the current scene. These compilations are done in the background and should not cause any stutters whatsoever.

Monitor NAVIGATION_2D_ACTIVE_MAPS = 39

Number of active navigation maps in the NavigationServer2D. This also includes the empty default navigation maps created by World2D instances.

Monitor NAVIGATION_2D_REGION_COUNT = 40

Number of active navigation regions in the NavigationServer2D.

Monitor NAVIGATION_2D_AGENT_COUNT = 41

Number of active navigation agents processing avoidance in the NavigationServer2D.

Number of active navigation links in the NavigationServer2D.

Monitor NAVIGATION_2D_POLYGON_COUNT = 43

Number of navigation mesh polygons in the NavigationServer2D.

Monitor NAVIGATION_2D_EDGE_COUNT = 44

Number of navigation mesh polygon edges in the NavigationServer2D.

Monitor NAVIGATION_2D_EDGE_MERGE_COUNT = 45

Number of navigation mesh polygon edges that were merged due to edge key overlap in the NavigationServer2D.

Monitor NAVIGATION_2D_EDGE_CONNECTION_COUNT = 46

Number of polygon edges that are considered connected by edge proximity NavigationServer2D.

Monitor NAVIGATION_2D_EDGE_FREE_COUNT = 47

Number of navigation mesh polygon edges that could not be merged in the NavigationServer2D. The edges still may be connected by edge proximity or with links.

Monitor NAVIGATION_2D_OBSTACLE_COUNT = 48

Number of active navigation obstacles in the NavigationServer2D.

Monitor NAVIGATION_3D_ACTIVE_MAPS = 49

Number of active navigation maps in the NavigationServer3D. This also includes the empty default navigation maps created by World3D instances.

Monitor NAVIGATION_3D_REGION_COUNT = 50

NavigationServer3D 中活動導覽地區的數量。

Monitor NAVIGATION_3D_AGENT_COUNT = 51

NavigationServer3D 中正在處理避障的活動導覽代理的數量。

NavigationServer3D 中活動導覽連結的數量。

Monitor NAVIGATION_3D_POLYGON_COUNT = 53

NavigationServer3D 中導覽網格多邊形的數量。

Monitor NAVIGATION_3D_EDGE_COUNT = 54

NavigationServer3D 中導覽網格多邊形邊緣的數量。

Monitor NAVIGATION_3D_EDGE_MERGE_COUNT = 55

NavigationServer3D 中由於邊鍵重疊而被合併的導覽網格多邊形的邊的數量。

Monitor NAVIGATION_3D_EDGE_CONNECTION_COUNT = 56

NavigationServer3D 中由邊緣接近而被認為已連接的多邊形的邊的數量。

Monitor NAVIGATION_3D_EDGE_FREE_COUNT = 57

NavigationServer3D 中無法合併的導覽網格多邊形的邊的數量。這些邊仍然可以通過邊緣接近或使用連結而被連接。

Monitor NAVIGATION_3D_OBSTACLE_COUNT = 58

Number of active navigation obstacles in the NavigationServer3D.

Monitor MONITOR_MAX = 59

代表 Monitor 列舉的大小。


enum MonitorType: 🔗

MonitorType MONITOR_TYPE_QUANTITY = 0

Monitor output is formatted as an integer value.

MonitorType MONITOR_TYPE_MEMORY = 1

Monitor output is formatted as computer memory. Submitted values should represent a number of bytes.

MonitorType MONITOR_TYPE_TIME = 2

Monitor output is formatted as time in milliseconds. Submitted values should represent a time in seconds (not milliseconds).

MonitorType MONITOR_TYPE_PERCENTAGE = 3

Monitor output is formatted as a percentage. Submitted values should represent a fractional value rather than the percentage directly, e.g. 0.5 for 50.00%.


方法說明

void add_custom_monitor(id: StringName, callable: Callable, arguments: Array = [], type: MonitorType = 0) 🔗

新增一個名為 id 的自訂監視器。可以在 id 中使用斜線分隔符號指定監視器的類別(例如:"Game/NumberOfNPCs")。如果有多個斜線分隔符,則使用預設的類別。預設類別是 "Custom"。如果給定的 id 已經存在,則列印一個錯誤。

func _ready():
    var monitor_value = Callable(self, "get_monitor_value")

    # 將名稱為“MyName”的監視器新增到類別“MyCategory”。
    Performance.add_custom_monitor("MyCategory/MyMonitor", monitor_value)

    # 將名稱為“MyName”的監視器新增到類別“Custom”。
    # 注意:“MyCategory/MyMonitor”和“MyMonitor”同名但不同 ID,所以程式碼有效。
    Performance.add_custom_monitor("MyMonitor", monitor_value)

    # 將名稱為“MyName”的監視器新增到類別“Custom”。
    # 注意:“MyMonitor”和“Custom/MyMonitor”名稱相同,類別相同,但 ID 不同,所以程式碼有效。
    Performance.add_custom_monitor("Custom/MyMonitor", monitor_value)

    # 將名稱為“MyCategoryOne/MyCategoryTwo/MyMonitor”的監視器新增到類別“Custom”。
    Performance.add_custom_monitor("MyCategoryOne/MyCategoryTwo/MyMonitor", monitor_value)

func get_monitor_value():
    return randi() % 25

除錯器呼叫可呼叫物件來獲取自訂監視器的值。可呼叫物件必須返回一個零或正整數或浮點數。

使用參數陣列中提供的參數來呼叫可呼叫物件。


Variant get_custom_monitor(id: StringName) 🔗

返回具有給定 id 的自訂監視器的值。呼叫這個可呼叫物件以獲取自訂監視器的值。另請參閱 has_custom_monitor()。如果給定的 id 不存在,則列印一個錯誤。


Array[StringName] get_custom_monitor_names() 🔗

以一個 Array,返回活動自訂監視器的名稱。


PackedInt32Array get_custom_monitor_types() 🔗

Returns the MonitorType values of active custom monitors in an Array.


float get_monitor(monitor: Monitor) const 🔗

返回任一可用的內建監視器的值。應該提供任一 Monitor 常數作為參數,如下所示:

print(Performance.get_monitor(Performance.TIME_FPS)) # 將 FPS 列印到控制台。

請參閱 get_custom_monitor(),以查詢自訂效能監視器的值。


int get_monitor_modification_time() 🔗

返回自訂監視器被新增/刪除時的最後一個刻度(自引擎啟動以來的微秒數)。當該監視器更新時,它被設定為 Time.get_ticks_usec()


bool has_custom_monitor(id: StringName) 🔗

如果存在具有給定 id 的自訂監視器,則返回 true,否則返回 false


void remove_custom_monitor(id: StringName) 🔗

移除具有給定 id 的自訂監視器。如果給定的 id 已經不存在,則列印一個錯誤。