From b53487bdbc196084f58f2554cfd9b0584cc2524f Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 14 Apr 2024 13:04:25 +0800 Subject: [PATCH] Add tokio-trace feature for tokio-console debug --- Cargo.lock | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 144 +++++++++++++++++---------------- Makefile | 4 + src/main.rs | 3 + 4 files changed, 301 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 414970fd95..22de2aab93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -580,6 +580,7 @@ version = "0.116.0-pre" dependencies = [ "ckb-bin", "ckb-build-info", + "console-subscriber", "tikv-jemallocator", ] @@ -1908,6 +1909,43 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "console-api" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd326812b3fd01da5bb1af7d340d0d555fd3d4b641e7f1dfcf5962a902952787" +dependencies = [ + "futures-core", + "prost", + "prost-types", + "tonic", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7481d4c57092cd1c19dd541b92bdce883de840df30aa5d03fd48a3935c01842e" +dependencies = [ + "console-api", + "crossbeam-channel", + "crossbeam-utils", + "futures-task", + "hdrhistogram", + "humantime", + "prost-types", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "const-random" version = "0.1.18" @@ -2655,8 +2693,8 @@ dependencies = [ "aho-corasick", "bstr", "log", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.6", + "regex-syntax 0.8.2", ] [[package]] @@ -2791,6 +2829,19 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "base64 0.21.7", + "byteorder", + "flate2", + "nom", + "num-traits", +] + [[package]] name = "heapsize" version = "0.4.2" @@ -2938,6 +2989,18 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -3024,7 +3087,7 @@ dependencies = [ "globset", "log", "memchr", - "regex-automata", + "regex-automata 0.4.6", "same-file", "walkdir", "winapi-util", @@ -3361,6 +3424,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "matches" version = "0.1.10" @@ -4163,12 +4235,44 @@ dependencies = [ "rand 0.8.5", "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax", + "regex-syntax 0.8.2", "rusty-fork", "tempfile", "unarray", ] +[[package]] +name = "prost" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" +dependencies = [ + "anyhow", + "itertools 0.12.1", + "proc-macro2", + "quote", + "syn 2.0.52", +] + +[[package]] +name = "prost-types" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" +dependencies = [ + "prost", +] + [[package]] name = "protobuf" version = "2.28.0" @@ -4368,8 +4472,17 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.6", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -4380,9 +4493,15 @@ checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.2" @@ -4880,6 +4999,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -5355,6 +5483,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tikv-jemalloc-ctl" version = "0.5.4" @@ -5467,9 +5605,20 @@ dependencies = [ "signal-hook-registry", "socket2 0.5.6", "tokio-macros", + "tracing", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-macros" version = "2.2.0" @@ -5562,6 +5711,33 @@ dependencies = [ "serde", ] +[[package]] +name = "tonic" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" +dependencies = [ + "async-stream", + "async-trait", + "axum", + "base64 0.21.7", + "bytes", + "h2", + "http", + "http-body", + "hyper", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -5570,9 +5746,13 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "indexmap 1.9.3", "pin-project", "pin-project-lite", + "rand 0.8.5", + "slab", "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", @@ -5617,9 +5797,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -5627,6 +5819,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "once_cell", + "regex", + "sharded-slab", + "thread_local", + "tracing", + "tracing-core", ] [[package]] @@ -5886,6 +6094,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 3d051a1ea7..b38fe4efe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,83 +16,84 @@ ckb-build-info = { path = "util/build-info", version = "= 0.116.0-pre" } [dependencies] ckb-build-info = { path = "util/build-info", version = "= 0.116.0-pre" } ckb-bin = { path = "ckb-bin", version = "= 0.116.0-pre" } +console-subscriber = { version = "0.2.0", optional = true } [dev-dependencies] [workspace] # To get a list sorted by dependencies, run devtools/ci/check-cyclic-dependencies.py members = [ - "util", - "util/occupied-capacity/core", - "util/channel", - "util/systemtime", - "util/fixed-hash/core", - "util/build-info", - "util/logger", - "util/logger-config", - "util/metrics-config", - "util/hash", - "util/rational", - "benches", - "db-schema", - "util/spawn", - "util/occupied-capacity/macros", - "util/fixed-hash/macros", - "util/logger-service", - "util/runtime", - "util/stop-handler", - "util/metrics", - "util/metrics-service", - "util/fixed-hash", - "util/occupied-capacity", - "util/crypto", - "util/constant", - "error", - "util/multisig", - "util/gen-types", - "util/migrate/migration-template", - "util/types", - "util/jsonrpc-types", - "freezer", - "resource", - "pow", - "util/dao/utils", - "traits", - "spec", - "util/proposal-table", - "script", - "util/app-config", - "db", - "network", - "miner", - "notify", - "util/memory-tracker", - "db-migration", - "util/network-alert", - "store", - "util/indexer-sync", - "util/indexer", - "util/rich-indexer", - "util/chain-iter", - "util/dao", - "util/test-chain-utils", - "util/reward-calculator", - "util/snapshot", - "util/migrate", - "verification/traits", - "verification", - "verification/contextual", - "tx-pool", - "shared", - "block-filter", - "chain", - "sync", - "util/instrument", - "rpc", - "util/light-client-protocol-server", - "util/launcher", - "devtools/doc/rpc-gen", - "ckb-bin" + "util", + "util/occupied-capacity/core", + "util/channel", + "util/systemtime", + "util/fixed-hash/core", + "util/build-info", + "util/logger", + "util/logger-config", + "util/metrics-config", + "util/hash", + "util/rational", + "benches", + "db-schema", + "util/spawn", + "util/occupied-capacity/macros", + "util/fixed-hash/macros", + "util/logger-service", + "util/runtime", + "util/stop-handler", + "util/metrics", + "util/metrics-service", + "util/fixed-hash", + "util/occupied-capacity", + "util/crypto", + "util/constant", + "error", + "util/multisig", + "util/gen-types", + "util/migrate/migration-template", + "util/types", + "util/jsonrpc-types", + "freezer", + "resource", + "pow", + "util/dao/utils", + "traits", + "spec", + "util/proposal-table", + "script", + "util/app-config", + "db", + "network", + "miner", + "notify", + "util/memory-tracker", + "db-migration", + "util/network-alert", + "store", + "util/indexer-sync", + "util/indexer", + "util/rich-indexer", + "util/chain-iter", + "util/dao", + "util/test-chain-utils", + "util/reward-calculator", + "util/snapshot", + "util/migrate", + "verification/traits", + "verification", + "verification/contextual", + "tx-pool", + "shared", + "block-filter", + "chain", + "sync", + "util/instrument", + "rpc", + "util/light-client-protocol-server", + "util/launcher", + "devtools/doc/rpc-gen", + "ckb-bin" ] [workspace.dependencies] @@ -124,3 +125,4 @@ with_dns_seeding = ["ckb-bin/with_dns_seeding"] profiling = ["tikv-jemallocator/profiling", "ckb-bin/profiling"] portable = ["ckb-bin/portable"] march-native = ["ckb-bin/march-native"] +tokio-trace = ["console-subscriber"] diff --git a/Makefile b/Makefile index 4915a49164..1190c70fc3 100644 --- a/Makefile +++ b/Makefile @@ -137,6 +137,10 @@ build-for-profiling: ## Build binary with for profiling. prod: ## Build binary for production release. cargo build ${VERBOSE} ${CKB_BUILD_TARGET} --profile prod --features "with_sentry,with_dns_seeding" +.PHONY: trace-tokio +trace-tokio: ## Build binary for production release and with tokio trace feature. + RUSTFLAGS="--cfg tokio_unstable" cargo build ${VERBOSE} ${CKB_BUILD_TARGET} --profile prod --features "tokio-trace,with_sentry,with_dns_seeding" + .PHONY: prod_portable prod_portable: ## Build binary for portable production release. cargo build ${VERBOSE} ${CKB_BUILD_TARGET} --profile prod --features "with_sentry,with_dns_seeding,portable" diff --git a/src/main.rs b/src/main.rs index 15f623d055..55c5dfa74d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,9 @@ use ckb_build_info::Version; static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; fn main() { + #[cfg(feature = "tokio-trace")] + console_subscriber::init(); + let version = get_version(); if let Some(exit_code) = run_app(version).err() { ::std::process::exit(exit_code.into());