diff --git a/docs/en/querying.md b/docs/en/querying.md index 2c5e1b3..f71a21a 100644 --- a/docs/en/querying.md +++ b/docs/en/querying.md @@ -64,15 +64,26 @@ Parameters: ## Output Format -Results display as a list: -- Shows first 10 results -- If more than 10, shows remaining count +All results are displayed by default. Use `-n` to limit the number of rows shown: ``` -Found 150 results: +# Show all results (default) +pt-snap query --template-use leak_detection + +# Show only first 5 +pt-snap query --template-use leak_detection -n 5 + +# Show all results (explicit) +pt-snap query --template-use leak_detection -n 0 +``` + +Example output (with `-n 2`): + +``` +Found 150 results, showing 2: {'id': 1, 'address': '0x1000', 'size': 2048, ...} - ... - ... and 140 more + {'id': 2, 'address': '0x2000', 'size': 4096, ...} + ... and 148 more (use -n to show more) ``` ## Template Architecture diff --git a/docs/zh/querying.md b/docs/zh/querying.md index 0a8fc39..2392cc3 100644 --- a/docs/zh/querying.md +++ b/docs/zh/querying.md @@ -64,15 +64,26 @@ pt-snap query --template-use leak_detection --params '{"min_size": 1024}' ## 输出格式 -结果以列表形式展示: -- 显示前 10 条结果 -- 超过 10 条时,显示剩余数量 +默认情况下显示所有结果。使用 `-n` 限制显示行数: ``` -Found 150 results: +# 显示所有结果(默认) +pt-snap query --template-use leak_detection + +# 仅显示前 5 条 +pt-snap query --template-use leak_detection -n 5 + +# 显示所有结果(显式) +pt-snap query --template-use leak_detection -n 0 +``` + +示例输出(使用 `-n 2`): + +``` +Found 150 results, showing 2: {'id': 1, 'address': '0x1000', 'size': 2048, ...} - ... - ... and 140 more + {'id': 2, 'address': '0x2000', 'size': 4096, ...} + ... and 148 more (use -n to show more) ``` ## 模板架构 diff --git a/src/pt_snap_cli/cli.py b/src/pt_snap_cli/cli.py index 3cf3457..040f643 100644 --- a/src/pt_snap_cli/cli.py +++ b/src/pt_snap_cli/cli.py @@ -210,6 +210,13 @@ def query_database( autocompletion=complete_template_names, ), ] = None, + max_rows: Annotated[ + int | None, + typer.Option( + "-n", + help="Maximum number of result rows to display (<= 0 for unlimited, default: unlimited)", + ), + ] = None, ) -> None: """Execute queries on the memory snapshot database. @@ -400,11 +407,13 @@ def query_database( results = executor.execute_template(template_use, query_params, device_id=target_device) if results: - typer.echo(f"Found {len(results)} results:") - for row in results[:10]: + effective_limit = max_rows if max_rows is not None and max_rows > 0 else len(results) + display = results[:effective_limit] + typer.echo(f"Found {len(results)} results, showing {len(display)}:") + for row in display: typer.echo(f" {row}") - if len(results) > 10: - typer.echo(f" ... and {len(results) - 10} more") + if effective_limit < len(results): + typer.echo(f" ... and {len(results) - effective_limit} more (use -n to show more)") else: typer.echo("No results found.") diff --git a/src/pt_snap_cli/query/templates/basic/allocation.yaml b/src/pt_snap_cli/query/templates/basic/allocation.yaml index 49d518a..ea5e13b 100644 --- a/src/pt_snap_cli/query/templates/basic/allocation.yaml +++ b/src/pt_snap_cli/query/templates/basic/allocation.yaml @@ -42,9 +42,9 @@ queries: description: Sort direction (ASC or DESC) limit: type: int - default: 1000 + default: -1 required: false - description: Maximum rows to return + description: Maximum rows to return (-1 for unlimited) offset: type: int default: 0 diff --git a/src/pt_snap_cli/query/templates/basic/block.yaml b/src/pt_snap_cli/query/templates/basic/block.yaml index e7d7ade..feb9b8c 100644 --- a/src/pt_snap_cli/query/templates/basic/block.yaml +++ b/src/pt_snap_cli/query/templates/basic/block.yaml @@ -77,9 +77,9 @@ queries: description: Sort direction (ASC or DESC) limit: type: int - default: 100 + default: -1 required: false - description: Maximum rows to return + description: Maximum rows to return (-1 for unlimited) offset: type: int default: 0 diff --git a/src/pt_snap_cli/query/templates/basic/event.yaml b/src/pt_snap_cli/query/templates/basic/event.yaml index ee97b20..6a85602 100644 --- a/src/pt_snap_cli/query/templates/basic/event.yaml +++ b/src/pt_snap_cli/query/templates/basic/event.yaml @@ -67,9 +67,9 @@ queries: description: Sort direction (ASC or DESC) limit: type: int - default: 1000 + default: -1 required: false - description: Maximum rows to return + description: Maximum rows to return (-1 for unlimited) offset: type: int default: 0