Skip to content

Commit 9f341b2

Browse files
committed
style: fix clippy warnings
1 parent 6bec6bd commit 9f341b2

File tree

4 files changed

+43
-34
lines changed

4 files changed

+43
-34
lines changed

datadog-profiling-ffi/src/profile_handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct EmptyHandleError;
5858
/// # Safety
5959
///
6060
/// Uses c-str literal to ensure valid UTF-8 and null termination.
61-
unsafe impl ddcommon::error::FfiSafeErrorMessage for EmptyHandleError {
61+
unsafe impl FfiSafeErrorMessage for EmptyHandleError {
6262
fn as_ffi_str(&self) -> &'static CStr {
6363
c"handle used with an interior null pointer"
6464
}

datadog-profiling-ffi/src/profiles/pprof_builder/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub unsafe extern "C" fn ddog_prof_PprofBuilder_new(
5757
/// references to that builder may be active for the duration of the call.
5858
/// - `profile` must be non-null and point to a valid `Profile` that
5959
/// remains alive until the pprof builder is done.
60+
///
6061
/// TODO: finish safety
6162
#[must_use]
6263
#[no_mangle]
@@ -69,7 +70,7 @@ pub unsafe extern "C" fn ddog_prof_PprofBuilder_add_profile(
6970
let builder = unsafe {
7071
handle
7172
.as_inner_mut()
72-
.map_err(|e| ProfileStatus::from_ffi_safe_error_message(e))?
73+
.map_err(ProfileStatus::from_ffi_safe_error_message)?
7374
};
7475
let prof_ref = unsafe { &*profile };
7576
builder
@@ -90,6 +91,7 @@ pub unsafe extern "C" fn ddog_prof_PprofBuilder_add_profile(
9091
/// references to that builder may be active for the duration of the call.
9192
/// - `profile` must be non-null and point to a valid `Profile` that
9293
/// remains alive until the pprof builder is done.
94+
///
9395
/// TODO: finish safety
9496
#[must_use]
9597
#[no_mangle]
@@ -103,7 +105,7 @@ pub unsafe extern "C" fn ddog_prof_PprofBuilder_add_profile_with_poisson_upscali
103105
let builder = unsafe {
104106
handle
105107
.as_inner_mut()
106-
.map_err(|e| ProfileStatus::from_ffi_safe_error_message(e))?
108+
.map_err(ProfileStatus::from_ffi_safe_error_message)?
107109
};
108110
let prof_ref = unsafe { &*profile };
109111

@@ -128,6 +130,7 @@ pub unsafe extern "C" fn ddog_prof_PprofBuilder_add_profile_with_poisson_upscali
128130
/// references to that builder may be active for the duration of the call.
129131
/// - `profile` must be non-null and point to a valid `Profile` that
130132
/// remains alive until the pprof builder is done.
133+
///
131134
/// TODO: finish safety
132135
#[must_use]
133136
#[no_mangle]

datadog-profiling/src/profiles/pprof_builder/mod.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,19 @@ pub struct PprofBuilder<'a> {
104104
state: PprofBuilderState<'a>,
105105
}
106106

107+
struct ProfileWithUpscaling<'a> {
108+
profile: &'a Profile,
109+
upscalings: Vec<UpscalingRule>,
110+
}
111+
107112
enum PprofBuilderState<'a> {
108113
Initialized,
109114
Configured {
110115
options: PprofOptions,
111116
},
112117
AddingProfiles {
113118
options: PprofOptions,
114-
profiles: Vec<(&'a Profile, Vec<UpscalingRule>)>,
119+
profiles: Vec<ProfileWithUpscaling<'a>>,
115120
string_table: StringTable<'a>,
116121
},
117122
}
@@ -222,9 +227,11 @@ impl<'a> PprofBuilder<'a> {
222227
};
223228
new_rules.push(UpscalingRule::ProportionalUpscalingRule(rule));
224229
}
225-
226230
profiles
227-
.try_push((profile, new_rules))
231+
.try_push(ProfileWithUpscaling {
232+
profile,
233+
upscalings: new_rules,
234+
})
228235
.map_err(|_| TryAddProfileError::OutOfMemoryProportionalUpscaling)
229236
}
230237

@@ -239,34 +246,34 @@ impl<'a> PprofBuilder<'a> {
239246
return Err(TryAddProfileError::WrongSampleTypeCountForPoisson);
240247
}
241248

242-
let mut new_rules = Vec::new();
243-
new_rules
249+
let mut upscaling_rules = Vec::new();
250+
upscaling_rules
244251
.try_reserve_exact(1)
245252
.map_err(|_| TryAddProfileError::OutOfMemoryPoissonUpscaling)?;
246-
new_rules.push(UpscalingRule::PoissonUpscalingRule(upscaling_rule));
253+
upscaling_rules.push(UpscalingRule::PoissonUpscalingRule(upscaling_rule));
247254

248255
profiles
249-
.try_push((profile, new_rules))
256+
.try_push(ProfileWithUpscaling {
257+
profile,
258+
upscalings: upscaling_rules,
259+
})
250260
.map_err(|_| TryAddProfileError::OutOfMemoryPoissonUpscaling)
251261
}
252262

253263
pub fn try_add_profile(&mut self, profile: &'a Profile) -> Result<(), TryAddProfileError> {
254264
let (profiles, _) = self.transition_to_adding_profiles()?;
255-
256265
profiles
257-
.try_push((profile, Vec::new()))
266+
.try_push(ProfileWithUpscaling {
267+
profile,
268+
upscalings: Vec::new(),
269+
})
258270
.map_err(|_| TryAddProfileError::OutOfMemoryWithoutUpscaling)
259271
}
260272

261273
fn transition_to_adding_profiles(
262274
&mut self,
263-
) -> Result<
264-
(
265-
&mut Vec<(&'a Profile, Vec<UpscalingRule>)>,
266-
&mut StringTable<'a>,
267-
),
268-
TryAddProfileError,
269-
> {
275+
) -> Result<(&mut Vec<ProfileWithUpscaling<'a>>, &mut StringTable<'a>), TryAddProfileError>
276+
{
270277
if matches!(self.state, Initialized) {
271278
let options = PprofOptions::default();
272279
self.state = Configured { options };
@@ -324,14 +331,17 @@ impl<'a> PprofBuilder<'a> {
324331
let dict_strings = dict.strings();
325332

326333
// --- unify sample types across profiles and emit ---
327-
let n_sample_types = profiles.iter().map(|(p, _)| p.sample_type.len()).sum();
334+
let n_sample_types = profiles
335+
.iter()
336+
.map(|pwu| pwu.profile.sample_type.len())
337+
.sum();
328338
let n_profiles = profiles.len();
329339

330340
let mut remaps: Vec<ArrayVec<usize, MAX_SAMPLE_TYPES>> = Vec::new();
331341
{
332342
let mut remapper = Remapper::new(dict_strings, &mut string_table, n_sample_types)?;
333343
remaps.try_reserve_exact(n_profiles)?;
334-
for profile in profiles.iter().map(|(p, _)| p) {
344+
for profile in profiles.iter().map(|pwu| pwu.profile) {
335345
let mut offsets = ArrayVec::new();
336346
for sample_type in profile.sample_type.iter() {
337347
if offsets
@@ -378,9 +388,9 @@ impl<'a> PprofBuilder<'a> {
378388
let mut values_buf: Vec<i64> = Vec::new();
379389
let mut labels_buf: Vec<pprof::Record<pprof::Label, 3, { pprof::NO_OPT_ZERO }>> =
380390
Vec::new();
381-
for (i, (prof, upscaling_rules)) in profiles.iter().enumerate() {
391+
for (i, pwu) in profiles.iter().enumerate() {
382392
let remap = &remaps[i];
383-
for sample in &prof.samples {
393+
for sample in &pwu.profile.samples {
384394
// location ids from stack
385395
let stack = sample.stack_id.as_slice();
386396
let mut locs_out: Vec<u64> = Vec::with_capacity(stack.len());
@@ -496,7 +506,7 @@ impl<'a> PprofBuilder<'a> {
496506
}
497507

498508
// Apply upscaling
499-
for rule in upscaling_rules {
509+
for rule in &pwu.upscalings {
500510
rule.scale(&mut values_buf, &labels_buf);
501511
}
502512

datadog-profiling/src/profiles/pprof_builder/upscaling.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@ impl ProportionalUpscalingRule {
4040
if group_by_label.key.is_zero() && group_by_label.value.is_zero() {
4141
scale_values(values, scale);
4242
} else {
43-
let matched = labels
44-
.iter()
45-
.find(|label| {
46-
let label = &label.value;
47-
label.key.value == group_by_label.key
48-
&& label.str.value == group_by_label.value
49-
})
50-
.is_some();
43+
let matched = labels.iter().any(|label| {
44+
let label = &label.value;
45+
label.key.value == group_by_label.key && label.str.value == group_by_label.value
46+
});
5147
if matched {
5248
scale_values(values, scale);
5349
}
@@ -65,8 +61,8 @@ pub struct PoissonUpscalingRule {
6561

6662
impl PoissonUpscalingRule {
6763
pub fn compute_scale(&self, values: &[i64]) -> f64 {
68-
let sum_offset = self.sum_offset as usize;
69-
let count_offset = self.count_offset as usize;
64+
let sum_offset = self.sum_offset;
65+
let count_offset = self.count_offset;
7066
let sum = values[sum_offset];
7167
let count = values[count_offset];
7268
let sampling_distance = self.sampling_distance.get() as f64;

0 commit comments

Comments
 (0)