Skip to content

Commit 0c14cf0

Browse files
authored
feat: Add more stats (#4)
1 parent be74365 commit 0c14cf0

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/data.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ use time::OffsetDateTime;
1414
use crate::cli::{Config, MAX_PROJECTS};
1515
use crate::types::{SpanId, TraceId};
1616

17+
#[derive(Clone, Debug, Default)]
18+
pub struct Stats {
19+
pub spans: usize,
20+
pub segments: usize,
21+
pub traces: usize,
22+
}
23+
1724
pub struct RandomGenerator<'a> {
1825
config: &'a Config,
1926
rng: ThreadRng,
2027
segment_dist: Normal<f64>,
2128
span_dist: Normal<f64>,
2229
#[allow(dead_code, reason = "TODO: support custom receive time")]
2330
batch_delay_dist: Normal<f64>,
31+
stats: Stats,
2432
}
2533

2634
impl<'a> RandomGenerator<'a> {
@@ -49,9 +57,14 @@ impl<'a> RandomGenerator<'a> {
4957
segment_dist,
5058
span_dist,
5159
batch_delay_dist,
60+
stats: Stats::default(),
5261
}
5362
}
5463

64+
pub fn stats(&self) -> &Stats {
65+
&self.stats
66+
}
67+
5568
pub fn rng(&mut self) -> &mut ThreadRng {
5669
&mut self.rng
5770
}
@@ -73,10 +86,12 @@ impl<'a> RandomGenerator<'a> {
7386
}
7487

7588
pub fn trace(&mut self) -> TraceInfo {
89+
self.stats.traces += 1;
7690
TraceInfo::new(self.organization_id())
7791
}
7892

7993
pub fn segment<'b>(&mut self, trace: &'b TraceInfo) -> SegmentInfo<'b> {
94+
self.stats.segments += 1;
8095
SegmentInfo::new(trace, self.project_id(trace.organization_id))
8196
}
8297

@@ -115,6 +130,8 @@ impl<'a> RandomGenerator<'a> {
115130
}
116131

117132
pub fn span<'b>(&mut self, segment: &'b SegmentInfo<'b>, span_ref: SpanRef) -> Span {
133+
self.stats.spans += 1;
134+
118135
let now = OffsetDateTime::now_utc();
119136
let lower = now - Duration::from_secs(60 * 60);
120137

src/main.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,28 @@ mod types;
1515

1616
struct StdoutProducer {
1717
stdout: StdoutLock<'static>,
18-
count: usize,
1918
}
2019

2120
impl StdoutProducer {
2221
pub fn new() -> Self {
2322
Self {
2423
stdout: std::io::stdout().lock(),
25-
count: 0,
2624
}
2725
}
2826

2927
pub fn produce_json<T: Serialize>(&mut self, value: &T) -> Result<()> {
3028
serde_json::to_writer(&mut self.stdout, value)?;
3129
writeln!(&mut self.stdout)?;
32-
33-
self.count += 1;
3430
Ok(())
3531
}
36-
37-
pub fn count(&self) -> usize {
38-
self.count
39-
}
4032
}
4133

4234
fn produce(config: &Config) -> Result<()> {
4335
let start = Instant::now();
4436
let mut generator = RandomGenerator::new(config);
4537
let mut producer = StdoutProducer::new();
4638

47-
while producer.count() < config.count {
39+
while generator.stats().spans < config.count {
4840
let trace = generator.trace();
4941
let mut remote_parent = None;
5042

@@ -69,11 +61,11 @@ fn produce(config: &Config) -> Result<()> {
6961
}
7062
}
7163

72-
log::info!(
73-
"Produced {} spans in {:?}",
74-
producer.count(),
75-
start.elapsed()
76-
);
64+
let stats = generator.stats();
65+
log::info!("Finished in {:?}", start.elapsed());
66+
log::info!(" traces: {}", stats.traces);
67+
log::info!(" segments: {}", stats.segments);
68+
log::info!(" spans: {}", stats.spans);
7769

7870
Ok(())
7971
}

0 commit comments

Comments
 (0)