- 重组文档目录结构: 每个模块的概述页移动到模块子目录 - 重命名 index.md 为 main.md - 修正所有模块文档中的错误: - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式 - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节 - core: 修复 types 链接错误 - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI - memory: 修复头文件路径, malloc vs operator new, 新增方法文档 - resources: 修复 Shader/Texture 链接错误 - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接 - 验证: fix_links.py 确认 0 个断裂引用
113 lines
2.5 KiB
Markdown
113 lines
2.5 KiB
Markdown
# Profiler
|
|
|
|
**命名空间**: `XCEngine::Debug`
|
|
|
|
**类型**: `class` (singleton)
|
|
|
|
**描述**: 性能分析器单例,用于测量代码块执行时间并支持 Chrome Tracing 格式导出。
|
|
|
|
## 概述
|
|
|
|
`Profiler` 是 XCEngine 的性能分析工具。它通过栈式记录和采样方式跟踪函数执行时间,支持导出为 Chrome Tracing 格式(可通过 Chrome 的 `chrome://tracing` 查看)。
|
|
|
|
## 单例访问
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `static Profiler& Get()` | 获取单例实例 |
|
|
|
|
## 公共方法
|
|
|
|
### 生命周期
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `void Initialize()` | [初始化性能分析器](initialize.md) |
|
|
| `void Shutdown()` | [关闭性能分析器](shutdown.md) |
|
|
|
|
### 性能测量
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `void BeginProfile(const char* name)` | [开始一个性能分析块](beginprofile.md) |
|
|
| `void EndProfile()` | [结束当前性能分析块](endprofile.md) |
|
|
|
|
### 帧管理
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `void BeginFrame()` | [开始一帧的分析](beginframe.md) |
|
|
| `void EndFrame()` | [结束一帧的分析](endframe.md) |
|
|
|
|
### 事件标记
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `void MarkEvent(const char* name, uint64_t timestamp, uint32_t threadId)` | [标记一个事件点](markevent.md) |
|
|
| `void SetMarker(const char* name, uint32_t color)` | [设置帧标记](setmarker.md) |
|
|
|
|
### 导出
|
|
|
|
| 方法 | 描述 |
|
|
|------|------|
|
|
| `void ExportChromeTracing(const Containers::String& filePath)` | [导出为 Chrome Tracing JSON 格式](exportchrometracing.md) |
|
|
|
|
## 宏定义
|
|
|
|
### XE_PROFILE_BEGIN
|
|
|
|
```cpp
|
|
#define XE_PROFILE_BEGIN(name) XCEngine::Debug::Profiler::Get().BeginProfile(name)
|
|
```
|
|
|
|
开始分析指定名称的代码块。
|
|
|
|
### XE_PROFILE_END
|
|
|
|
```cpp
|
|
#define XE_PROFILE_END() XCEngine::Debug::Profiler::Get().EndProfile()
|
|
```
|
|
|
|
结束当前分析块。
|
|
|
|
### XE_PROFILE_FUNCTION
|
|
|
|
```cpp
|
|
#define XE_PROFILE_FUNCTION() XE_PROFILE_BEGIN(__FUNCTION__)
|
|
```
|
|
|
|
自动使用当前函数名进行分析。
|
|
|
|
## 使用示例
|
|
|
|
```cpp
|
|
Profiler::Get().Initialize();
|
|
|
|
void RenderFrame() {
|
|
XE_PROFILE_FUNCTION();
|
|
|
|
{
|
|
XE_PROFILE_BEGIN("UpdateGeometry");
|
|
UpdateGeometry();
|
|
XE_PROFILE_END();
|
|
}
|
|
|
|
{
|
|
XE_PROFILE_BEGIN("DrawCalls");
|
|
DrawCalls();
|
|
XE_PROFILE_END();
|
|
}
|
|
}
|
|
|
|
Profiler::Get().BeginFrame();
|
|
// ... 渲染帧 ...
|
|
Profiler::Get().EndFrame();
|
|
Profiler::Get().ExportChromeTracing("profile.json");
|
|
Profiler::Get().Shutdown();
|
|
```
|
|
|
|
## 相关文档
|
|
|
|
- [Debug 模块总览](../debug.md) - 返回模块总览
|
|
- [Logger](../logger/logger.md) - 日志记录器
|