Skip to content

Commit 8c7a813

Browse files
committed
add memory allocator to version info
1 parent 9147904 commit 8c7a813

22 files changed

Lines changed: 161 additions & 99 deletions

File tree

Cargo.lock

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

vey-bench/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ description = "Multi-Target Benchmark Tool developed by the VEY project"
1111
[dependencies]
1212
thiserror.workspace = true
1313
anyhow.workspace = true
14+
cfg-if.workspace = true
1415
clap.workspace = true
1516
clap_complete.workspace = true
1617
indicatif = "0.18"

vey-bench/src/build.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@ const QUIC_FEATURE: Option<&str> = option_env!("VEY_QUIC_FEATURE");
2222
pub fn print_version() {
2323
println!("{PKG_NAME} {VERSION}");
2424
print!("Features:");
25-
#[cfg(feature = "jemalloc")]
26-
if let Some(version) = vey_jemalloc::lib_version() {
27-
print!(" jemalloc({})", version.to_string_lossy());
28-
}
29-
#[cfg(feature = "mimalloc")]
30-
println!(" mimalloc({})", vey_mimalloc::lib_version());
3125
if let Some(quic) = QUIC_FEATURE {
3226
print!(" {quic}");
3327
}
3428
println!();
29+
print!("Memory Allocator: ");
30+
cfg_if::cfg_if!(
31+
if #[cfg(feature = "jemalloc")] {
32+
if let Some(version) = vey_jemalloc::lib_version() {
33+
println!("jemalloc {}", version.to_string_lossy());
34+
}
35+
} else if #[cfg(feature = "mimalloc")] {
36+
println!("mimalloc {}", vey_mimalloc::lib_version());
37+
} else {
38+
println!("system");
39+
}
40+
);
3541
if let Some(variant) = vey_openssl::variant_name() {
3642
println!("OpenSSL Variant: {variant}");
3743
}

vey-bench/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ use clap_complete::Shell;
1515
const COMMAND_VERSION: &str = "version";
1616
const COMMAND_COMPLETION: &str = "completion";
1717

18-
#[cfg(feature = "jemalloc")]
19-
#[global_allocator]
20-
static GLOBAL: vey_jemalloc::Jemalloc = vey_jemalloc::Jemalloc;
21-
22-
#[cfg(feature = "mimalloc")]
23-
#[global_allocator]
24-
static GLOBAL: vey_mimalloc::Mimalloc = vey_mimalloc::Mimalloc;
18+
cfg_if::cfg_if! {
19+
if #[cfg(feature="jemalloc")] {
20+
#[global_allocator]
21+
static GLOBAL: vey_jemalloc::Jemalloc = vey_jemalloc::Jemalloc;
22+
} else if #[cfg(feature="mimalloc")] {
23+
#[global_allocator]
24+
static GLOBAL: vey_mimalloc::Mimalloc = vey_mimalloc::Mimalloc;
25+
}
26+
}
2527

2628
fn build_cli_args() -> Command {
2729
vey_bench::add_global_args(Command::new(vey_bench::build::PKG_NAME))

vey-dcgen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ description = "Dynamic certificate generator"
1111
[dependencies]
1212
anyhow.workspace = true
1313
clap.workspace = true
14+
cfg-if.workspace = true
1415
log = { workspace = true, features = ["max_level_trace", "release_max_level_debug"] }
1516
openssl.workspace = true
1617
openssl-sys.workspace = true # for openssl variant detection

vey-dcgen/src/build.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ const OPENSSL_VARIANT: Option<&str> = option_env!("VEY_OPENSSL_VARIANT");
2222
pub fn print_version(verbose_level: u8) {
2323
println!("{PKG_NAME} {VERSION}");
2424
if verbose_level > 0 {
25-
print!("Features:");
26-
#[cfg(feature = "jemalloc")]
27-
if let Some(version) = vey_jemalloc::lib_version() {
28-
print!(" jemalloc({})", version.to_string_lossy());
29-
}
30-
#[cfg(feature = "mimalloc")]
31-
println!(" mimalloc({})", vey_mimalloc::lib_version());
32-
println!();
25+
print!("Memory Allocator: ");
26+
cfg_if::cfg_if!(
27+
if #[cfg(feature = "jemalloc")] {
28+
if let Some(version) = vey_jemalloc::lib_version() {
29+
println!("jemalloc {}", version.to_string_lossy());
30+
}
31+
} else if #[cfg(feature = "mimalloc")] {
32+
println!("mimalloc {}", vey_mimalloc::lib_version());
33+
} else {
34+
println!("system");
35+
}
36+
);
3337
if let Some(variant) = OPENSSL_VARIANT {
3438
println!("OpenSSL Variant: {variant}");
3539
}

vey-dcgen/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ use log::{debug, error, info};
99

1010
use vey_dcgen::opts::ProcArgs;
1111

12-
#[cfg(feature = "jemalloc")]
13-
#[global_allocator]
14-
static GLOBAL: vey_jemalloc::Jemalloc = vey_jemalloc::Jemalloc;
15-
16-
#[cfg(feature = "mimalloc")]
17-
#[global_allocator]
18-
static GLOBAL: vey_mimalloc::Mimalloc = vey_mimalloc::Mimalloc;
12+
cfg_if::cfg_if! {
13+
if #[cfg(feature="jemalloc")] {
14+
#[global_allocator]
15+
static GLOBAL: vey_jemalloc::Jemalloc = vey_jemalloc::Jemalloc;
16+
} else if #[cfg(feature="mimalloc")] {
17+
#[global_allocator]
18+
static GLOBAL: vey_mimalloc::Mimalloc = vey_mimalloc::Mimalloc;
19+
}
20+
}
1921

2022
fn main() -> anyhow::Result<()> {
2123
openssl::init();

vey-gateway/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description = "Generic Gateway"
1212
anyhow.workspace = true
1313
thiserror.workspace = true
1414
async-trait.workspace = true
15+
cfg-if.workspace = true
1516
yaml-rust.workspace = true
1617
serde_json.workspace = true
1718
log = { workspace = true, features = ["max_level_trace", "release_max_level_debug"] }

vey-gateway/src/build.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ pub(crate) fn print_version(verbose_level: u8) {
2323
println!("{PKG_NAME} {VERSION}");
2424
if verbose_level > 0 {
2525
print!("Features:");
26-
#[cfg(feature = "jemalloc")]
27-
if let Some(version) = vey_jemalloc::lib_version() {
28-
print!(" jemalloc({})", version.to_string_lossy());
29-
}
30-
#[cfg(feature = "mimalloc")]
31-
println!(" mimalloc({})", vey_mimalloc::lib_version());
3226
if let Some(quic) = QUIC_FEATURE {
3327
print!(" {quic}");
3428
}
3529
println!();
30+
print!("Memory Allocator: ");
31+
cfg_if::cfg_if!(
32+
if #[cfg(feature = "jemalloc")] {
33+
if let Some(version) = vey_jemalloc::lib_version() {
34+
println!("jemalloc {}", version.to_string_lossy());
35+
}
36+
} else if #[cfg(feature = "mimalloc")] {
37+
println!("mimalloc {}", vey_mimalloc::lib_version());
38+
} else {
39+
println!("system");
40+
}
41+
);
3642
if let Some(variant) = vey_openssl::variant_name() {
3743
println!("OpenSSL Variant: {variant}");
3844
}

vey-gateway/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ use vey_daemon::control::{QuitAction, UpgradeAction};
1111

1212
use vey_gateway::opts::ProcArgs;
1313

14-
#[cfg(feature = "jemalloc")]
15-
#[global_allocator]
16-
static GLOBAL: vey_jemalloc::Jemalloc = vey_jemalloc::Jemalloc;
17-
18-
#[cfg(feature = "mimalloc")]
19-
#[global_allocator]
20-
static GLOBAL: vey_mimalloc::Mimalloc = vey_mimalloc::Mimalloc;
14+
cfg_if::cfg_if! {
15+
if #[cfg(feature="jemalloc")] {
16+
#[global_allocator]
17+
static GLOBAL: vey_jemalloc::Jemalloc = vey_jemalloc::Jemalloc;
18+
} else if #[cfg(feature="mimalloc")] {
19+
#[global_allocator]
20+
static GLOBAL: vey_mimalloc::Mimalloc = vey_mimalloc::Mimalloc;
21+
}
22+
}
2123

2224
fn main() -> anyhow::Result<()> {
2325
#[cfg(feature = "openssl-probe")]

0 commit comments

Comments
 (0)