Skip to content

Commit

Permalink
add debug
Browse files Browse the repository at this point in the history
Signed-off-by: CalvinNeo <[email protected]>
  • Loading branch information
CalvinNeo committed Jul 22, 2024
1 parent 274da2f commit 22ff6ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 5 additions & 5 deletions proxy_components/proxy_ffi/src/jemalloc_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn issue_mallctl_args(
oldsize: *mut u64,
newptr: *mut ::std::os::raw::c_void,
newsize: u64,
) {
) -> ::std::os::raw::c_int {
unsafe {
let c_str = std::ffi::CString::new(command).unwrap();
let c_ptr: *const ::std::os::raw::c_char = c_str.as_ptr() as *const ::std::os::raw::c_char;
Expand All @@ -42,13 +42,13 @@ pub fn issue_mallctl_args(
{
// See NO_UNPREFIXED_MALLOC
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "macos"))]
_rjem_mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
return _rjem_mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
#[cfg(not(any(
target_os = "android",
target_os = "dragonfly",
target_os = "macos"
)))]
mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
return mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
}
}

Expand All @@ -57,12 +57,12 @@ pub fn issue_mallctl_args(
#[cfg(feature = "external-jemalloc")]
{
// Must linked to tiflash.
let _ = mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
return mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
}
#[cfg(not(feature = "external-jemalloc"))]
{
// Happens only with `raftstore-proxy-main`
let _ = mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
return mallctl(c_ptr, oldptr, oldsize, newptr, newsize);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,34 @@ pub fn deactivate_prof() -> ProfResult<()> {
Ok(())
}

extern crate libc;

pub fn dump_prof(path: &str) -> tikv_alloc::error::ProfResult<()> {
{
let mut bytes = std::ffi::CString::new(path)?.into_bytes_with_nul();
let mut ptr = bytes.as_mut_ptr() as *mut ::std::os::raw::c_char;
let len = std::mem::size_of_val(&ptr) as u64;
issue_mallctl_args(
let r = issue_mallctl_args(
"prof.dump",
std::ptr::null_mut(),
std::ptr::null_mut(),
&mut ptr as *mut _ as *mut _,
len,
);
if r != 0 {
unsafe {
let err = *libc::__errno_location();
let err_msg = libc::strerror(err);
let c_str = std::ffi::CStr::from_ptr(err_msg);
let str_slice = c_str.to_str().unwrap_or("Unknown error");
tikv_util::warn!(
"dump_prof returns non-zero {} error_code: {} error_message: {}",
r,
err,
str_slice
);
}
}
}
Ok(())
}
Expand Down

0 comments on commit 22ff6ed

Please sign in to comment.