Skip to content

Conversation

dloukadakis
Copy link
Contributor

@dloukadakis dloukadakis commented Sep 3, 2025

Objective

Fixes #20802

Solution

System information diagnostics now uses a single task that wakes up every
time the First schedule runs. The task checks if enough time has
passed since the last refresh. If enough time has passed, it refreshes
the system information and sends it to a channel. The
read_diagonstic_task system then reads the system information from the
channel to add diagnostic data.

Testing

  • Did you test these changes? If so, how?
    I used the log diagnostics example and compare before the changes and after the changes to ensure it works similarly or better than before.
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
cargo run --example log_diagnostics
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test?
    Linux

@alice-i-cecile
Copy link
Member

This solves the same problem as #20845: we should pick one and coalesce our efforts :)

@dloukadakis dloukadakis force-pushed the bugfix/system-diagnostics-20802 branch from 399899a to c51744d Compare September 3, 2025 18:11
@NthTensor
Copy link
Contributor

I'll have to compare this with the other PR. It would be good for you too read over the comments on that one.

@dloukadakis
Copy link
Contributor Author

I just realized, I will review #20845 as well.

@dloukadakis
Copy link
Contributor Author

dloukadakis commented Sep 3, 2025

I measured the CPU usage between main, #20852 and #20845 letting it run for 20 seconds per test.

#20852 (this pull request)

2025-09-03T18:56:21.619919Z  INFO bevy_diagnostic: system/cpu_usage :    9.591195%  (avg 9.572284%)
2025-09-03T18:56:21.619952Z  INFO bevy_diagnostic: process/cpu_usage:    9.119496%  (avg 8.990516%)

#20845

It's not reporting correctly, my system CPU usage is 22%.

2025-09-03T19:01:52.360746Z  INFO bevy_diagnostic: system/cpu_usage :    1.999126%  (avg 1.998040%)
2025-09-03T19:01:52.360777Z  INFO bevy_diagnostic: process/cpu_usage:    0.000000%  (avg 0.000000%)

It works, when we fix https://github.com/bevyengine/bevy/pull/20845/files#r2319871486 , my system CPU usage drops to 16%, and it starts reporting correctly.

2025-09-03T19:05:57.686947Z  INFO bevy_diagnostic: system/cpu_usage :   16.323296%  (avg 16.180935%)
2025-09-03T19:05:57.686989Z  INFO bevy_diagnostic: process/cpu_usage:   16.006338%  (avg 15.766926%)

main (0ffd9d6)

2025-09-03T18:53:54.654583Z  INFO bevy_diagnostic: system/cpu_usage :   10.244648%  (avg 9.765763%)
2025-09-03T18:53:54.654623Z  INFO bevy_diagnostic: process/cpu_usage:    9.021406%  (avg 9.076174%)

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Diagnostics Logging, crash handling, error reporting and performance analysis S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 3, 2025
@dloukadakis dloukadakis force-pushed the bugfix/system-diagnostics-20802 branch 3 times, most recently from 701a0d7 to 1fdfb72 Compare September 3, 2025 21:39
Copy link
Contributor

@Olle-Lukowski Olle-Lukowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with this solution, I wrote my PR quite quickly honestly. And clearly that did not help with the quality. This looks better, and it's clear @dloukadakis has thoroughly tested this.

@dloukadakis dloukadakis force-pushed the bugfix/system-diagnostics-20802 branch from f022f67 to f247499 Compare September 4, 2025 10:55
Copy link
Contributor

@NthTensor NthTensor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. This pattern, keeping a task around which we wake every frame, is very interesting. I wonder if there are other places within the engine where this would be useful.

Since this uses some bits of async that people may not be familiar with, I'd really appreciate a small doc comment that explains what's going on. Maybe on the plugin itself?

System information diagnostics now uses a single task that wakes up every
time the `First` schedule runs. The task checks if enough time has
passed since the last refresh. If enough time has passed, it refreshes
the system information and sends it to a channel. The
`read_diagonstic_task` system then reads the system information from the
channel to add diagnostic data.
@dloukadakis dloukadakis force-pushed the bugfix/system-diagnostics-20802 branch from c82c366 to f1157b7 Compare September 5, 2025 18:23
Copy link
Contributor

@NthTensor NthTensor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work here, thank you.

@NthTensor NthTensor added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 8, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 8, 2025
Merged via the queue into bevyengine:main with commit 8e441c3 Sep 8, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bevy diagnostics should not spawn multiple diagnostic tasks
5 participants