Skip to content

Commit

Permalink
refactor the profile module and add more functions (tikv#11005)
Browse files Browse the repository at this point in the history
* refactor the profile module and add more functions

Signed-off-by: qupeng <[email protected]>

* address comments

Signed-off-by: qupeng <[email protected]>

* address comments

Signed-off-by: qupeng <[email protected]>
  • Loading branch information
hicqu authored Oct 11, 2021
1 parent 677ff9a commit 085ee22
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 302 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ collections = { path = "components/collections" }
coprocessor_plugin_api = { path = "components/coprocessor_plugin_api" }
time = "0.1"
tipb = { git = "https://github.com/pingcap/tipb.git", default-features = false }
tokio = { version = "1.5", features = ["full"] }
tokio = { version = "1.12", features = ["full"] }
tokio-timer = "0.2"
tokio-openssl = "0.6"
toml = "0.5"
Expand Down
3 changes: 1 addition & 2 deletions components/tikv_alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jemalloc = ["tikv-jemallocator", "tikv-jemalloc-ctl", "tikv-jemalloc-sys"]

# Build jemalloc's profiling features. Without this
# certain profile functions will return nothing.
mem-profiling = ["tikv-jemallocator/profiling", "log"]
mem-profiling = ["tikv-jemallocator/profiling"]
snmalloc = ["snmalloc-rs"]

[dependencies]
fxhash = "0.2.1"
libc = "0.2"
log = { version = "0.4", optional = true }
lazy_static = "1.3"

[dev-dependencies]
Expand Down
19 changes: 5 additions & 14 deletions components/tikv_alloc/src/jemalloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ mod profiling {
const PROF_DUMP: &[u8] = b"prof.dump\0";

pub fn activate_prof() -> ProfResult<()> {
info!("start profiler");
unsafe {
if let Err(e) = tikv_jemalloc_ctl::raw::update(PROF_ACTIVE, true) {
error!("failed to activate profiling: {}", e);
return Err(ProfError::JemallocError(format!(
"failed to activate profiling: {}",
e
Expand All @@ -138,10 +136,8 @@ mod profiling {
}

pub fn deactivate_prof() -> ProfResult<()> {
info!("stop profiler");
unsafe {
if let Err(e) = tikv_jemalloc_ctl::raw::update(PROF_ACTIVE, false) {
error!("failed to deactivate profiling: {}", e);
return Err(ProfError::JemallocError(format!(
"failed to deactivate profiling: {}",
e
Expand All @@ -155,20 +151,15 @@ mod profiling {
pub fn dump_prof(path: &str) -> ProfResult<()> {
let mut bytes = CString::new(path)?.into_bytes_with_nul();
let ptr = bytes.as_mut_ptr() as *mut c_char;
let res = unsafe { tikv_jemalloc_ctl::raw::write(PROF_DUMP, ptr) };
match res {
Err(e) => {
error!("failed to dump the profile to {:?}: {}", path, e);
Err(ProfError::JemallocError(format!(
unsafe {
if let Err(e) = tikv_jemalloc_ctl::raw::write(PROF_DUMP, ptr) {
return Err(ProfError::JemallocError(format!(
"failed to dump the profile to {:?}: {}",
path, e
)))
}
Ok(_) => {
info!("dump profile to {}", path);
Ok(())
)));
}
}
Ok(())
}

#[cfg(test)]
Expand Down
4 changes: 0 additions & 4 deletions components/tikv_alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@
//! `--features=mem-profiling` to cargo for eather `tikv_alloc` or
//! `tikv`.
#[cfg(feature = "mem-profiling")]
#[macro_use]
extern crate log;

#[cfg(feature = "jemalloc")]
#[macro_use]
extern crate lazy_static;
Expand Down
3 changes: 1 addition & 2 deletions src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ impl ConfigManager for ServerConfigManager {
fn dispatch(&mut self, c: ConfigChange) -> std::result::Result<(), Box<dyn std::error::Error>> {
{
let change = c.clone();
self.config
.update(move |cfg: &mut Config| cfg.update(change));
self.config.update(move |cfg| cfg.update(change));
if let Err(e) = self.tx.schedule(SnapTask::RefreshConfigEvent) {
error!("server configuration manager schedule refresh snapshot work task failed"; "err"=> ?e);
}
Expand Down
Loading

0 comments on commit 085ee22

Please sign in to comment.