Profiler

class in UnityEngine.Profiling

Switch to Manual

Description

通过脚本控制 Profiler

您可以使用 Profiler.BeginSampleProfiler.EndSample 在脚本中添加自定义性能分析器部分。

On standalone platforms, you can save all profiling information to a file, which allows you to inspect it later. To do this, you must specify a Profiler.logFile and set both Profiler.enabled and Profiler.enableBinaryLog to true.

Because use of the Profiler negatively affects the performance of your app, most of the Profiler API functionality is only available when "Development Build" is enabled. This means you must enable "Developer Build" if you want to use profiler API methods in your built app. Disabling "Development Build" makes your app run faster, but prevents you from using most of the Profiler API methods.

The exception to this are the Profiler API methods relating to memory usage. Because Unity manages most of its system memory at run-time, it can provide that information with no performance penalty, therefore those methods are available even if "Development Build" is not enabled. This applies to all memory-related Profiler API methods except Profiler.GetAllocatedMemoryForGraphicsDriver and Profiler.GetRuntimeMemorySizeLong, since they require extra profiling data only available in development builds.

Static Variables

areaCountThe number of Profiler Areas that you can profile.
enableBinaryLog启用将性能分析数据记录到文件中的功能。
enabled启用性能分析器。
logFile指定写入性能分析数据时要使用的文件。
maxUsedMemorySets the maximum amount of memory that Profiler uses for buffering data. This property is expressed in bytes.
usedHeapSizeLong返回 Unity 已分配的字节数。这不包括外部库或驱动程序分配的字节。

Static Functions

AddFramesFromFile显示性能分析器中记录的性能分析数据。
BeginSample开始使用自定义标签分析一段代码。
BeginThreadProfiling在调用此方法的线程上启用性能分析。
EndSample结束当前的性能分析样本。
EndThreadProfiling释放性能分析器用于线程的内部资源。
GetAllocatedMemoryForGraphicsDriver返回为图形驱动程序分配的内存大小(以字节为单位)。Only available in development players and editor.
GetAreaEnabledReturns whether or not a given ProfilerArea is currently enabled.
GetMonoHeapSizeLong返回托管内存的预留空间大小。
GetMonoUsedSizeLong活动对象和非收集对象的已分配托管内存。
GetRuntimeMemorySizeLong收集 Unity 对象使用的本机内存。
GetTempAllocatorSize返回临时分配器的大小。
GetTotalAllocatedMemoryLongUnity 中的内部分配器分配的内存总量。Unity 在系统中预留了大型内存池。此函数将返回这些池中使用的内存量。
GetTotalReservedMemoryLongUnity 预留的总内存。
GetTotalUnusedReservedMemoryLong当 Unity 需要分配内存时,Unity 会在池中分配内存以供使用。此函数返回这些池中未使用的内存量。
SetAreaEnabledEnable or disable a given ProfilerArea.
SetTempAllocatorRequestedSize设置临时分配器的大小。