Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

Profiler

class in UnityEngine.Profiling

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Controls the Profiler from script.

You can add custom Profiler sections in your scripts with Profiler.BeginSample and Profiler.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 application, most of the Profiler API functionality is only available when you enable the Development Build option or set the ManagedCodeVariant to one that defines the ENABLE_PROFILER scripting symbol. Disabling Development Build makes your application 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, which are available even if you don't enable Development Build or select a ManagedCodeVariant that doesn't define the ENABLE_PROFILER scripting symbol. This is because Unity manages most of its system memory at runtime, which means it can provide that information with no impact on performance. This applies to all memory-related Profiler API methods except Profiler.GetAllocatedMemoryForGraphicsDriver and Profiler.GetRuntimeMemorySizeLong, because they require extra profiling data only available in development builds.

Static Properties

Property Description
areaCountThe number of Profiler Areas that you can profile.
enableAllocationCallstacksEnables the recording of callstacks for managed allocations.
enableBinaryLogEnables the logging of profiling data to a file.
enabledEnables the Profiler.
logFileSpecifies the file to use when writing profiling data.
maxUsedMemorySets the maximum amount of memory that Profiler uses for buffering data. This property is expressed in bytes.
usedHeapSizeLongReturns the number of bytes that Unity has allocated. This does not include bytes allocated by external libraries or drivers.

Static Methods

Method Description
AddFramesFromFileDisplays the recorded profile data in the profiler.
BeginSampleBegin profiling a piece of code with a custom label.
BeginThreadProfilingEnables profiling on the thread from which you call this method.
EmitFrameMetaDataWrite metadata associated with the current frame to the Profiler stream.
EmitSessionMetaDataWrite metadata associated with the whole Profiler session capture.
EndSampleEnds the current profiling sample.
EndThreadProfilingFrees the internal resources used by the Profiler for the thread.
GetAllCategoriesReturns all ProfilerCategory registered in Profiler.
GetAllocatedMemoryForGraphicsDriverReturns the estimated amount of allocated memory for the graphics driver, in bytes.
GetAreaEnabledReturns whether or not a given ProfilerArea is currently enabled.
GetCategoriesCountReturns number of ProfilerCategory registered in Profiler.
GetMonoHeapSizeLongReturns the size of the reserved space for managed-memory.
GetMonoUsedSizeLongGets the allocated managed memory for live objects and non-collected objects.
GetRuntimeMemorySizeLongGathers the native-memory used by a Unity object.
GetTempAllocatorSizeReturns the size of the temp allocator.
GetTotalAllocatedMemoryLongThe total memory allocated by the internal allocators in Unity. Unity reserves large pools of memory from the system; this includes double the required memory for textures because Unity keeps a copy of each texture on both the CPU and GPU. This function returns the amount of used memory in those pools.
GetTotalFragmentationInfoReturns heap memory fragmentation information.
GetTotalReservedMemoryLongThe total memory Unity has reserved.
GetTotalUnusedReservedMemoryLongUnity allocates memory in pools for usage when unity needs to allocate memory. This function returns the amount of unused memory in these pools.
IsCategoryEnabledReturns whether or not a given ProfilerCategory is currently enabled.
SetAreaEnabledEnable or disable a given ProfilerArea.
SetCategoryEnabledEnable or disable a given ProfilerCategory.
SetScreenshotCaptureFrameIntervalAlter the rate that the Profiler takes a new screenshot for capture list thumbnails.
SetTempAllocatorRequestedSizeSets the size of the temp allocator.