@@ -44,7 +44,7 @@ help [command]
4444View Python execution stack information for all threads currently running in the process, and support analyzing native stacks and exporting to files.
4545
4646``` shell
47- stack [pid] [-f < value> ] [--native]
47+ stack [pid] [-f < value> ] [--native] [-a | --async]
4848```
4949
5050##### Parameter Analysis
@@ -53,6 +53,7 @@ stack [pid] [-f <value>] [--native]
5353| pid | No | Process ID to analyze, defaults to the injected process ID | 3303 |
5454| -f, --filepath | No | File path to export thread stacks to | /home/admin/stack.log |
5555| --native | No | Whether to analyze native stacks of Python threads, defaults to False | --native |
56+ | -a, --async | No | Whether to display async coroutine/task stacks | -a |
5657
5758##### Output Display
5859Command examples:
6465# View native stacks of Python threads
6566stack --native
6667
68+ # View async coroutine/task stacks
69+ stack -a
70+ stack --async
71+
6772# Export execution stack information to a file
6873stack -f ./stack.log
6974```
@@ -80,19 +85,58 @@ Analyzing native thread stacks:
8085View Python execution stack information for all threads currently running in the process, and support exporting to files.
8186
8287``` shell
83- stack [filepath]
88+ stack [filepath] [-a | --async]
8489```
8590
8691##### Parameter Analysis
8792| Parameter | Required | Meaning | Example |
8893| --- | --- | --- | --- |
8994| filepath | No | File path to export thread stacks to | /home/admin/stack.log |
95+ | -a, --async | No | Whether to display async coroutine/task stacks | -a |
9096
9197##### Output Display
9298Executing the ` stack ` command will display stack information for all threads in the console.
9399
94100![ img.png] ( https://raw.githubusercontent.com/alibaba/PyFlightProfiler/refs/heads/main/docs/images/stack_mac.png )
95101
102+ ### Async Coroutine Stack: stack --async
103+ View all async coroutines/tasks running across all event loops in all threads.
104+
105+ ``` shell
106+ stack -a
107+ stack --async
108+ ```
109+
110+ The async stack display shows:
111+ - ** Thread** : The thread where the event loop is running
112+ - ** Task Name** : The asyncio Task name
113+ - ** State** : Task state (PENDING, WAITING, FINISHED, CANCELLED, FAILED)
114+ - ** Coroutine** : The coroutine function name
115+ - ** Stack** : Full coroutine call chain following the ` cr_await ` chain
116+
117+ Example output:
118+ ```
119+ ============================================================
120+ Async Coroutine/Task Stacks
121+ ============================================================
122+
123+ Thread: AsyncEventLoop (tid: 0x16f8a7000)
124+ --------------------------------------------------
125+
126+ Task #1: FetchAPI1
127+ State: WAITING
128+ Coroutine: fetch_data_loop
129+ Stack (3 frames):
130+ File "/app/demo.py", line 95, in fetch_data_loop
131+ await fetch_data(name, delay)
132+ File "/app/demo.py", line 26, in fetch_data
133+ await asyncio.sleep(delay)
134+ File "/usr/lib/python3.9/asyncio/tasks.py", line 649, in sleep
135+ return await future
136+
137+ ============================================================
138+ ```
139+
96140
97141## Method Execution Observation: watch
98142### Observing Method Input, Output, and Time Consumption
0 commit comments