EM_Task/TraceInsights/.trae/documents/plan_20260212_063942.md
Boshuang Zhao 5144a49c9b add
2026-02-13 16:18:33 +08:00

91 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## MinimalTimerExporter 增量导出框架重构计划
### 目标
`BuildEventTreeForFrame()` 改造为**流式增量处理模式**,支持大区间安全扫描,避免内存溢出。
---
### 步骤 1: 重构 IEventWriter 接口
**目标**:增加分段感知能力
**变更**
```cpp
// IEventWriter 新增方法
virtual void BeginLogicalChunk(int32 ChunkIndex) = 0;
virtual void EndLogicalChunk(int32 ChunkIndex) = 0;
virtual void Flush() = 0;
virtual bool WantsStructuredPath() const { return false; }
```
**新增**
- `FStructuredEventData` 结构体,用于传递树形事件数据
---
### 步骤 2: 重构 BuildEventTreeForFrame
**目标**:增量流式处理,内部判断 flush 时机
**核心逻辑**
```cpp
void BuildEventTreeForFrame(
const Trace::ITimingProfilerProvider::Timeline& Timeline,
const Trace::ITimingProfilerTimerReader* TimerReader,
double StartTime,
double EndTime,
IEventWriter& Writer, // 改为接口依赖
int32 EventsPerChunk = 10000) // 可配置的 flush 阈值
{
// 1. Writer.BeginLogicalChunk(0)
// 2. 迭代 EnumerateEvents
// 3. 内部维护 Stack 构建树
// 4. 当处理事件数 >= EventsPerChunk 时:
// - Writer.EndLogicalChunk(chunkIndex)
// - Writer.Flush()
// - 清空 StackchunkIndex++
// - Writer.BeginLogicalChunk(chunkIndex)
// 5. 结束时 Writer.EndLogicalChunk()
}
```
---
### 步骤 3: 重构 FJsonEventWriter
**适配新的 Writer 接口**
- 实现 `BeginLogicalChunk()` / `EndLogicalChunk()`
- 支持 JSON 数组内的分段标记
- 确保每个 chunk 都是自洽的 JSON
---
### 步骤 4: 保持 FCsvEventWriter 兼容
- 实现新的接口方法(空实现或基本转发)
- 保持原有 CSV 格式兼容
---
### 步骤 5: 重构 RunExport
**目标**:统一调度入口
**变更**
- 引入 `ExportCoordinator` 类(如果需要)
- 或者增强现有 `RunExport()` 函数
- 支持传入 `WantsStructuredPath()` 判断
---
### 步骤 6: 清理与重构
**重命名建议**
- `BuildEventTreeForFrame``StreamEventsWithTreeBuilding`(更准确描述行为)
- `FCsvEventWriter``CsvEventWriter`(去掉无意义的 F 前缀)
- `FJsonEventWriter``JsonEventWriter`
- `FExportChunker``ChunkingFileWriter`
**清理**
- 移除未使用的 `ExportMetadataToCSV`(功能重复)
- 统一导出入口点