Metadata-Version: 2.3
Name: perfetto_extras
Version: 0.2.0
Summary: 
Author: liumoulu
Requires-Python: >=3.11
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: click (>=8.2.1,<9.0.0)
Requires-Dist: protobuf (==5.29.3)
Description-Content-Type: text/markdown

# perfetto_extras

基于 Perfetto 的 Python 工具包，提供 trace 事件生成与浏览器可视化能力。

## 特性

- **trace_events**：便捷生成符合 Perfetto 规范的 trace 事件，可自定义进程、线程、事件类型等。
- **opentrace**：一键在浏览器中打开本地 trace 文件，自动本地 HTTP 服务并跳转至 [ui.perfetto.dev](https://ui.perfetto.dev)。

## 安装

```bash
pip install perfetto_extras
```

或使用 poetry：

```bash
poetry add perfetto_extras
```

## 快速开始

### 1. 生成 Trace 事件

```python
from perfetto_extras import trace_events

# 创建 Trace 对象
t = trace_events.Trace()
# 创建进程轨迹
track = t.create_process_track("MyProcess", "category")
# 添加线程轨迹
thread = track.create_thread_track("MainThread", "category")
# 添加事件
thread.add_complete_event("event1", ts=0, duration_us=1000, args={"foo": 1})

# 导出为 JSON
with open("my_trace.json", "w") as f:
    f.write(t.dumps(indent=2, ensure_ascii=False))
```

### 2. 浏览器可视化 Trace 文件

```bash
poetry run python -m perfetto_extras.opentrace my_trace.json
```
或
```bash
python -m perfetto_extras.opentrace my_trace.json
```

命令会自动打开浏览器并加载本地 trace 文件到 Perfetto UI。

## 目录结构

```
perfetto_extras/
    trace_events.py   # Trace 事件生成核心模块
    opentrace.py      # 浏览器可视化工具
pyproject.toml        # 项目配置与依赖
README.md             # 使用说明
```

## 依赖

- Python >= 3.11
- protobuf == 5.29.3
- click >= 8.2.1, <9.0.0

## 贡献

欢迎提交 issue 和 PR！

1. Fork 本仓库
2. 新建分支
3. 提交修改
4. 发起 Pull Request

## License

MIT

---

**温馨提示：**  
- 如果你的包有更多功能、API 或命令行参数，请在 README 里详细补充示例和说明。
- 如果有徽章（如 PyPI 版本、CI 状态），可以加在最上面。

如需根据你的实际 API 或功能进一步定制，请把主要功能点或代码片段发给我，我可以帮你写得更详细！
