Version: 2020.2
LanguageEnglish
  • C#

ProfilerMarker

struct in Unity.Profiling

/

Implemented in:UnityEngine.CoreModule

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

Performance marker used for profiling arbitrary code blocks.

Use ProfilerMarker to mark up script code blocks for the Profiler.
The information produced by markers is displayed in the CPU Profiler and can be also captured with Recorder. During development (in Editor and Development Players) this can help to get performance overview of different parts of game code and identify performance issues.

using Unity.Profiling;

public class MySystemClass { static readonly ProfilerMarker s_PreparePerfMarker = new ProfilerMarker("MySystem.Prepare"); static readonly ProfilerMarker s_SimulatePerfMarker = new ProfilerMarker(ProfilerCategory.Ai, "MySystem.Simulate");

public void UpdateLogic() { s_PreparePerfMarker.Begin(); // ... s_PreparePerfMarker.End();

using (s_SimulatePerfMarker.Auto()) { // ... } } }

ProfilerMarker represents a named profiler handle and is the most efficient way of profiling your code. It can be used in jobified code.
Methods Begin and End are marked with ConditionalAttribute. They are conditionally compiled away and thus have zero overhead in non-Developmenet (Release) builds.

When Profiler collects instrumentation data, ProfilerMarker helps to reduce overhead and the amount of transferred data. Profiler.BeginSample transfers full string to the data stream while ProfilerMarker.Begin and CustomSampler.Begin only integer identifier of the marker.

Also ProfilerMarker.End provides a context information to the Recorder making it possible to track timings of a marked code in Players.

See Also: Recorder.

Properties

HandleGets native handle of the ProfilerMarker.

Constructors

ProfilerMarkerConstructs a new performance marker for code instrumentation.

Public Methods

AutoCreates a helper struct for the scoped using blocks.
BeginBegin profiling a piece of code marked with a custom name defined by this instance of ProfilerMarker.
EndEnd profiling a piece of code marked with a custom name defined by this instance of ProfilerMarker.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961