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

iter_recorded() method fails to iterate if all the values are zero. #92

Open
minghanc opened this issue Aug 4, 2020 · 3 comments
Open

Comments

@minghanc
Copy link

minghanc commented Aug 4, 2020

iter_recorded() won't work when all the values recorded by the Histogram instance is 0.
Sample code to hit the issue:

let mut tracker = Histogram::<u64>::new(3).unwrap();
tracker += 0;
tracker += 0;
tracker += 0;

 // print 3 as expected.
 println!("{}", tracker.len());

 let mut res = String::new();
 for v in tracker.iter_recorded() {
     res.push_str(format!("value {} and count {}", v.value_iterated_to(), v.count_at_value()).as_str());
 }

 // nothing is printed. Expected: value 0 and count 3
 println!("{}", res);

We use the iterator to print out a certain format and emit to our log file. Is there a better way to do that for the logging purpose?

@marshallpierce
Copy link
Collaborator

It's been a while since I was in the guts of the data structure, but IIRC the hdrhistogram structure squashes everything below the lowest trackable number into the 0th internal slot which is then ignored because it doesn't obey the same scaling rules as all the other slots. The lowest trackable number is at least 1, so 0 would fall into the void, in the same way that if you configured a histogram with the lowest trackable number of 10000 then 44 would also get lost.

If you do need to record zeroes for your use case, a slightly unpleasant workaround would be to simply add 1 to everything at record time, then subtract it off at iteration time.

@minghanc
Copy link
Author

minghanc commented Aug 4, 2020

Ok. But if I continue to record another value, for example 1, to the above tracker, then it will be able to print out the result correctly. (value 0 and count 3 value 1 and count 1), Could you clarify that? Since as you said, 1 is below the lowest trackable number. I just want to make sure there would be no other corner cases for the iterator.

@marshallpierce
Copy link
Collaborator

Hm, that does seem unexpected. Will have to look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants