Skip to content

Commit f303a82

Browse files
committed
Fix clippy lints
1 parent cd4de3c commit f303a82

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

quickwit/quickwit-common/src/jemalloc_profiled.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ pub struct JemallocProfile {
4444
pub realloc_size: i64,
4545
}
4646

47-
pub fn start_profiling(min_alloc_size_for_backtrace: usize) -> Result<(), ()> {
47+
#[derive(Debug, thiserror::Error)]
48+
#[error("profiling unavailable")]
49+
pub struct Unavailable;
50+
51+
pub fn start_profiling(min_alloc_size_for_backtrace: usize) -> Result<(), Unavailable> {
4852
warmup_symbol_cache();
4953
configure_min_alloc_size_for_backtrace(min_alloc_size_for_backtrace);
5054
info!(min_alloc_size_for_backtrace, "start heap profiling");
5155
let profiling_previously_enabled = ENABLED.swap(true, Ordering::Acquire);
5256
if profiling_previously_enabled {
5357
info!("heap profiling already running");
54-
return Err(());
58+
return Err(Unavailable);
5559
}
5660
ALLOC_COUNT.store(0, Ordering::SeqCst);
5761
ALLOC_SIZE.store(0, Ordering::SeqCst);
@@ -63,10 +67,10 @@ pub fn start_profiling(min_alloc_size_for_backtrace: usize) -> Result<(), ()> {
6367
Ok(())
6468
}
6569

66-
pub fn stop_profiling() -> Result<JemallocProfile, ()> {
70+
pub fn stop_profiling() -> Result<JemallocProfile, Unavailable> {
6771
let profiling_previously_enabled = ENABLED.swap(false, Ordering::Release);
6872
if !profiling_previously_enabled {
69-
return Err(());
73+
return Err(Unavailable);
7074
}
7175
info!("end heap profiling");
7276
backtrace::clear_symbol_cache();
@@ -89,7 +93,7 @@ fn configure_min_alloc_size_for_backtrace(min_alloc_size_for_backtrace: usize) {
8993
fn warmup_symbol_cache() {
9094
backtrace::trace(|frame| {
9195
backtrace::resolve_frame(frame, |_| {});
92-
return true;
96+
true
9397
});
9498
}
9599

@@ -175,7 +179,7 @@ fn dump_trace(kind: &'static str, alloc_size: usize) {
175179
let mut remaining_frames_to_inspect = 100;
176180
backtrace::trace(|frame| {
177181
if remaining_frames_to_inspect == 0 {
178-
println!("{},{},{}", kind, alloc_size, "<max_frames_reached>");
182+
println!("{},{},<max_frames_reached>", kind, alloc_size);
179183
return false;
180184
} else {
181185
remaining_frames_to_inspect = -1;
@@ -186,7 +190,6 @@ fn dump_trace(kind: &'static str, alloc_size: usize) {
186190
if prefix_helper::is_prefix("quickwit_common::jemalloc_profiled", &symbol_name)
187191
{
188192
profiling_frames_skipped = true;
189-
return;
190193
}
191194
}
192195
});
@@ -246,9 +249,7 @@ mod prefix_helper {
246249
}
247250
let max_idx = (self.matched + new_slice.len()).min(self.prefix.len());
248251
let matched_prefix_slice = &self.prefix[self.matched..max_idx];
249-
if new_slice.len() < matched_prefix_slice.len() {
250-
self.failed = true;
251-
} else if matched_prefix_slice != &new_slice[..matched_prefix_slice.len()] {
252+
if matched_prefix_slice != &new_slice[..matched_prefix_slice.len()] {
252253
self.failed = true;
253254
} else {
254255
self.matched += matched_prefix_slice.len();
@@ -278,6 +279,7 @@ mod prefix_helper {
278279
"hello",
279280
["h", "e", "l", "l", "o", "!"].iter().format("")
280281
));
282+
assert!(!is_prefix("hello", ["h", "i"].iter().format("")));
281283
}
282284
}
283285
}

quickwit/quickwit-serve/src/developer_api/heap_prof.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ pub fn heap_prof_handlers(
3535
.and_then(move |params: ProfilerQueryParams| start_profiler_handler(params))
3636
};
3737

38-
let stop_profiler =
39-
{ warp::path!("heap-prof" / "stop").and_then(move || stop_profiler_handler()) };
38+
let stop_profiler = { warp::path!("heap-prof" / "stop").and_then(stop_profiler_handler) };
4039

4140
async fn start_profiler_handler(
4241
params: ProfilerQueryParams,

0 commit comments

Comments
 (0)