diff --git a/Cargo.lock b/Cargo.lock index dccda78d5bb4e..4828ed27fae82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7097,7 +7097,6 @@ dependencies = [ "sysinfo", "tempfile", "thiserror", - "tikv-jemalloc-ctl", "tinyvec", "toml 0.7.8", "tower-layer", @@ -7111,6 +7110,19 @@ dependencies = [ "workspace-hack", ] +[[package]] +name = "risingwave_common_heap_profiling" +version = "1.3.0-alpha" +dependencies = [ + "anyhow", + "chrono", + "madsim-tokio", + "parking_lot 0.12.1", + "risingwave_common", + "tikv-jemalloc-ctl", + "tracing", +] + [[package]] name = "risingwave_common_proc_macro" version = "1.3.0-alpha" @@ -7181,6 +7193,7 @@ dependencies = [ "parking_lot 0.12.1", "prometheus", "risingwave_common", + "risingwave_common_heap_profiling", "risingwave_common_service", "risingwave_object_store", "risingwave_pb", @@ -7214,6 +7227,7 @@ dependencies = [ "rand", "risingwave_batch", "risingwave_common", + "risingwave_common_heap_profiling", "risingwave_common_service", "risingwave_connector", "risingwave_hummock_sdk", @@ -7666,6 +7680,7 @@ dependencies = [ "reqwest", "risingwave_backup", "risingwave_common", + "risingwave_common_heap_profiling", "risingwave_common_service", "risingwave_connector", "risingwave_hummock_sdk", diff --git a/Cargo.toml b/Cargo.toml index 81d914b416d17..a975a0186e712 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -127,6 +127,7 @@ risingwave_batch = { path = "./src/batch" } risingwave_cmd = { path = "./src/cmd" } risingwave_common = { path = "./src/common" } risingwave_common_service = { path = "./src/common/common_service" } +risingwave_common_heap_profiling = { path = "./src/common/heap_profiling" } risingwave_compactor = { path = "./src/storage/compactor" } risingwave_compute = { path = "./src/compute" } risingwave_ctl = { path = "./src/ctl" } diff --git a/src/common/Cargo.toml b/src/common/Cargo.toml index fd105333f645d..a9b1ef1c95d7f 100644 --- a/src/common/Cargo.toml +++ b/src/common/Cargo.toml @@ -86,7 +86,6 @@ strum = "0.25" strum_macros = "0.25" sysinfo = { version = "0.29", default-features = false } thiserror = "1" -tikv-jemalloc-ctl = { workspace = true } tinyvec = { version = "1", features = ["rustc_1_55", "grab_spare_slice"] } tokio = { version = "0.2", package = "madsim-tokio", features = [ "rt", diff --git a/src/common/heap_profiling/Cargo.toml b/src/common/heap_profiling/Cargo.toml new file mode 100644 index 0000000000000..6c1b9957555bd --- /dev/null +++ b/src/common/heap_profiling/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "risingwave_common_heap_profiling" +version = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[package.metadata.cargo-machete] +ignored = ["workspace-hack"] + +[package.metadata.cargo-udeps.ignore] +normal = ["workspace-hack"] + +[dependencies] +tikv-jemalloc-ctl = { workspace = true } +risingwave_common = {workspace =true} +tokio = { version = "0.2", package = "madsim-tokio" } +tracing = "0.1" +chrono = { version = "0.4", default-features = false, features = [ + "clock", + "std", +] } +anyhow = "1" +parking_lot = "0.12" + +[lints] +workspace = true diff --git a/src/common/src/heap_profiling/jeprof.rs b/src/common/heap_profiling/src/jeprof.rs similarity index 97% rename from src/common/src/heap_profiling/jeprof.rs rename to src/common/heap_profiling/src/jeprof.rs index 5c79c67604418..013632f32838e 100644 --- a/src/common/src/heap_profiling/jeprof.rs +++ b/src/common/heap_profiling/src/jeprof.rs @@ -17,8 +17,7 @@ use std::process::Command; use std::{env, fs}; use anyhow::anyhow; - -use crate::error::Result; +use risingwave_common::error::Result; pub async fn run(profile_path: String, collapsed_path: String) -> Result<()> { let executable_path = env::current_exe()?; diff --git a/src/common/src/heap_profiling/mod.rs b/src/common/heap_profiling/src/lib.rs similarity index 100% rename from src/common/src/heap_profiling/mod.rs rename to src/common/heap_profiling/src/lib.rs diff --git a/src/common/src/heap_profiling/profiler.rs b/src/common/heap_profiling/src/profiler.rs similarity index 98% rename from src/common/src/heap_profiling/profiler.rs rename to src/common/heap_profiling/src/profiler.rs index fbf972d94f2f0..49e81e8526241 100644 --- a/src/common/src/heap_profiling/profiler.rs +++ b/src/common/heap_profiling/src/profiler.rs @@ -17,13 +17,13 @@ use std::fs; use std::path::Path; use parking_lot::Once; +use risingwave_common::config::HeapProfilingConfig; use tikv_jemalloc_ctl::{ epoch as jemalloc_epoch, opt as jemalloc_opt, prof as jemalloc_prof, stats as jemalloc_stats, }; use tokio::time::{self, Duration}; use super::AUTO_DUMP_SUFFIX; -use crate::config::HeapProfilingConfig; pub struct HeapProfiler { config: HeapProfilingConfig, diff --git a/src/common/src/lib.rs b/src/common/src/lib.rs index 86d29213374a0..da58e53b8c52d 100644 --- a/src/common/src/lib.rs +++ b/src/common/src/lib.rs @@ -77,7 +77,6 @@ pub mod test_utils; pub mod types; pub mod vnode_mapping; -pub mod heap_profiling; pub mod range; pub mod test_prelude { diff --git a/src/compute/Cargo.toml b/src/compute/Cargo.toml index 1cf81e6070820..93e4e643dcf04 100644 --- a/src/compute/Cargo.toml +++ b/src/compute/Cargo.toml @@ -29,6 +29,7 @@ pprof = { version = "0.13", features = ["flamegraph"] } prometheus = { version = "0.13" } risingwave_batch = { workspace = true } risingwave_common = { workspace = true } +risingwave_common_heap_profiling = { workspace = true } risingwave_common_service = { workspace = true } risingwave_connector = { workspace = true } risingwave_hummock_sdk = { workspace = true } diff --git a/src/compute/src/rpc/service/monitor_service.rs b/src/compute/src/rpc/service/monitor_service.rs index ea95a87574572..565a7af2467ec 100644 --- a/src/compute/src/rpc/service/monitor_service.rs +++ b/src/compute/src/rpc/service/monitor_service.rs @@ -20,9 +20,7 @@ use std::time::Duration; use itertools::Itertools; use risingwave_common::config::ServerConfig; -use risingwave_common::heap_profiling::{ - self, AUTO_DUMP_SUFFIX, COLLAPSED_SUFFIX, MANUALLY_DUMP_SUFFIX, -}; +use risingwave_common_heap_profiling::{AUTO_DUMP_SUFFIX, COLLAPSED_SUFFIX, MANUALLY_DUMP_SUFFIX}; use risingwave_pb::monitor_service::monitor_service_server::MonitorService; use risingwave_pb::monitor_service::{ AnalyzeHeapRequest, AnalyzeHeapResponse, HeapProfilingRequest, HeapProfilingResponse, @@ -219,7 +217,11 @@ impl MonitorService for MonitorServiceImpl { // run jeprof if the target was not analyzed before if !collapsed_path.exists() { - heap_profiling::jeprof::run(dumped_path_str, collapsed_path_str.clone()).await?; + risingwave_common_heap_profiling::jeprof::run( + dumped_path_str, + collapsed_path_str.clone(), + ) + .await?; } let file = fs::read(Path::new(&collapsed_path_str))?; diff --git a/src/compute/src/server.rs b/src/compute/src/server.rs index 02d7d6683ea8c..bfa2ad6584090 100644 --- a/src/compute/src/server.rs +++ b/src/compute/src/server.rs @@ -26,7 +26,6 @@ use risingwave_common::config::{ load_config, AsyncStackTraceOption, MetricLevel, StorageMemoryConfig, MAX_CONNECTION_WINDOW_SIZE, STREAM_WINDOW_SIZE, }; -use risingwave_common::heap_profiling::HeapProfiler; use risingwave_common::monitor::connection::{RouterExt, TcpConfig}; use risingwave_common::system_param::local_manager::LocalSystemParamsManager; use risingwave_common::telemetry::manager::TelemetryManager; @@ -34,6 +33,7 @@ use risingwave_common::telemetry::telemetry_env_enabled; use risingwave_common::util::addr::HostAddr; use risingwave_common::util::pretty_bytes::convert; use risingwave_common::{GIT_SHA, RW_VERSION}; +use risingwave_common_heap_profiling::HeapProfiler; use risingwave_common_service::metrics_manager::MetricsManager; use risingwave_common_service::observer_manager::ObserverManager; use risingwave_common_service::tracing::TracingExtractLayer; diff --git a/src/meta/Cargo.toml b/src/meta/Cargo.toml index f9876eb9cfe25..1478d9e34e5be 100644 --- a/src/meta/Cargo.toml +++ b/src/meta/Cargo.toml @@ -49,6 +49,7 @@ regex = "1" reqwest = "0.11" risingwave_backup = { workspace = true } risingwave_common = { workspace = true } +risingwave_common_heap_profiling = { workspace = true } risingwave_common_service = { workspace = true } risingwave_connector = { workspace = true } risingwave_hummock_sdk = { workspace = true } diff --git a/src/meta/src/dashboard/mod.rs b/src/meta/src/dashboard/mod.rs index e00b87b0ed9a4..a184bc9155e68 100644 --- a/src/meta/src/dashboard/mod.rs +++ b/src/meta/src/dashboard/mod.rs @@ -57,7 +57,7 @@ pub(super) mod handlers { use axum::Json; use itertools::Itertools; use risingwave_common::bail; - use risingwave_common::heap_profiling::COLLAPSED_SUFFIX; + use risingwave_common_heap_profiling::COLLAPSED_SUFFIX; use risingwave_pb::catalog::table::TableType; use risingwave_pb::catalog::{Sink, Source, Table}; use risingwave_pb::common::WorkerNode; diff --git a/src/meta/src/lib.rs b/src/meta/src/lib.rs index 5fa90a77d48cb..7a147274a8d2f 100644 --- a/src/meta/src/lib.rs +++ b/src/meta/src/lib.rs @@ -55,9 +55,9 @@ use std::time::Duration; use clap::Parser; pub use error::{MetaError, MetaResult}; use risingwave_common::config::OverrideConfig; -use risingwave_common::heap_profiling::HeapProfiler; use risingwave_common::util::resource_util; use risingwave_common::{GIT_SHA, RW_VERSION}; +use risingwave_common_heap_profiling::HeapProfiler; pub use rpc::{ElectionClient, ElectionMember, EtcdElectionClient}; use crate::manager::MetaOpts; diff --git a/src/storage/compactor/Cargo.toml b/src/storage/compactor/Cargo.toml index f4118ff639b5d..54d48a88923a6 100644 --- a/src/storage/compactor/Cargo.toml +++ b/src/storage/compactor/Cargo.toml @@ -22,6 +22,7 @@ clap = { version = "4", features = ["derive"] } parking_lot = "0.12" prometheus = { version = "0.13" } risingwave_common = { workspace = true } +risingwave_common_heap_profiling = { workspace = true } risingwave_common_service = { workspace = true } risingwave_object_store = { workspace = true } risingwave_pb = { workspace = true } diff --git a/src/storage/compactor/src/server.rs b/src/storage/compactor/src/server.rs index 627cd3491d78f..3ad23bf68cc3b 100644 --- a/src/storage/compactor/src/server.rs +++ b/src/storage/compactor/src/server.rs @@ -21,7 +21,6 @@ use parking_lot::RwLock; use risingwave_common::config::{ extract_storage_memory_config, load_config, AsyncStackTraceOption, MetricLevel, RwConfig, }; -use risingwave_common::heap_profiling::HeapProfiler; use risingwave_common::monitor::connection::{RouterExt, TcpConfig}; use risingwave_common::system_param::local_manager::LocalSystemParamsManager; use risingwave_common::system_param::reader::SystemParamsReader; @@ -30,6 +29,7 @@ use risingwave_common::telemetry::telemetry_env_enabled; use risingwave_common::util::addr::HostAddr; use risingwave_common::util::resource_util; use risingwave_common::{GIT_SHA, RW_VERSION}; +use risingwave_common_heap_profiling::HeapProfiler; use risingwave_common_service::metrics_manager::MetricsManager; use risingwave_common_service::observer_manager::ObserverManager; use risingwave_object_store::object::object_metrics::GLOBAL_OBJECT_STORE_METRICS;