]>
git.proxmox.com Git - rustc.git/blob - vendor/rustc-rayon/examples/cpu_monitor.rs
6 Usage: cpu_monitor [options] <scenario>
9 A test for monitoring how much CPU usage Rayon consumes under various
10 scenarios. This test is intended to be executed interactively, like so:
12 cargo run --example cpu_monitor -- tasks_ended
14 The list of scenarios you can try are as follows:
16 - tasks_ended: after all tasks have finished, go to sleep
17 - task_stall_root: a root task stalls for a very long time
18 - task_stall_scope: a task in a scope stalls for a very long time
21 -h, --help Show this message.
22 -d N, --depth N Control how hard the dummy task works [default: 27]
25 #[derive(serde::Deserialize)]
32 let args
: &Args
= &Docopt
::new(USAGE
)
33 .and_then(|d
| d
.deserialize())
34 .unwrap_or_else(|e
| e
.exit());
36 match &args
.arg_scenario
[..] {
37 "tasks_ended" => tasks_ended(args
),
38 "task_stall_root" => task_stall_root(args
),
39 "task_stall_scope" => task_stall_scope(args
),
41 println
!("unknown scenario: `{}`", args
.arg_scenario
);
42 println
!("try --help");
49 let mut input
= String
::new();
50 io
::stdin().read_line(&mut input
).unwrap();
53 fn task(args
: &Args
) {
54 fn join_recursively(n
: usize) {
58 rayon
::join(|| join_recursively(n
- 1), || join_recursively(n
- 1));
61 println
!("Starting heavy work at depth {}...wait.", args
.flag_depth
);
62 join_recursively(args
.flag_depth
);
63 println
!("Heavy work done; check top. You should see CPU usage drop to zero soon.");
64 println
!("Press <enter> to quit...");
67 fn tasks_ended(args
: &Args
) {
72 fn task_stall_root(args
: &Args
) {
73 rayon
::join(|| task(args
), wait_for_user
);
76 fn task_stall_scope(args
: &Args
) {
77 rayon
::scope(|scope
| {
78 scope
.spawn(move |_
| task(args
));
79 scope
.spawn(move |_
| wait_for_user());