Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/quickstart/04-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Fluent API 构建 SQL 查询。
位于 `query/templates/` 目录,按分类组织:

- **Basic**: `active_blocks.yaml`, `blocks_by_size.yaml`, `events_by_action.yaml`, `memory_timeline.yaml`
- **Statistical**: `memory_summary.yaml`, `callstack_analysis.yaml`
- **Statistical**: `memory_peak.yaml`, `callstack_analysis.yaml`
- **Business**: `leak_detection.yaml`

## 使用示例
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pt-snap focus examples/snapshot_expandable.pkl.db --device 0
pt-snap query --list

# Run a query (automatically uses the focused device)
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak

# Detect potential memory leaks
pt-snap query --template-use leak_detection --params '{"min_size": 1024}'
Expand Down Expand Up @@ -51,7 +51,7 @@ See the [full quick start guide](docs/en/quickstart.md) for a walkthrough.
7 built-in templates across 3 categories:

- **Basic**: `active_blocks`, `blocks_by_size`, `events_by_action`, `memory_timeline`
- **Statistical**: `callstack_analysis`, `memory_summary`
- **Statistical**: `callstack_analysis`, `memory_peak`
- **Business**: `leak_detection`

See [Querying](docs/en/querying.md) for details.
Expand Down
4 changes: 2 additions & 2 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pt-snap focus examples/snapshot_expandable.pkl.db --device 0
pt-snap query --list

# 运行查询(自动使用 focus 中设置的设备)
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak

# 检测潜在内存泄漏
pt-snap query --template-use leak_detection --params '{"min_size": 1024}'
Expand Down Expand Up @@ -51,7 +51,7 @@ pt-snap query --template-use leak_detection --params '{"min_size": 1024}'
7 个内置模板,3 个分类:

- **Basic**: `active_blocks`, `blocks_by_size`, `events_by_action`, `memory_timeline`
- **Statistical**: `callstack_analysis`, `memory_summary`
- **Statistical**: `callstack_analysis`, `memory_peak`
- **Business**: `leak_detection`

详见 [Querying](docs/zh/querying.md)。
Expand Down
10 changes: 5 additions & 5 deletions docs/en/focus-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ When a shell or agent needs an isolated database without changing project focus:

```bash
export PT_SNAP_DB_PATH=/path/to/agent-specific/snapshot.db
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
```

Or validate and print the export command in one step:
Expand All @@ -57,10 +57,10 @@ Even with focus configured, you can temporarily specify a different database or

```bash
# Uses this database temporarily, does not affect saved focus
pt-snap query /path/to/other.db --template-use memory_summary
pt-snap query /path/to/other.db --template-use memory_peak

# Override device (ignores focused device_id)
pt-snap query --template-use memory_summary --device 2
pt-snap query --template-use memory_peak --device 2
```

## Legacy Global Configuration
Expand Down Expand Up @@ -101,15 +101,15 @@ pt-snap config --clear # Clear global configuration
**No focus configured:**

```bash
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
# Error: No database path specified and no database configured.
# Use 'pt-snap focus <database_path>' to set a project database, or provide db_path argument.
```

**Database file not found:**

```bash
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
# Error: Database from project focus not found: /path/to/missing.db
# Use 'pt-snap focus <new_database_path>' to set a new project database, or provide db_path argument.
```
2 changes: 1 addition & 1 deletion docs/en/querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Aggregation and analysis.
| Template | Description |
|----------|-------------|
| `callstack_analysis` | Analyze callstack information |
| `memory_summary` | Memory usage statistics |
| `memory_peak` | Peak memory metrics |

### Business Queries

Expand Down
2 changes: 1 addition & 1 deletion docs/en/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pt-snap query --list
### Step 3: Run a Query

```bash
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
```

### Step 4: Try Advanced Queries
Expand Down
10 changes: 5 additions & 5 deletions docs/zh/focus-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pt-snap focus --device 1

```bash
export PT_SNAP_DB_PATH=/path/to/agent-specific/snapshot.db
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
```

或在验证数据库的同时输出 export 命令:
Expand All @@ -57,10 +57,10 @@ pt-snap focus

```bash
# 仅本次查询使用该数据库,不影响已保存的 focus
pt-snap query /path/to/other.db --template-use memory_summary
pt-snap query /path/to/other.db --template-use memory_peak

# 覆盖设备(忽略 focus 中的 device_id)
pt-snap query --template-use memory_summary --device 2
pt-snap query --template-use memory_peak --device 2
```

## Legacy 全局配置
Expand Down Expand Up @@ -101,15 +101,15 @@ pt-snap config --clear # 清除全局配置
**未设置焦点时查询:**

```bash
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
# Error: No database path specified and no database configured.
# Use 'pt-snap focus <database_path>' to set a project database, or provide db_path argument.
```

**数据库文件不存在:**

```bash
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
# Error: Database from project focus not found: /path/to/missing.db
# Use 'pt-snap focus <new_database_path>' to set a new project database, or provide db_path argument.
```
2 changes: 1 addition & 1 deletion docs/zh/querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pt-snap query [--template-use <template_name>] [--params <json>] [--device <id>]
| 模板 | 说明 |
|------|------|
| `callstack_analysis` | 调用栈分析 |
| `memory_summary` | 内存使用统计摘要 |
| `memory_peak` | 峰值内存指标 |

### Business Queries

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pt-snap query --list
### 第三步:运行查询

```bash
pt-snap query --template-use memory_summary
pt-snap query --template-use memory_peak
```

### 第四步:尝试高级查询
Expand Down
60 changes: 60 additions & 0 deletions src/pt_snap_cli/query/templates/memory_peak.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: "1.0"
queries:
memory_peak:
category: statistical
description: Get peak memory metrics from trace events with corresponding event IDs
devices:
- all
parameters:
start_id:
type: int
default: null
required: false
description: Start event ID for range filtering
end_id:
type: int
default: null
required: false
description: End event ID for range filtering
query: |
SELECT
(SELECT MAX(allocated) FROM {{ device_trace_table }}
{% if start_id is not none %}WHERE id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}WHERE id <= {{ end_id|int }}{% endif %}
) as peak_allocated,
(SELECT MIN(id) FROM {{ device_trace_table }}
WHERE allocated = (SELECT MAX(allocated) FROM {{ device_trace_table }}
{% if start_id is not none %}WHERE id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}WHERE id <= {{ end_id|int }}{% endif %}
)
{% if start_id is not none %}AND id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}AND id <= {{ end_id|int }}{% endif %}
) as peak_allocated_event_id,
(SELECT MAX(active) FROM {{ device_trace_table }}
{% if start_id is not none %}WHERE id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}WHERE id <= {{ end_id|int }}{% endif %}
) as peak_active,
(SELECT MIN(id) FROM {{ device_trace_table }}
WHERE active = (SELECT MAX(active) FROM {{ device_trace_table }}
{% if start_id is not none %}WHERE id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}WHERE id <= {{ end_id|int }}{% endif %}
)
{% if start_id is not none %}AND id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}AND id <= {{ end_id|int }}{% endif %}
) as peak_active_event_id,
(SELECT MAX(reserved) FROM {{ device_trace_table }}
{% if start_id is not none %}WHERE id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}WHERE id <= {{ end_id|int }}{% endif %}
) as peak_reserved,
(SELECT MIN(id) FROM {{ device_trace_table }}
WHERE reserved = (SELECT MAX(reserved) FROM {{ device_trace_table }}
{% if start_id is not none %}WHERE id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}WHERE id <= {{ end_id|int }}{% endif %}
)
{% if start_id is not none %}AND id >= {{ start_id|int }}{% if end_id is not none %} AND id <= {{ end_id|int }}{% endif %}{% elif end_id is not none %}AND id <= {{ end_id|int }}{% endif %}
) as peak_reserved_event_id
output_schema:
- column: peak_allocated
type: int
- column: peak_allocated_event_id
type: int
- column: peak_active
type: int
- column: peak_active_event_id
type: int
- column: peak_reserved
type: int
- column: peak_reserved_event_id
type: int
26 changes: 0 additions & 26 deletions src/pt_snap_cli/query/templates/memory_summary.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/query/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_list_by_category_statistical(self):

result = list_by_category("statistical")
assert "test_stat" in result
assert "memory_summary" in result
assert "memory_peak" in result

def test_list_by_category_business(self):
register_query(QueryTemplate(name="test_biz", query="SELECT 1", category="business"))
Expand Down
Loading