inspect_task/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Logic for inspecting the task list.
5
6#![forbid(unsafe_code)]
7
8use inspect::Inspect;
9use pal_async::task::TaskData;
10use pal_async::task::TaskList;
11
12struct Wrap(Vec<TaskData>);
13
14impl Inspect for Wrap {
15    fn inspect(&self, req: inspect::Request<'_>) {
16        let mut resp = req.respond();
17        for task in &self.0 {
18            resp.child(&task.id().to_string(), |req| {
19                req.respond()
20                    .field("name", task.name())
21                    .field("executor", task.executor())
22                    .display("state", &task.state())
23                    .field(
24                        "location",
25                        format!("{}:{}", task.location().file(), task.location().line()),
26                    );
27            });
28        }
29    }
30}
31
32/// Takes a snapshot of the active tasks and returns them in an inspectable
33/// format.
34pub fn inspect_task_list() -> impl Inspect {
35    Wrap(TaskList::global().tasks())
36}