From b771d52128cfb8244b067b19e13c425d7cfe0997 Mon Sep 17 00:00:00 2001 From: YangKeao Date: Thu, 19 Jan 2023 04:41:24 -0500 Subject: [PATCH] update the prost generated file and remove malloc_free (#188) * update prost file Signed-off-by: YangKeao * remove malloc free test Signed-off-by: YangKeao Signed-off-by: YangKeao --- examples/malloc_hook.rs | 109 --------------------------------- proto/perftools.profiles.rs | 8 +++ src/collector.rs | 87 --------------------------- src/profiler.rs | 116 ------------------------------------ 4 files changed, 8 insertions(+), 312 deletions(-) delete mode 100644 examples/malloc_hook.rs diff --git a/examples/malloc_hook.rs b/examples/malloc_hook.rs deleted file mode 100644 index 56bea852..00000000 --- a/examples/malloc_hook.rs +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. - -extern crate libc; - -use std::ffi::c_void; - -#[cfg(not(target_env = "gnu"))] -#[allow(clippy::wrong_self_convention)] -#[allow(non_upper_case_globals)] -static mut __malloc_hook: Option *mut c_void> = None; - -#[cfg(target_arch = "riscv64")] -#[allow(clippy::wrong_self_convention)] -#[allow(non_upper_case_globals)] -static mut __malloc_hook: Option *mut c_void> = None; - -extern "C" { - #[cfg(target_env = "gnu")] - #[cfg(not(target_arch = "riscv64"))] - static mut __malloc_hook: Option *mut c_void>; - - fn malloc(size: usize) -> *mut c_void; -} - -static mut FLAG: bool = false; - -extern "C" fn malloc_hook(size: usize) -> *mut c_void { - unsafe { - FLAG = true; - } - remove_hook(); - - let bt = backtrace::Backtrace::new(); - println!("{:?}", bt); - let p = unsafe { malloc(size) }; - - set_hook(); - - p -} - -fn set_hook() { - unsafe { - __malloc_hook = Some(malloc_hook); - } -} - -fn remove_hook() { - unsafe { - __malloc_hook = None; - } -} - -#[inline(never)] -fn is_prime_number(v: usize, prime_numbers: &[usize]) -> bool { - if v < 10000 { - let r = prime_numbers.binary_search(&v); - return r.is_ok(); - } - - for n in prime_numbers { - if v % n == 0 { - return false; - } - } - - true -} - -#[inline(never)] -fn prepare_prime_numbers() -> Vec { - // bootstrap: Generate a prime table of 0..10000 - let mut prime_number_table: [bool; 10000] = [true; 10000]; - prime_number_table[0] = false; - prime_number_table[1] = false; - for i in 2..10000 { - if prime_number_table[i] { - let mut v = i * 2; - while v < 10000 { - prime_number_table[v] = false; - v += i; - } - } - } - let mut prime_numbers = vec![]; - for (i, exist) in prime_number_table.iter().enumerate().skip(2) { - if *exist { - prime_numbers.push(i); - } - } - prime_numbers -} - -fn main() { - let prime_numbers = prepare_prime_numbers(); - - let _ = pprof::ProfilerGuard::new(100).unwrap(); - - loop { - let mut _v = 0; - - set_hook(); - for i in 2..50000 { - if is_prime_number(i, &prime_numbers) { - _v += 1; - } - } - } -} diff --git a/proto/perftools.profiles.rs b/proto/perftools.profiles.rs index 3d3e432e..22453330 100644 --- a/proto/perftools.profiles.rs +++ b/proto/perftools.profiles.rs @@ -1,5 +1,6 @@ // f9f855b960d01b292a3c2642e263e6156d52631e78e0177fe51416ed5bbecc81 proto/profile.proto +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Profile { /// A description of the samples associated with each Sample.value. @@ -65,6 +66,7 @@ pub struct Profile { pub default_sample_type: i64, } /// ValueType describes the semantics and measurement units of a value. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct ValueType { /// Rename it from type to ty to avoid using keyword in Rust. @@ -80,6 +82,7 @@ pub struct ValueType { /// context. The program context is typically a stack trace, perhaps /// augmented with auxiliary information like the thread-id, some /// indicator of a higher level request being handled etc. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Sample { /// The ids recorded here correspond to a Profile.location.id. @@ -99,6 +102,7 @@ pub struct Sample { #[prost(message, repeated, tag = "3")] pub label: ::prost::alloc::vec::Vec