diff --git a/.github/workflows/asf-header.yml b/.github/workflows/asf-header.yml index a71c6627c0..62e3684981 100644 --- a/.github/workflows/asf-header.yml +++ b/.github/workflows/asf-header.yml @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Check License Header diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e4b6cc4a9..466c080018 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - run: | @@ -88,7 +88,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - run: | @@ -117,12 +117,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - - uses: actions/setup-go@v3 - with: - go-version: 1.21 - run: | rustup set auto-self-update disable rustup toolchain install ${RUST_VERSION} --profile minimal @@ -140,7 +137,7 @@ jobs: RUST_BACKTRACE: "1" - name: Upload Logs if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: CI-${{ github.sha }} path: | @@ -154,12 +151,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - - uses: actions/setup-go@v3 - with: - go-version: 1.21 - run: | rustup set auto-self-update disable rustup toolchain install ${RUST_VERSION} --profile minimal @@ -206,7 +200,7 @@ jobs: make run-opentsdb - name: Upload Logs if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: sdk-test-${{ github.sha }} path: | @@ -217,7 +211,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - run: | @@ -236,7 +230,7 @@ jobs: make run-recovery - name: Upload Logs if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: recovery-test-${{ github.sha }} path: | @@ -247,12 +241,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - - uses: actions/setup-go@v3 - with: - go-version: 1.21 - run: | rustup set auto-self-update disable rustup toolchain install ${RUST_VERSION} --profile minimal @@ -269,7 +260,7 @@ jobs: make run-dist-query - name: Upload Logs if: always() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: dist-query-test-${{ github.sha }} path: | diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml.disabled similarity index 98% rename from .github/workflows/coverage.yml rename to .github/workflows/coverage.yml.disabled index 1f91451aef..ecc8df5e4e 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml.disabled @@ -41,7 +41,7 @@ jobs: name: coverage runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Setup Rust toolchain @@ -65,4 +65,3 @@ jobs: - name: Report coverage continue-on-error: true run: bash <(curl -s https://codecov.io/bash) - diff --git a/.github/workflows/meta-ci.yml b/.github/workflows/meta-ci.yml.disabled similarity index 84% rename from .github/workflows/meta-ci.yml rename to .github/workflows/meta-ci.yml.disabled index dcbfcc7922..75410f215a 100644 --- a/.github/workflows/meta-ci.yml +++ b/.github/workflows/meta-ci.yml.disabled @@ -36,9 +36,6 @@ jobs: timeout-minutes: 5 steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v3 - with: - go-version: 1.21.3 - working-directory: ./horaemeta run: | make install-tools @@ -48,10 +45,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.21.3 + - uses: actions/checkout@v4 - working-directory: ./horaemeta run: | make install-tools @@ -61,10 +55,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 - with: - go-version: 1.21.3 + - uses: actions/checkout@v4 - working-directory: ./integration_tests run: | sudo apt install -y protobuf-compiler diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index be97587c5e..546df31e9b 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -29,7 +29,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: refs/tags/${{ inputs.version }} - name: Set up Docker Buildx @@ -52,7 +52,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: refs/tags/${{ inputs.version }} - name: Set up Docker Buildx diff --git a/.github/workflows/publish-nightly-image.yml b/.github/workflows/publish-nightly-image.yml index 13e1c69d06..e76e0512d1 100644 --- a/.github/workflows/publish-nightly-image.yml +++ b/.github/workflows/publish-nightly-image.yml @@ -35,7 +35,7 @@ jobs: packages: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to Container Registry diff --git a/.github/workflows/test-build-image.yml b/.github/workflows/test-build-image.yml index 6efb49b8da..cec0dd6a90 100644 --- a/.github/workflows/test-build-image.yml +++ b/.github/workflows/test-build-image.yml @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Release Disk Quota run: | sudo rm -rf /usr/local/lib/android # release about 10 GB diff --git a/.github/workflows/tsbs.yml b/.github/workflows/tsbs.yml index 7216edbc44..242c8b66c5 100644 --- a/.github/workflows/tsbs.yml +++ b/.github/workflows/tsbs.yml @@ -31,7 +31,7 @@ jobs: run-tsbs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Release Disk Quota @@ -57,7 +57,7 @@ jobs: - name: Update Summary run: | cat tsbs/result.md >> $GITHUB_STEP_SUMMARY - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: bench-${{ env.NOW }} path: | diff --git a/Cargo.lock b/Cargo.lock index 273a89683d..f4adea76ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -745,7 +745,7 @@ dependencies = [ "log", "parking", "polling", - "rustix", + "rustix 0.37.5", "slab", "socket2 0.4.9", "waker-fn", @@ -1060,9 +1060,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "bitvec" @@ -1590,7 +1590,7 @@ dependencies = [ "hash_ext", "horaedbproto 2.0.0", "macros", - "paste 1.0.12", + "paste", "prost 0.11.8", "rand 0.8.5", "seahash", @@ -2132,7 +2132,7 @@ dependencies = [ "arrow 49.0.0", "arrow-array 49.0.0", "datafusion-common", - "paste 1.0.12", + "paste", "sqlparser", "strum 0.25.0", "strum_macros 0.25.1", @@ -2179,7 +2179,7 @@ dependencies = [ "itertools 0.12.0", "log", "md-5", - "paste 1.0.12", + "paste", "petgraph", "rand 0.8.5", "regex", @@ -2512,23 +2512,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.0" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.45.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] @@ -2729,12 +2718,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -3192,7 +3175,7 @@ dependencies = [ "dashmap", "futures 0.3.28", "horaedbproto 1.0.24", - "paste 1.0.12", + "paste", "thiserror", "tokio", "tonic 0.8.3", @@ -3692,7 +3675,7 @@ checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", - "rustix", + "rustix 0.37.5", "windows-sys 0.45.0", ] @@ -3730,35 +3713,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] -name = "jemalloc-ctl" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" -dependencies = [ - "jemalloc-sys", - "libc", - "paste 0.1.18", -] - -[[package]] -name = "jemalloc-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" -dependencies = [ - "cc", - "fs_extra", - "libc", -] - -[[package]] -name = "jemallocator" -version = "0.3.2" +name = "jemalloc_pprof" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" +checksum = "5622af6d21ff86ed7797ef98e11b8f302da25ec69a7db9f6cde8e2e1c8df9992" dependencies = [ - "jemalloc-sys", + "anyhow", "libc", + "mappings", + "once_cell", + "pprof_util", + "tempfile", + "tikv-jemalloc-ctl", + "tokio", + "tracing", ] [[package]] @@ -3872,9 +3840,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.152" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libloading" @@ -3957,6 +3925,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "local-ip-address" version = "0.5.7" @@ -4073,6 +4047,19 @@ dependencies = [ name = "macros" version = "2.2.0-dev" +[[package]] +name = "mappings" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e434981a332777c2b3062652d16a55f8e74fa78e6b1882633f0d77399c84fc2a" +dependencies = [ + "anyhow", + "libc", + "once_cell", + "pprof_util", + "tracing", +] + [[package]] name = "matchers" version = "0.1.0" @@ -4406,7 +4393,7 @@ dependencies = [ "base64 0.21.0", "bigdecimal", "bindgen 0.65.1", - "bitflags 2.3.3", + "bitflags 2.9.1", "bitvec", "byteorder", "bytes", @@ -4986,7 +4973,7 @@ dependencies = [ "num", "num-bigint", "object_store 0.8.0", - "paste 1.0.12", + "paste", "seq-macro", "snap", "thrift", @@ -5050,31 +5037,12 @@ dependencies = [ "tokio", ] -[[package]] -name = "paste" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - [[package]] name = "paste" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", -] - [[package]] name = "pbjson" version = "0.5.1" @@ -5354,6 +5322,20 @@ dependencies = [ "thiserror", ] +[[package]] +name = "pprof_util" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa015c78eed2130951e22c58d2095849391e73817ab2e74f71b0b9f63dd8416" +dependencies = [ + "anyhow", + "backtrace", + "flate2", + "num", + "paste", + "prost 0.13.5", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -5465,11 +5447,11 @@ dependencies = [ name = "profile" version = "2.2.0-dev" dependencies = [ - "jemalloc-ctl", - "jemalloc-sys", - "jemallocator", + "jemalloc_pprof", "logger", "pprof", + "tikv-jemalloc-ctl", + "tikv-jemallocator", ] [[package]] @@ -5571,6 +5553,16 @@ dependencies = [ "prost-derive 0.12.3", ] +[[package]] +name = "prost" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" +dependencies = [ + "bytes", + "prost-derive 0.13.5", +] + [[package]] name = "prost-build" version = "0.11.7" @@ -5619,6 +5611,19 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "prost-derive" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" +dependencies = [ + "anyhow", + "itertools 0.12.0", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "prost-types" version = "0.11.8" @@ -5713,7 +5718,7 @@ dependencies = [ "macros", "meta_client", "notifier", - "paste 1.0.12", + "paste", "prom-remote-api", "prometheus 0.12.0", "prometheus-static-metric", @@ -5840,7 +5845,7 @@ dependencies = [ "logger", "macros", "partition_table_engine", - "paste 1.0.12", + "paste", "prom-remote-api", "regex", "regex-syntax 0.6.29", @@ -6047,15 +6052,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -6474,10 +6470,23 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys", + "linux-raw-sys 0.3.1", "windows-sys 0.45.0", ] +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags 2.9.1", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" version = "0.20.8" @@ -6786,7 +6795,7 @@ dependencies = [ "once_cell", "opensrv-mysql", "partition_table_engine", - "paste 1.0.12", + "paste", "pgwire", "profile", "prom-remote-api", @@ -7454,15 +7463,15 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.5.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "b8fcd239983515c23a32fb82099f97d0b11b8c72f654ed659363a95c3dad7a53" dependencies = [ "cfg-if 1.0.0", - "fastrand 1.9.0", - "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.45.0", + "fastrand 2.1.0", + "once_cell", + "rustix 0.38.44", + "windows-sys 0.52.0", ] [[package]] @@ -7549,6 +7558,37 @@ dependencies = [ "ordered-float", ] +[[package]] +name = "tikv-jemalloc-ctl" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f21f216790c8df74ce3ab25b534e0718da5a1916719771d3fec23315c99e468b" +dependencies = [ + "libc", + "paste", + "tikv-jemalloc-sys", +] + +[[package]] +name = "tikv-jemalloc-sys" +version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.1.43" diff --git a/horaemeta/README.md b/horaemeta/README.md index 79dd40effd..1f3d23227c 100644 --- a/horaemeta/README.md +++ b/horaemeta/README.md @@ -43,9 +43,5 @@ mkdir /tmp/meta2 ## Acknowledgment HoraeMeta refers to the excellent project [pd](https://github.com/tikv/pd) in design and some module and codes are forked from [pd](https://github.com/tikv/pd), thanks to the TiKV team. -## Contributing -The project is under rapid development so that any contribution is welcome. -Check our [Contributing Guide](https://github.com/apache/horaedb/blob/main/horaemeta/CONTRIBUTING.md) and make your first contribution! - ## License [Apache License 2.0](./LICENSE) diff --git a/src/components/profile/Cargo.toml b/src/components/profile/Cargo.toml index 1e6f9f44ee..0a1190c390 100644 --- a/src/components/profile/Cargo.toml +++ b/src/components/profile/Cargo.toml @@ -27,15 +27,12 @@ workspace = true [package.authors] workspace = true -[dependencies.jemalloc-sys] -version = "0.3.2" -features = ["stats", "profiling", "unprefixed_malloc_on_supported_platforms"] - [package.edition] workspace = true [dependencies] -jemalloc-ctl = "0.3.2" -jemallocator = "0.3.2" +jemalloc_pprof = { version = "0.7", features = ["symbolize"] } logger = { workspace = true } pprof = { workspace = true, features = ["flamegraph"] } +tikv-jemalloc-ctl = { version = "0.6.0", features = ["profiling"] } +tikv-jemallocator = { version = "0.6.0", features = ["profiling", "unprefixed_malloc_on_supported_platforms"] } diff --git a/src/components/profile/src/lib.rs b/src/components/profile/src/lib.rs index a6e7edf79f..882a8ddc43 100644 --- a/src/components/profile/src/lib.rs +++ b/src/components/profile/src/lib.rs @@ -27,8 +27,8 @@ use std::{ time::Duration, }; -use jemalloc_ctl::{Access, AsName}; use logger::{error, info}; +use tikv_jemalloc_ctl::{self as jemalloc_ctl, Access, AsName}; #[derive(Debug)] pub enum Error { @@ -48,7 +48,7 @@ impl std::error::Error for Error {} pub type Result = std::result::Result; #[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; +static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; const PROF_ACTIVE: &[u8] = b"prof.active\0"; const PROF_DUMP: &[u8] = b"prof.dump\0"; @@ -183,4 +183,37 @@ impl Profiler { })?; Ok(()) } + + pub fn dump_heap_pprof(&self, seconds: u64) -> Result> { + // concurrent profiling is disabled. + let lock_guard = self + .heap_prof_lock + .try_lock() + .map_err(|e| Error::Internal { + msg: format!("failed to acquire heap_prof_lock, err:{e}"), + })?; + info!( + "Profiler::dump_heap_pprof start heap profiling {} seconds", + seconds + ); + + let _guard = ProfLockGuard::new(lock_guard)?; + + // wait for seconds for collect the profiling data + thread::sleep(Duration::from_secs(seconds)); + + if let Some(prof_ctl) = jemalloc_pprof::PROF_CTL.as_ref() { + let mut prof_ctl = prof_ctl.try_lock().map_err(|e| Error::Internal { + msg: format!("failed to lock JemallocProfCtl, err: {e}"), + })?; + let pprof = prof_ctl.dump_pprof().map_err(|e| Error::Internal { + msg: format!("failed to dump pprof, err: {e}"), + })?; + Ok(pprof) + } else { + Err(Error::Internal { + msg: "PROF_CTL is not initialized".to_string(), + }) + } + } } diff --git a/src/server/src/http.rs b/src/server/src/http.rs index d31f5adec0..1c045d03e7 100644 --- a/src/server/src/http.rs +++ b/src/server/src/http.rs @@ -103,6 +103,12 @@ pub enum Error { backtrace: Backtrace, }, + #[snafu(display("Fail to do heap pprof, err:{}.\nBacktrace:\n{}", source, backtrace))] + PprofHeap { + source: profile::Error, + backtrace: Backtrace, + }, + #[snafu(display("Fail to do cpu profiling, err:{}.\nBacktrace:\n{}", source, backtrace))] ProfileCPU { source: profile::Error, @@ -251,6 +257,7 @@ impl Service { .or(self.update_log_level()) .or(self.profile_cpu()) .or(self.profile_heap()) + .or(self.pprof_heap()) .or(self.server_config()) .or(self.shards()) .or(self.wal_stats()) @@ -627,6 +634,30 @@ impl Service { ) } + // GET /debug/pprof/heap/{seconds} + fn pprof_heap( + &self, + ) -> impl Filter + Clone { + warp::path!("debug" / "pprof" / "heap" / ..) + .and(warp::path::param::()) + .and(warp::get()) + .and(self.with_profiler()) + .and(self.with_runtime()) + .and_then( + |duration_sec: u64, profiler: Arc, runtime: Arc| async move { + let handle = runtime.spawn_blocking(move || { + profiler.dump_heap_pprof(duration_sec).context(PprofHeap) + }); + let result = handle.await.context(JoinAsyncTask); + match result { + Ok(Ok(pprof_data)) => Ok(pprof_data.into_response()), + Ok(Err(e)) => Err(reject::custom(e)), + Err(e) => Err(reject::custom(e)), + } + }, + ) + } + // GET /debug/config fn server_config( &self, @@ -975,6 +1006,7 @@ fn error_to_status_code(err: &Error) -> StatusCode { | Error::ParseIpAddr { .. } | Error::ProfileHeap { .. } | Error::ProfileCPU { .. } + | Error::PprofHeap { .. } | Error::Internal { .. } | Error::JoinAsyncTask { .. } | Error::AlreadyStarted { .. }