Skip to content

Commit ca5d1ba

Browse files
committed
feat(profiling): emit an otel protobuf
1 parent 0d7bdf3 commit ca5d1ba

File tree

5 files changed

+351
-15
lines changed

5 files changed

+351
-15
lines changed

libdd-profiling/src/internal/location.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ pub struct Location {
1616
pub line: i64,
1717
}
1818

19+
impl Default for Location {
20+
fn default() -> Self {
21+
Self {
22+
mapping_id: None,
23+
function_id: super::FunctionId::from_offset(0),
24+
address: 0,
25+
line: 0,
26+
}
27+
}
28+
}
29+
1930
impl Item for Location {
2031
type Id = LocationId;
2132
}

libdd-profiling/src/internal/mapping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::*;
66
/// Represents a [pprof::Mapping] with some space-saving changes:
77
/// - The id is not stored on the struct. It's stored in the container that holds the struct.
88
/// - ids for linked objects use 32-bit numbers instead of 64 bit ones.
9-
#[derive(Eq, PartialEq, Hash)]
9+
#[derive(Default, Eq, PartialEq, Hash)]
1010
pub struct Mapping {
1111
/// Address at which the binary (or DLL) is loaded into memory.
1212
pub memory_start: u64,

libdd-profiling/src/internal/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ mod function;
77
mod label;
88
mod location;
99
mod mapping;
10+
#[cfg(not(feature = "otel"))]
1011
mod observation;
12+
#[cfg(feature = "otel")]
1113
mod otel_style_observation;
1214
mod profile;
1315
mod sample;
@@ -22,6 +24,9 @@ pub use label::*;
2224
pub use libdd_profiling_protobuf::ValueType;
2325
pub use location::*;
2426
pub use mapping::*;
27+
#[cfg(not(feature = "otel"))]
28+
pub use observation::*;
29+
#[cfg(feature = "otel")]
2530
pub use otel_style_observation::*;
2631
pub use profile::*;
2732
pub use sample::*;

libdd-profiling/src/internal/otel_style_observation.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use std::collections::{HashMap, HashSet};
1010
#[derive(Default)]
1111
pub struct Observations {
1212
sample_types: Box<[SampleType]>,
13-
aggregated: HashMap<SampleType, HashMap<Sample, i64>>,
14-
timestamped: HashMap<SampleType, HashMap<Sample, Vec<(i64, Timestamp)>>>,
13+
pub aggregated: HashMap<SampleType, HashMap<Sample, i64>>,
14+
pub timestamped: HashMap<SampleType, HashMap<Sample, Vec<(i64, Timestamp)>>>,
1515
}
1616

1717
impl Observations {
@@ -64,15 +64,15 @@ impl Observations {
6464
let samples: HashSet<&Sample> = self
6565
.aggregated
6666
.iter()
67-
.flat_map(|(_, samples)| samples.iter().map(|(s, _)| s))
67+
.flat_map(|(_, samples)| samples.keys())
6868
.collect();
6969
samples.len()
7070
}
7171

7272
pub fn timestamped_samples_count(&self) -> usize {
7373
self.timestamped
7474
.iter()
75-
.flat_map(|(_, v)| v.iter().map(|(_, v)| v.len()))
75+
.flat_map(|(_, v)| v.values().map(|v| v.len()))
7676
.sum()
7777
}
7878

@@ -82,6 +82,8 @@ impl Observations {
8282
Ok(self.into_iter())
8383
}
8484

85+
// TODO make this a trait impl
86+
#[allow(clippy::should_implement_trait)]
8587
pub fn into_iter(self) -> impl Iterator<Item = (Sample, Option<Timestamp>, Vec<i64>)> {
8688
let index_map: HashMap<SampleType, usize> = self
8789
.sample_types

0 commit comments

Comments
 (0)