Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - add get_history function to Diagnostic #2772

Closed
wants to merge 3 commits into from
Closed

[Merged by Bors] - add get_history function to Diagnostic #2772

wants to merge 3 commits into from

Conversation

wendivoid
Copy link
Contributor

Objective

Solution

  • Add Diagnostic::get_history function.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Sep 4, 2021
@@ -119,6 +119,10 @@ impl Diagnostic {
pub fn get_max_history_length(&self) -> usize {
self.max_history_length
}

pub fn get_history(&self) -> Vec<f64> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub fn get_history(&self) -> Vec<f64> {
pub fn history(&self) -> Vec<f64> {

Elsewhere in the code base we tend to prefer this naming convention.

@alice-i-cecile
Copy link
Member

Two quick questions about the return type:

  1. Why do we want to collect this into a vec, rather rather returning an iterator?
  2. Are we okay to discard the temporal data here? I suspect it's going to be essential for more complex use cases.

I think that two separate methods make sense here; one for just the values, called .values, and a second one with the temporal data called .history that just returns the history field.

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Sep 4, 2021
@wendivoid
Copy link
Contributor Author

Although i haven't had a use for it yet, I think your completely right. Just to be clear you are talking about two functions signatures like this right?

pub fn values(&self) -> impl Iterator<Item=&f64>;
pub fn history(&self) -> impl Iterator<Item=&DiagnosticMeasurement>

@cart
Copy link
Member

cart commented Sep 4, 2021

Yup I agree that we should be using iterators here instead of allocating. values and history are both "history", one just includes more information. I think these names might be a bit less ambiguous:

pub fn values(&self) -> impl Iterator<Item=&f64>;
pub fn measurements(&self) -> impl Iterator<Item=&DiagnosticMeasurement>

Using "measurements" also has the benefit of having parity with add_measurement. However they are both still "measurements". Maybe instead we should just expose a single pub fn measurements(&self) -> impl Iterator<Item=&DiagnosticMeasurement> and let users access the values via the iterator.

@alice-i-cecile
Copy link
Member

Just to be clear you are talking about two functions signatures like this right?

Correct :) I also prefer Cart's measurements naming suggestion. I could go either way on the one vs two methods. I think one method gets a slight preference for me because I like the type-safety of &DiagnosticMeasurement and it's trivial to extract the underlying data if that's all you want.

@alice-i-cecile alice-i-cecile added the A-Diagnostics Logging, crash handling, error reporting and performance analysis label Sep 4, 2021
@wendivoid
Copy link
Contributor Author

Sorry for taking a while to respond, I agree with all the points made and have made the changes. I believe this should be ready for a final look then

@cart
Copy link
Member

cart commented Sep 6, 2021

bors r+

bors bot pushed a commit that referenced this pull request Sep 6, 2021
# Objective

- Allow access to diagnostic history value.
- Fixes #2771.

## Solution

- Add Diagnostic::get_history function.
@cart
Copy link
Member

cart commented Sep 6, 2021

Haha just realized this will fail. @ByteBuddha can you run cargo fmt --all and commit the changes?

@bors
Copy link
Contributor

bors bot commented Sep 6, 2021

Build failed:

@cart
Copy link
Member

cart commented Sep 6, 2021

bors r+

bors bot pushed a commit that referenced this pull request Sep 6, 2021
# Objective

- Allow access to diagnostic history value.
- Fixes #2771.

## Solution

- Add Diagnostic::get_history function.
@bors bors bot changed the title add get_history function to Diagnostic [Merged by Bors] - add get_history function to Diagnostic Sep 6, 2021
@bors bors bot closed this Sep 6, 2021
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-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access Diagnostic::history field
3 participants