Skip to content

Commit

Permalink
Unify thread name, and combine all threads in the same thread pool in…
Browse files Browse the repository at this point in the history
… framegraph produced by cpu_profiler. (#9721)
  • Loading branch information
grao1991 authored Aug 23, 2023
1 parent 0af47b4 commit 7d4fb98
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 33 deletions.
78 changes: 53 additions & 25 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ heck = "0.3.2"
hex = "0.4.3"
hkdf = "0.10.0"
hostname = "0.3.1"
httpmock = "0.6"
httpmock = "0.6.8"
hyper = { version = "0.14.18", features = ["full"] }
hyper-tls = "0.5.0"
image = "0.24.5"
Expand Down Expand Up @@ -566,7 +566,7 @@ random_word = "0.3.0"
rayon = "1.5.2"
redis = { version = "0.22.3", features = ["tokio-comp", "script", "connection-manager"] }
redis-test = { version = "0.1.1", features = ["aio"] }
regex = "1.5.5"
regex = "1.9.3"
reqwest = { version = "0.11.11", features = [
"blocking",
"cookies",
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub static RAYON_EXEC_POOL: Lazy<Arc<rayon::ThreadPool>> = Lazy::new(|| {
Arc::new(
rayon::ThreadPoolBuilder::new()
.num_threads(num_cpus::get())
.thread_name(|index| format!("par_exec_{}", index))
.thread_name(|index| format!("par_exec-{}", index))
.build()
.unwrap(),
)
Expand Down
1 change: 1 addition & 0 deletions crates/aptos-profiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust-version = { workspace = true }

[dependencies]
anyhow = { workspace = true }
regex = { workspace = true }

[target.'cfg(unix)'.dependencies]
pprof = { version = "0.11", features = ["flamegraph"] }
Expand Down
17 changes: 16 additions & 1 deletion crates/aptos-profiler/src/cpu_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};
use anyhow::Result;
use pprof::ProfilerGuard;
use regex::Regex;
use std::{path::PathBuf, thread, time};

pub struct CpuProfiler<'a> {
Expand All @@ -33,6 +34,16 @@ impl<'a> CpuProfiler<'a> {
self.guard = None;
Ok(())
}

fn frames_post_processor() -> impl Fn(&mut pprof::Frames) {
let regex = Regex::new(r"^(.*)-(\d*)$").unwrap();

move |frames| {
if let Some((_, [name, _])) = regex.captures(&frames.thread_name).map(|c| c.extract()) {
frames.thread_name = name.to_string();
}
}
}
}

impl Profiler for CpuProfiler<'_> {
Expand All @@ -59,7 +70,11 @@ impl Profiler for CpuProfiler<'_> {
/// End profiling
fn end_profiling(&mut self, _binary_path: &str) -> Result<()> {
if let Some(guard) = self.guard.take() {
if let Ok(report) = guard.report().build() {
if let Ok(report) = guard
.report()
.frames_post_processor(Self::frames_post_processor())
.build()
{
let file = create_file_with_parents(self.svg_result_path.as_path())?;
let _result = report.flamegraph(file);
}
Expand Down
2 changes: 1 addition & 1 deletion storage/aptosdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub(crate) const NUM_STATE_SHARDS: usize = 16;
static COMMIT_POOL: Lazy<rayon::ThreadPool> = Lazy::new(|| {
rayon::ThreadPoolBuilder::new()
.num_threads(32)
.thread_name(|index| format!("commit_{}", index))
.thread_name(|index| format!("commit-{}", index))
.build()
.unwrap()
});
Expand Down
2 changes: 1 addition & 1 deletion storage/aptosdb/src/state_merkle_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub const STATE_MERKLE_METADATA_DB_NAME: &str = "state_merkle_metadata_db";
static TREE_COMMIT_POOL: Lazy<rayon::ThreadPool> = Lazy::new(|| {
rayon::ThreadPoolBuilder::new()
.num_threads(32)
.thread_name(|index| format!("tree_commit_{}", index))
.thread_name(|index| format!("tree_commit-{}", index))
.build()
.unwrap()
});
Expand Down
2 changes: 1 addition & 1 deletion storage/aptosdb/src/state_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const MAX_COMMIT_PROGRESS_DIFFERENCE: u64 = 100000;
static IO_POOL: Lazy<rayon::ThreadPool> = Lazy::new(|| {
rayon::ThreadPoolBuilder::new()
.num_threads(32)
.thread_name(|index| format!("kv_reader_{}", index))
.thread_name(|index| format!("kv_reader-{}", index))
.build()
.unwrap()
});
Expand Down
2 changes: 1 addition & 1 deletion storage/storage-interface/src/async_proof_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
static IO_POOL: Lazy<rayon::ThreadPool> = Lazy::new(|| {
rayon::ThreadPoolBuilder::new()
.num_threads(AptosVM::get_num_proof_reading_threads())
.thread_name(|index| format!("proof_reader_{}", index))
.thread_name(|index| format!("proof_reader-{}", index))
.build()
.unwrap()
});
Expand Down

0 comments on commit 7d4fb98

Please sign in to comment.