Skip to content

Commit

Permalink
fix write_thread_name_fallback and bench addr_validate
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Jordan <[email protected]>
  • Loading branch information
Jardynq committed Jul 26, 2022
1 parent c855009 commit e9f8cf7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions benches/addr_validate.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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| {
let stack_addrs = [0; 100];

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);
})
})
});
Expand All @@ -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);
})
})
});
Expand Down
4 changes: 2 additions & 2 deletions src/platform/nix_impl/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ use crate::{MAX_DEPTH, MAX_THREAD_NAME};
pub(crate) static PROFILER: Lazy<RwLock<Result<Profiler>>> =
Lazy::new(|| RwLock::new(Profiler::new()));

pub fn write_thread_name_fallback<T: Into<u128>>(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;
Expand Down

0 comments on commit e9f8cf7

Please sign in to comment.