From b3ce7775e56b2967a507b0ff34b8e6c530afce52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20Bezerra?= Date: Wed, 11 Dec 2024 15:43:36 -0300 Subject: [PATCH 1/3] enha: add flamegraph feature flag to ease profiling by improving readability of generated graphs --- Cargo.toml | 3 +++ src/config.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6db3cb008..836df1eca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -209,6 +209,9 @@ metrics = ["dep:metrics-exporter-prometheus"] # Enable runtime tracing/spans collection. tracing = [] +# Changes to help us generate our flamegraphs +flamegraph = [] + # Use Jemalloc as the global allocator jemalloc = ["dep:tikv-jemallocator"] diff --git a/src/config.rs b/src/config.rs index 8331c4455..622695f19 100644 --- a/src/config.rs +++ b/src/config.rs @@ -149,12 +149,20 @@ impl CommonConfig { // identify async threads let async_id = ASYNC_ID.fetch_add(1, Ordering::SeqCst); if async_id <= num_async_threads { - return format!("tokio-async-{}", async_id); + if cfg!(feature = "flamegraph") { + return format!("tokio-async"); + } else { + return format!("tokio-async-{}", async_id); + } } // identify blocking threads let blocking_id = BLOCKING_ID.fetch_add(1, Ordering::SeqCst); - format!("tokio-blocking-{}", blocking_id) + if cfg!(feature = "flamegraph") { + format!("tokio-blocking") + } else { + format!("tokio-blocking-{}", blocking_id) + } }) .build(); From 9826c34bd1e0d0c66fbb174fee528e78fd66fa9c Mon Sep 17 00:00:00 2001 From: gabriel-aranha-cw Date: Mon, 16 Dec 2024 18:48:00 -0300 Subject: [PATCH 2/3] fix: lint --- src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 622695f19..a220a62cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -150,7 +150,7 @@ impl CommonConfig { let async_id = ASYNC_ID.fetch_add(1, Ordering::SeqCst); if async_id <= num_async_threads { if cfg!(feature = "flamegraph") { - return format!("tokio-async"); + return "tokio-async".to_string() } else { return format!("tokio-async-{}", async_id); } @@ -159,7 +159,7 @@ impl CommonConfig { // identify blocking threads let blocking_id = BLOCKING_ID.fetch_add(1, Ordering::SeqCst); if cfg!(feature = "flamegraph") { - format!("tokio-blocking") + "tokio-blocking".to_string() } else { format!("tokio-blocking-{}", blocking_id) } From e8b3f862a7f1eaf487e1bf697d476bcb959a874a Mon Sep 17 00:00:00 2001 From: gabriel-aranha-cw Date: Mon, 16 Dec 2024 18:50:32 -0300 Subject: [PATCH 3/3] fix: lint --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index a220a62cf..57ee00884 100644 --- a/src/config.rs +++ b/src/config.rs @@ -150,7 +150,7 @@ impl CommonConfig { let async_id = ASYNC_ID.fetch_add(1, Ordering::SeqCst); if async_id <= num_async_threads { if cfg!(feature = "flamegraph") { - return "tokio-async".to_string() + return "tokio-async".to_string(); } else { return format!("tokio-async-{}", async_id); }