Files
XCEngine/docs/api/XCEngine/Debug/Profiler/EndProfile.md

49 lines
843 B
Markdown
Raw Normal View History

2026-03-26 16:45:24 +08:00
# Profiler::EndProfile
2026-03-26 17:21:44 +08:00
结束最近一次开始的 profile 区段,并记录其耗时。
2026-03-26 16:45:24 +08:00
```cpp
void EndProfile();
```
2026-03-26 17:21:44 +08:00
## 行为说明
2026-03-26 16:45:24 +08:00
2026-03-26 17:21:44 +08:00
当前实现会:
2026-03-26 16:45:24 +08:00
2026-03-26 17:21:44 +08:00
1. 检查内部栈是否为空;为空则直接返回。
2. 读取当前微秒时间作为结束时间。
3. 弹出最近一个 `ProfileNode`
4. 计算区段耗时并把结果追加到内部 `m_samples`
2026-03-26 16:45:24 +08:00
2026-03-26 17:21:44 +08:00
当前不会:
- 验证开始与结束是否发生在同一线程。
- 提供读取样本的公开 API。
## 参数
- 无。
## 返回值
- 无。
## 线程语义
- 必须与 [BeginProfile](BeginProfile.md) 形成正确的 LIFO 配对。
## 示例
2026-03-26 16:45:24 +08:00
```cpp
2026-03-26 17:21:44 +08:00
using namespace XCEngine::Debug;
2026-03-26 16:45:24 +08:00
2026-03-26 17:21:44 +08:00
Profiler::Get().BeginProfile("FrameBuild");
// ...
Profiler::Get().EndProfile();
2026-03-26 16:45:24 +08:00
```
## 相关文档
2026-03-26 17:21:44 +08:00
- [返回类型总览](Profiler.md)
- [BeginProfile](BeginProfile.md)