Skip to content

Commit 07cf2fe

Browse files
housemeCopilot
andauthored
fix(pprof): Fixed the problem that pprof crate does not support the window platform (rustfs#1681)
Signed-off-by: houseme <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 087f58b commit 07cf2fe

File tree

5 files changed

+57
-132
lines changed

5 files changed

+57
-132
lines changed

Cargo.lock

Lines changed: 4 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/scanner/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ tracing = { workspace = true }
3838
serde = { workspace = true, features = ["derive"] }
3939
serde_json = { workspace = true }
4040
thiserror = { workspace = true }
41-
uuid = { workspace = true, features = ["v4", "serde"] }
42-
anyhow = { workspace = true }
4341
async-trait = { workspace = true }
4442
futures = { workspace = true }
4543
time = { workspace = true }
@@ -55,8 +53,6 @@ rand = { workspace = true }
5553
s3s = { workspace = true }
5654

5755
[dev-dependencies]
58-
tokio-test = { workspace = true }
5956
tracing-subscriber = { workspace = true }
60-
tempfile = { workspace = true }
6157
serial_test = { workspace = true }
62-
heed = { version = "0.22.0" }
58+
uuid = { workspace = true, features = ["v4", "serde"] }

rustfs/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ urlencoding = { workspace = true }
125125
uuid = { workspace = true }
126126
zip = { workspace = true }
127127
libc = { workspace = true }
128-
pprof = { workspace = true }
129128

130129
# Observability and Metrics
131130
metrics = { workspace = true }
@@ -141,14 +140,20 @@ libsystemd.workspace = true
141140

142141
[target.'cfg(not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))'.dependencies]
143142
mimalloc = { workspace = true }
143+
144+
# Note: If you want to *explicitly* exclude Windows from a target dependency set,
145+
# you can use a cfg like the following instead:
146+
[target.'cfg(all(not(target_os = "windows"), not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))))'.dependencies]
144147
starshard = { workspace = true }
145148
backtrace = { workspace = true }
146149
rand = { workspace = true }
150+
pprof = { workspace = true }
147151

148152
[target.'cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))'.dependencies]
149153
tikv-jemallocator = { workspace = true }
150154
tikv-jemalloc-ctl = { workspace = true }
151155
jemalloc_pprof = { workspace = true }
156+
pprof = { workspace = true }
152157

153158
[dev-dependencies]
154159
uuid = { workspace = true, features = ["v4"] }

rustfs/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,18 @@ use tracing::{debug, error, info, instrument, warn};
7070
#[global_allocator]
7171
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
7272

73-
#[cfg(not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
73+
#[cfg(all(
74+
not(target_os = "windows"),
75+
not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))
76+
))]
7477
#[global_allocator]
7578
static GLOBAL: profiling::allocator::TracingAllocator<mimalloc::MiMalloc> =
7679
profiling::allocator::TracingAllocator::new(mimalloc::MiMalloc);
7780

81+
#[cfg(target_os = "windows")]
82+
#[global_allocator]
83+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
84+
7885
fn main() {
7986
let runtime = server::get_tokio_runtime_builder()
8087
.build()

rustfs/src/profiling.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,42 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#[cfg(not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
15+
#[cfg(all(
16+
not(target_os = "windows"),
17+
not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))
18+
))]
1619
pub mod allocator;
1720

18-
#[cfg(not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
21+
#[cfg(target_os = "windows")]
22+
mod windows_impl {
23+
use std::path::PathBuf;
24+
use std::time::Duration;
25+
use tracing::info;
26+
27+
pub async fn init_from_env() {
28+
info!("Profiling initialization skipped on Windows platform (not supported)");
29+
}
30+
31+
/// Stop all background profiling tasks
32+
pub fn shutdown_profiling() {
33+
info!("profiling: shutdown called on Windows platform (no-op)");
34+
}
35+
36+
pub async fn dump_cpu_pprof_for(_duration: Duration) -> Result<PathBuf, String> {
37+
Err("CPU profiling is not supported on Windows platform".to_string())
38+
}
39+
40+
pub async fn dump_memory_pprof_now() -> Result<PathBuf, String> {
41+
Err("Memory profiling is not supported on Windows platform".to_string())
42+
}
43+
}
44+
#[cfg(target_os = "windows")]
45+
pub use windows_impl::{dump_cpu_pprof_for, dump_memory_pprof_now, init_from_env, shutdown_profiling};
46+
47+
#[cfg(all(
48+
not(target_os = "windows"),
49+
not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))
50+
))]
1951
mod generic_impl {
2052
use super::allocator;
2153
use rustfs_config::{
@@ -123,7 +155,10 @@ mod generic_impl {
123155
}
124156
}
125157

126-
#[cfg(not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64")))]
158+
#[cfg(all(
159+
not(target_os = "windows"),
160+
not(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))
161+
))]
127162
pub use generic_impl::{dump_cpu_pprof_for, dump_memory_pprof_now, init_from_env, shutdown_profiling};
128163

129164
#[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"))]

0 commit comments

Comments
 (0)