From e9f8cf7b18609ee539f3bc34f3ff2b7f294fbe8a Mon Sep 17 00:00:00 2001 From: Christian Jordan Date: Tue, 26 Jul 2022 21:10:18 +0200 Subject: [PATCH] fix write_thread_name_fallback and bench addr_validate Signed-off-by: Christian Jordan --- benches/addr_validate.rs | 6 +++--- src/platform/nix_impl/profiler.rs | 4 ++-- src/profiler.rs | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/benches/addr_validate.rs b/benches/addr_validate.rs index 4154f33f..4c4c1b1a 100644 --- a/benches/addr_validate.rs +++ b/benches/addr_validate.rs @@ -1,7 +1,7 @@ // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. use criterion::{criterion_group, criterion_main, Criterion}; -use pprof::validate; +use pprof::addr_validate; fn bench_validate_addr(c: &mut Criterion) { c.bench_function("validate stack addr", |b| { @@ -9,7 +9,7 @@ fn bench_validate_addr(c: &mut Criterion) { b.iter(|| { stack_addrs.iter().for_each(|item| { - validate(item as *const _ as *const libc::c_void); + addr_validate(item as *const _ as *const libc::c_void); }) }) }); @@ -19,7 +19,7 @@ fn bench_validate_addr(c: &mut Criterion) { b.iter(|| { heap_addrs.iter().for_each(|item| { - validate(item as *const _ as *const libc::c_void); + addr_validate(item as *const _ as *const libc::c_void); }) }) }); diff --git a/src/platform/nix_impl/profiler.rs b/src/platform/nix_impl/profiler.rs index c3f4e4b3..0c5df5e4 100644 --- a/src/platform/nix_impl/profiler.rs +++ b/src/platform/nix_impl/profiler.rs @@ -32,7 +32,7 @@ impl ProfilerImpl for Profiler { #[cfg(not(all(any(target_os = "linux", target_os = "macos"), target_env = "gnu")))] fn write_thread_name(current_thread: libc::pthread_t, name: &mut [libc::c_char]) { - crate::profiler::write_thread_name_fallback(current_thread, name); + write_thread_name_fallback(current_thread as usize as u128, name); } #[cfg(all(any(target_os = "linux", target_os = "macos"), target_env = "gnu"))] @@ -41,7 +41,7 @@ fn write_thread_name(current_thread: libc::pthread_t, name: &mut [libc::c_char]) let ret = unsafe { libc::pthread_getname_np(current_thread, name_ptr, MAX_THREAD_NAME) }; if ret != 0 { - write_thread_name_fallback(current_thread, name); + write_thread_name_fallback(current_thread as usize as u128, name); } } diff --git a/src/profiler.rs b/src/profiler.rs index 1ae95698..5669d854 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -21,11 +21,10 @@ use crate::{MAX_DEPTH, MAX_THREAD_NAME}; pub(crate) static PROFILER: Lazy>> = Lazy::new(|| RwLock::new(Profiler::new())); -pub fn write_thread_name_fallback>(thread: T, name: &mut [libc::c_char]) { +pub fn write_thread_name_fallback(thread: u128, name: &mut [libc::c_char]) { let mut len = 0; let mut base = 1; - let thread: u128 = thread.into(); while thread > base && len < MAX_THREAD_NAME { base *= 10; len += 1;