mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
fix crashes with small log counts
This commit is contained in:
parent
046c65a774
commit
1af348c35b
1 changed files with 7 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use hdrhistogram::Histogram;
|
use hdrhistogram::Histogram;
|
||||||
|
use std::cmp::max;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
pub struct TimeGraph {
|
pub struct TimeGraph {
|
||||||
|
|
@ -11,10 +12,13 @@ impl TimeGraph {
|
||||||
pub fn new(start: OffsetDateTime, end: OffsetDateTime) -> Self {
|
pub fn new(start: OffsetDateTime, end: OffsetDateTime) -> Self {
|
||||||
let histogram = Histogram::new_with_bounds(
|
let histogram = Histogram::new_with_bounds(
|
||||||
1,
|
1,
|
||||||
|
max(
|
||||||
end.unix_timestamp() as u64 - start.unix_timestamp() as u64 + 1,
|
end.unix_timestamp() as u64 - start.unix_timestamp() as u64 + 1,
|
||||||
|
4,
|
||||||
|
),
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.expect("Failed to build histogram");
|
||||||
TimeGraph {
|
TimeGraph {
|
||||||
histogram,
|
histogram,
|
||||||
start: start.unix_timestamp() as u64,
|
start: start.unix_timestamp() as u64,
|
||||||
|
|
@ -32,7 +36,7 @@ impl TimeGraph {
|
||||||
let step = (self.end - self.start + 1) / buckets as u64;
|
let step = (self.end - self.start + 1) / buckets as u64;
|
||||||
|
|
||||||
self.histogram
|
self.histogram
|
||||||
.iter_linear(step)
|
.iter_linear(max(1, step))
|
||||||
.map(|val| val.count_since_last_iteration())
|
.map(|val| val.count_since_last_iteration())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue