- Understand the behavior of your asynchronous tasks and futures.
▶️ New branch for tokio-runtime is working in progress
- Please install and build uftrace first
- Build your executable in debug mode
- With this tool, we can:
- Understand the behavior of rust asynchronous tasks, including the polling time of the futures and the waiting time of the futures
- Find out some abnormal execution patterns (long polling time may cause blocking)
- e.g. Here is a simple rust asynchronous program:
use async_std::task;
use std::time::Duration;
async fn my_test()
{
task::sleep(Duration::from_millis(100)).await;
}
#[async_std::main]
async fn main(){
my_test().await;
task::sleep(Duration::from_millis(150)).await;
}
And We can have a visualization for our rust asynchronous program:
- Clone the repository (No building needed)
- Move the profile directory into your
target
directory
profile
├── parser_nu.py
├── parser.py
└── profile.sh
- Run the profiler script:
For tracing all futures:
. profile.sh $EXECUTABLE_NAME $OUTPUT_FILE_NAME
Tracing the compiler generated futures only:
. profile.sh $EXECUTABLE_NAME $OUTPUT_FILE_NAME --generated-future
⚠️ The function location of futures are not provided by default, you can pass argument--get-location
to get locations. Note that if enable it, the progress will become very slow, see issue #2. - After executing the script, we get a json file in the profile directory
profile
├── parser_nu.py
├── parser.py
├── profile.sh
└── $OUTPUT_FILE_NAME.json
- Then we can use the trace-viewer to visualize the result:
- Open the chrome browser
- Type
chrome://tracing/
on your chrome browser - Load the json file generated by profiler
- Result example:
- Different task(future) instances should be recognized
- Combinators(e.g.
join!
,select!
) issues - Speed up for parsing and recording are neeeded
- Annotate different tasks with different colors
- Tracing progress should be done correctly in release mode
- Some locations information are wrong because of the same demangled symbol
This work was sponsored by the internship of ADLINK during 2021-2022.
- MIT license (http://opensource.org/licenses/MIT)