录制特定采样器生成的性能分析数据。
录制器会累积帧期间每个 Begin/End 对所用的时间。 启用后,它会对采样器生成的 Begin 和 End 样本之间的增量时间求和。 使用 elapsedNanoseconds 可获取前一帧的累积时间。
using UnityEngine; using UnityEngine.Profiling;
public class ExampleClass : MonoBehaviour { Recorder behaviourUpdateRecorder; void Start() { behaviourUpdateRecorder = Recorder.Get("BehaviourUpdate"); behaviourUpdateRecorder.enabled = true; }
void Update() { if (behaviourUpdateRecorder.isValid) Debug.Log("BehaviourUpdate time: " + behaviourUpdateRecorder.elapsedNanoseconds); } }
注意:
无论性能分析器状态如何,录制器都会收集数据。启用录制器后,每次按采样器时都会累积数据。
这些信息等同于您在 Profiler Window 的 Hierarchy 视图中看到的信息。
目前,采样器仅在 Editor 和 Development Player 中可用。使用 Recorder.isValid 可验证录制器能否收集数据。
录制器仅支持内部静态性能分析器标签以及 CustomSampler 生成的标签。
不支持脚本方法调用生成的动态内部标签以及 Profiler.BeginSample 生成的标签。
另请参阅:Sampler、Recorder.isValid、Recorder.elapsedNanoseconds。
elapsedNanoseconds | 前一帧的 Begin/End 对的累积时间(以纳秒为单位)。(只读) |
enabled | 启用录制。 |
gpuElapsedNanoseconds | Gets the accumulated GPU time, in nanoseconds, for a frame. The Recorder has a three frame delay so this gives the timings for the frame that was three frames before the one that you access this property on. (Read Only). |
gpuSampleBlockCount | Gets the number of Begin/End time pairs that the GPU executed during a frame. The Recorder has a three frame delay so this gives the timings for the frame that was three frames before the one that you access this property on. (Read Only). |
isValid | 如果录制器有效且可收集数据,则返回 true。(只读) |
sampleBlockCount | 在前一帧中调用 Begin/End 对的次数。(只读) |
CollectFromAllThreads | 将录制器配置为从所有线程收集样本。 |
FilterToCurrentThread | 将录制器配置为仅从当前线程收集数据。 |
Get | 使用此函数可获取特定性能分析器标签的录制器。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.