From 9b07e799c8afcd6a76741a1aa8944306c3ad1bbb Mon Sep 17 00:00:00 2001 From: YangKeao Date: Tue, 29 Jun 2021 19:53:40 +0800 Subject: [PATCH 1/4] add phantom data for criterion output Signed-off-by: YangKeao --- src/criterion.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/criterion.rs b/src/criterion.rs index f7f3dfdb..a791b231 100644 --- a/src/criterion.rs +++ b/src/criterion.rs @@ -13,6 +13,7 @@ use std::fs::File; use std::io::Write; use std::os::raw::c_int; use std::path::Path; +use std::marker::PhantomData; pub enum Output<'a> { #[cfg(feature = "flamegraph")] @@ -20,6 +21,9 @@ pub enum Output<'a> { #[cfg(feature = "protobuf")] Protobuf, + + #[deprecated(note = "This branch is used to include lifetime parameter. Don't use it directly.")] + _Phantom(PhantomData<&'a ()>), } pub struct PProfProfiler<'a, 'b> { @@ -38,6 +42,9 @@ impl<'a, 'b> PProfProfiler<'a, 'b> { } } +#[cfg(not(any(feature = "protobuf", feature = "flamegraph")))] +compile_error!("Either feature \"protobuf\" or \"flamegraph\" must be enabled when \"criterion\" feature is enabled."); + impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { fn start_profiling(&mut self, _benchmark_id: &str, _benchmark_dir: &Path) { self.active_profiler = Some(ProfilerGuard::new(self.frequency).unwrap()); @@ -51,6 +58,10 @@ impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { Output::Flamegraph(_) => "flamegraph.svg", #[cfg(feature = "protobuf")] Output::Protobuf => "profile.pb", + // This is `""` but not `unreachable!()`, because `unreachable!()` + // will result in another compile error, so that the user may not + // realize the error thrown by `compile_error!()` at the first time. + _ => { "" }, }; let output_path = benchmark_dir.join(filename); let output_file = File::create(&output_path).unwrap_or_else(|_| { @@ -87,6 +98,8 @@ impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { .write_all(&content) .expect("Error while writing protobuf"); } + + _ => unreachable!() } } } From 1ec0039787d74950f0afa24a5e5d965c4eb61adb Mon Sep 17 00:00:00 2001 From: YangKeao Date: Wed, 30 Jun 2021 11:42:06 +0800 Subject: [PATCH 2/4] format the codes Signed-off-by: YangKeao --- src/criterion.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/criterion.rs b/src/criterion.rs index a791b231..97ac85af 100644 --- a/src/criterion.rs +++ b/src/criterion.rs @@ -11,9 +11,9 @@ use criterion::profiler::Profiler; use std::fs::File; #[cfg(feature = "protobuf")] use std::io::Write; +use std::marker::PhantomData; use std::os::raw::c_int; use std::path::Path; -use std::marker::PhantomData; pub enum Output<'a> { #[cfg(feature = "flamegraph")] @@ -22,7 +22,9 @@ pub enum Output<'a> { #[cfg(feature = "protobuf")] Protobuf, - #[deprecated(note = "This branch is used to include lifetime parameter. Don't use it directly.")] + #[deprecated( + note = "This branch is used to include lifetime parameter. Don't use it directly." + )] _Phantom(PhantomData<&'a ()>), } @@ -61,7 +63,7 @@ impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { // This is `""` but not `unreachable!()`, because `unreachable!()` // will result in another compile error, so that the user may not // realize the error thrown by `compile_error!()` at the first time. - _ => { "" }, + _ => "", }; let output_path = benchmark_dir.join(filename); let output_file = File::create(&output_path).unwrap_or_else(|_| { @@ -99,7 +101,7 @@ impl<'a, 'b> Profiler for PProfProfiler<'a, 'b> { .expect("Error while writing protobuf"); } - _ => unreachable!() + _ => unreachable!(), } } } From d66b8d22a063b92b04dd283bc73979b3a1308a38 Mon Sep 17 00:00:00 2001 From: YangKeao Date: Sun, 4 Jul 2021 03:03:51 +0800 Subject: [PATCH 3/4] allow uninit_assumed_init Signed-off-by: YangKeao --- src/collector.rs | 1 + src/frames.rs | 1 + src/lib.rs | 1 + src/profiler.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/src/collector.rs b/src/collector.rs index 5652278b..f6ffac12 100644 --- a/src/collector.rs +++ b/src/collector.rs @@ -1,5 +1,6 @@ // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. + use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; use std::io::{Read, Seek, SeekFrom, Write}; diff --git a/src/frames.rs b/src/frames.rs index 06f4d0b8..087f2c5e 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -40,6 +40,7 @@ impl Debug for UnresolvedFrames { } impl UnresolvedFrames { + #[allow(clippy::uninit_assumed_init)] pub fn new(bt: &[Frame], tn: &[u8], thread_id: u64) -> Self { let depth = bt.len(); let mut frames: [Frame; MAX_DEPTH] = diff --git a/src/lib.rs b/src/lib.rs index 3c298afc..32da691a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ pub const MAX_DEPTH: usize = 32; /// Define the MAX supported thread name length. TODO: make this variable mutable. pub const MAX_THREAD_NAME: usize = 16; +#[allow(clippy::uninit_assumed_init)] mod collector; mod error; mod frames; diff --git a/src/profiler.rs b/src/profiler.rs index ae09b6ef..3d547a8b 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -117,6 +117,7 @@ fn write_thread_name(current_thread: libc::pthread_t, name: &mut [libc::c_char]) } #[no_mangle] +#[allow(clippy::uninit_assumed_init)] extern "C" fn perf_signal_handler(_signal: c_int) { if let Some(mut guard) = PROFILER.try_write() { if let Ok(profiler) = guard.as_mut() { From 6236da8348b044cf0faf3c65e10d5a15d4331af8 Mon Sep 17 00:00:00 2001 From: YangKeao Date: Sun, 4 Jul 2021 03:07:00 +0800 Subject: [PATCH 4/4] format codes Signed-off-by: YangKeao --- src/collector.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/collector.rs b/src/collector.rs index f6ffac12..5652278b 100644 --- a/src/collector.rs +++ b/src/collector.rs @@ -1,6 +1,5 @@ // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. - use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; use std::io::{Read, Seek, SeekFrom, Write};