mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 17:14:21 +01:00
debug: add memory debug window
enable with: $ cargo build --release --features memory and then click the memory widget on the chrome sidepanel currently doesn't track C allocations... we should fix that Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
150
Cargo.lock
generated
150
Cargo.lock
generated
@@ -172,7 +172,7 @@ dependencies = [
|
|||||||
"objc2-foundation 0.3.1",
|
"objc2-foundation 0.3.1",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
"x11rb",
|
"x11rb",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1358,7 +1358,7 @@ version = "0.31.1"
|
|||||||
source = "git+https://github.com/damus-io/egui?rev=73a831ed43d3a8592611e2948b505add88d8aba2#73a831ed43d3a8592611e2948b505add88d8aba2"
|
source = "git+https://github.com/damus-io/egui?rev=73a831ed43d3a8592611e2948b505add88d8aba2#73a831ed43d3a8592611e2948b505add88d8aba2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"emath",
|
"emath 0.31.1 (git+https://github.com/damus-io/egui?rev=73a831ed43d3a8592611e2948b505add88d8aba2)",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1407,7 +1407,7 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
"emath",
|
"emath 0.31.1 (git+https://github.com/damus-io/egui?rev=73a831ed43d3a8592611e2948b505add88d8aba2)",
|
||||||
"epaint",
|
"epaint",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
@@ -1533,6 +1533,12 @@ version = "1.15.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "emath"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e4cadcff7a5353ba72b7fea76bf2122b5ebdbc68e8155aa56dfdea90083fe1b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "emath"
|
name = "emath"
|
||||||
version = "0.31.1"
|
version = "0.31.1"
|
||||||
@@ -1622,6 +1628,15 @@ dependencies = [
|
|||||||
"syn 2.0.103",
|
"syn 2.0.103",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_filter"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epaint"
|
name = "epaint"
|
||||||
version = "0.31.1"
|
version = "0.31.1"
|
||||||
@@ -1631,7 +1646,7 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"ecolor",
|
"ecolor",
|
||||||
"emath",
|
"emath 0.31.1 (git+https://github.com/damus-io/egui?rev=73a831ed43d3a8592611e2948b505add88d8aba2)",
|
||||||
"epaint_default_fonts",
|
"epaint_default_fonts",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
@@ -2625,6 +2640,15 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.15"
|
version = "1.0.15"
|
||||||
@@ -2855,6 +2879,15 @@ version = "0.4.27"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log-once"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d8a05e3879b317b1b6dbf353e5bba7062bedcc59815267bb23eaa0c576cebf0"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "loop9"
|
name = "loop9"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@@ -2928,6 +2961,16 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memory-stats"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c73f5c649995a115e1a0220b35e4df0a1294500477f97a91d0660fb5abeb574a"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "metal"
|
name = "metal"
|
||||||
version = "0.31.0"
|
version = "0.31.0"
|
||||||
@@ -3275,6 +3318,7 @@ dependencies = [
|
|||||||
"profiling",
|
"profiling",
|
||||||
"puffin",
|
"puffin",
|
||||||
"puffin_egui",
|
"puffin_egui",
|
||||||
|
"re_memory",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"strum",
|
"strum",
|
||||||
@@ -3386,6 +3430,15 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ntapi"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.46.0"
|
version = "0.46.0"
|
||||||
@@ -4426,6 +4479,60 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3b42e27ef78c35d3998403c1d26f3efd9e135d3e5121b0a4845cc5cc27547f4f"
|
checksum = "3b42e27ef78c35d3998403c1d26f3efd9e135d3e5121b0a4845cc5cc27547f4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "re_format"
|
||||||
|
version = "0.23.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2911aed8ef5b658871fc109072e056d77e8a8af9c438f9662ed5c88ac6850313"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "re_log"
|
||||||
|
version = "0.23.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1179e5409f57aebeedcea10d5cc4bea2bf5a9f237901501cb9a0e505ae06112f"
|
||||||
|
dependencies = [
|
||||||
|
"env_filter",
|
||||||
|
"log",
|
||||||
|
"log-once",
|
||||||
|
"parking_lot",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "re_memory"
|
||||||
|
version = "0.23.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ee6d1efd5f0478116ca816ee1689995c7878107fe0ee06b7aecee8cd454ce00"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"backtrace",
|
||||||
|
"emath 0.31.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"memory-stats",
|
||||||
|
"nohash-hasher",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot",
|
||||||
|
"re_format",
|
||||||
|
"re_log",
|
||||||
|
"re_tracing",
|
||||||
|
"smallvec",
|
||||||
|
"sysinfo",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"web-time 1.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "re_tracing"
|
||||||
|
version = "0.23.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41f4ddc0564f0ae8fbe75a5ade3c66c9ddecf51bfcdf6aa4fa8b9ccce695a8fc"
|
||||||
|
dependencies = [
|
||||||
|
"puffin",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -5252,6 +5359,20 @@ dependencies = [
|
|||||||
"syn 2.0.103",
|
"syn 2.0.103",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sysinfo"
|
||||||
|
version = "0.30.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
"ntapi",
|
||||||
|
"once_cell",
|
||||||
|
"windows 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "system-deps"
|
name = "system-deps"
|
||||||
version = "6.2.2"
|
version = "6.2.2"
|
||||||
@@ -6351,7 +6472,7 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
"windows",
|
"windows 0.58.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6409,6 +6530,16 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core 0.52.0",
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows"
|
name = "windows"
|
||||||
version = "0.58.0"
|
version = "0.58.0"
|
||||||
@@ -6419,6 +6550,15 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.58.0"
|
version = "0.58.0"
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ lightning-invoice = "0.33.1"
|
|||||||
secp256k1 = "0.30.0"
|
secp256k1 = "0.30.0"
|
||||||
hashbrown = "0.15.2"
|
hashbrown = "0.15.2"
|
||||||
openai-api-rs = "6.0.3"
|
openai-api-rs = "6.0.3"
|
||||||
|
re_memory = "0.23.4"
|
||||||
|
|
||||||
[profile.small]
|
[profile.small]
|
||||||
inherits = 'release'
|
inherits = 'release'
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ tracing-appender = { workspace = true }
|
|||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
profiling = { workspace = true }
|
profiling = { workspace = true }
|
||||||
|
re_memory = { workspace = true, optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
@@ -45,6 +46,7 @@ path = "src/notedeck.rs"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
memory = ["re_memory"]
|
||||||
puffin = ["profiling/profile-with-puffin", "dep:puffin"]
|
puffin = ["profiling/profile-with-puffin", "dep:puffin"]
|
||||||
debug-widget-callstack = ["egui/callstack"]
|
debug-widget-callstack = ["egui/callstack"]
|
||||||
debug-interactive-widgets = []
|
debug-interactive-widgets = []
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ pub struct Chrome {
|
|||||||
open: bool,
|
open: bool,
|
||||||
tab_selected: i32,
|
tab_selected: i32,
|
||||||
apps: Vec<NotedeckApp>,
|
apps: Vec<NotedeckApp>,
|
||||||
|
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
show_memory_debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Chrome {
|
impl Default for Chrome {
|
||||||
@@ -28,6 +31,9 @@ impl Default for Chrome {
|
|||||||
tab_selected: 0,
|
tab_selected: 0,
|
||||||
open: true,
|
open: true,
|
||||||
apps: vec![],
|
apps: vec![],
|
||||||
|
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
show_memory_debug: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +226,7 @@ impl Chrome {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ui.with_layout(Layout::bottom_up(egui::Align::Center), |ui| {
|
ui.with_layout(Layout::bottom_up(egui::Align::Center), |ui| {
|
||||||
if let Some(action) = bottomup_sidebar(app_ctx, ui) {
|
if let Some(action) = bottomup_sidebar(self, app_ctx, ui) {
|
||||||
got_action = Some(action);
|
got_action = Some(action);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -656,7 +662,11 @@ fn pfp_button(ctx: &mut AppContext, ui: &mut egui::Ui) -> egui::Response {
|
|||||||
|
|
||||||
/// The section of the chrome sidebar that starts at the
|
/// The section of the chrome sidebar that starts at the
|
||||||
/// bottom and goes up
|
/// bottom and goes up
|
||||||
fn bottomup_sidebar(ctx: &mut AppContext, ui: &mut egui::Ui) -> Option<ChromePanelAction> {
|
fn bottomup_sidebar(
|
||||||
|
_chrome: &mut Chrome,
|
||||||
|
ctx: &mut AppContext,
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
) -> Option<ChromePanelAction> {
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
|
|
||||||
let pfp_resp = pfp_button(ctx, ui);
|
let pfp_resp = pfp_button(ctx, ui);
|
||||||
@@ -701,6 +711,26 @@ fn bottomup_sidebar(ctx: &mut AppContext, ui: &mut egui::Ui) -> Option<ChromePan
|
|||||||
"{:10.1}",
|
"{:10.1}",
|
||||||
ctx.frame_history.mean_frame_time() * 1e3
|
ctx.frame_history.mean_frame_time() * 1e3
|
||||||
));
|
));
|
||||||
|
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
{
|
||||||
|
let mem_use = re_memory::MemoryUse::capture();
|
||||||
|
if let Some(counted) = mem_use.counted {
|
||||||
|
let memory_resp = ui.label(format!("{}", format_bytes(counted as f64)));
|
||||||
|
if memory_resp.clicked() {
|
||||||
|
_chrome.show_memory_debug = !_chrome.show_memory_debug;
|
||||||
|
} else if memory_resp.hovered() {
|
||||||
|
notedeck_ui::show_pointer(ui);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(resident) = mem_use.resident {
|
||||||
|
ui.weak(format!("{}", format_bytes(resident as f64)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if _chrome.show_memory_debug {
|
||||||
|
egui::Window::new("Memory Debug").show(ui.ctx(), memory_debug_ui);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pfp_resp.hovered()
|
if pfp_resp.hovered()
|
||||||
@@ -725,3 +755,100 @@ fn bottomup_sidebar(ctx: &mut AppContext, ui: &mut egui::Ui) -> Option<ChromePan
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
fn memory_debug_ui(ui: &mut egui::Ui) {
|
||||||
|
let Some(stats) = &re_memory::accounting_allocator::tracking_stats() else {
|
||||||
|
ui.label("re_memory::accounting_allocator::set_tracking_callstacks(true); not set!!");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
|
ui.label(format!(
|
||||||
|
"track_size_threshold {}",
|
||||||
|
stats.track_size_threshold
|
||||||
|
));
|
||||||
|
ui.label(format!(
|
||||||
|
"untracked {} {}",
|
||||||
|
stats.untracked.count,
|
||||||
|
format_bytes(stats.untracked.size as f64)
|
||||||
|
));
|
||||||
|
ui.label(format!(
|
||||||
|
"stochastically_tracked {} {}",
|
||||||
|
stats.stochastically_tracked.count,
|
||||||
|
format_bytes(stats.stochastically_tracked.size as f64),
|
||||||
|
));
|
||||||
|
ui.label(format!(
|
||||||
|
"fully_tracked {} {}",
|
||||||
|
stats.fully_tracked.count,
|
||||||
|
format_bytes(stats.fully_tracked.size as f64)
|
||||||
|
));
|
||||||
|
ui.label(format!(
|
||||||
|
"overhead {} {}",
|
||||||
|
stats.overhead.count,
|
||||||
|
format_bytes(stats.overhead.size as f64)
|
||||||
|
));
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
for (i, callstack) in stats.top_callstacks.iter().enumerate() {
|
||||||
|
let full_bt = format!("{}", callstack.readable_backtrace);
|
||||||
|
let mut lines = full_bt.lines().skip(5);
|
||||||
|
let bt_header = lines.nth(0).map_or("??", |v| v);
|
||||||
|
let header = format!(
|
||||||
|
"#{} {bt_header} {}x {}",
|
||||||
|
i + 1,
|
||||||
|
callstack.extant.count,
|
||||||
|
format_bytes(callstack.extant.size as f64)
|
||||||
|
);
|
||||||
|
|
||||||
|
egui::CollapsingHeader::new(header)
|
||||||
|
.id_salt(("mem_cs", i))
|
||||||
|
.show(ui, |ui| {
|
||||||
|
ui.label(lines.collect::<Vec<_>>().join("\n"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pretty format a number of bytes by using SI notation (base2), e.g.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use re_format::format_bytes;
|
||||||
|
/// assert_eq!(format_bytes(123.0), "123 B");
|
||||||
|
/// assert_eq!(format_bytes(12_345.0), "12.1 KiB");
|
||||||
|
/// assert_eq!(format_bytes(1_234_567.0), "1.2 MiB");
|
||||||
|
/// assert_eq!(format_bytes(123_456_789.0), "118 MiB");
|
||||||
|
/// ```
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
pub fn format_bytes(number_of_bytes: f64) -> String {
|
||||||
|
/// The minus character: <https://www.compart.com/en/unicode/U+2212>
|
||||||
|
/// Looks slightly different from the normal hyphen `-`.
|
||||||
|
const MINUS: char = '−';
|
||||||
|
|
||||||
|
if number_of_bytes < 0.0 {
|
||||||
|
format!("{MINUS}{}", format_bytes(-number_of_bytes))
|
||||||
|
} else if number_of_bytes == 0.0 {
|
||||||
|
"0 B".to_owned()
|
||||||
|
} else if number_of_bytes < 1.0 {
|
||||||
|
format!("{number_of_bytes} B")
|
||||||
|
} else if number_of_bytes < 20.0 {
|
||||||
|
let is_integer = number_of_bytes.round() == number_of_bytes;
|
||||||
|
if is_integer {
|
||||||
|
format!("{number_of_bytes:.0} B")
|
||||||
|
} else {
|
||||||
|
format!("{number_of_bytes:.1} B")
|
||||||
|
}
|
||||||
|
} else if number_of_bytes < 10.0_f64.exp2() {
|
||||||
|
format!("{number_of_bytes:.0} B")
|
||||||
|
} else if number_of_bytes < 20.0_f64.exp2() {
|
||||||
|
let decimals = (10.0 * number_of_bytes < 20.0_f64.exp2()) as usize;
|
||||||
|
format!("{:.*} KiB", decimals, number_of_bytes / 10.0_f64.exp2())
|
||||||
|
} else if number_of_bytes < 30.0_f64.exp2() {
|
||||||
|
let decimals = (10.0 * number_of_bytes < 30.0_f64.exp2()) as usize;
|
||||||
|
format!("{:.*} MiB", decimals, number_of_bytes / 20.0_f64.exp2())
|
||||||
|
} else {
|
||||||
|
let decimals = (10.0 * number_of_bytes < 40.0_f64.exp2()) as usize;
|
||||||
|
format!("{:.*} GiB", decimals, number_of_bytes / 30.0_f64.exp2())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
// hide console window on Windows in release
|
// hide console window on Windows in release
|
||||||
|
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
use re_memory::AccountingAllocator;
|
||||||
|
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: AccountingAllocator<std::alloc::System> =
|
||||||
|
AccountingAllocator::new(std::alloc::System);
|
||||||
|
|
||||||
use notedeck::{DataPath, DataPathType, Notedeck};
|
use notedeck::{DataPath, DataPathType, Notedeck};
|
||||||
use notedeck_chrome::{
|
use notedeck_chrome::{
|
||||||
setup::{generate_native_options, setup_chrome},
|
setup::{generate_native_options, setup_chrome},
|
||||||
@@ -66,6 +74,9 @@ fn setup_logging(path: &DataPath) -> Option<WorkerGuard> {
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
#[cfg(feature = "memory")]
|
||||||
|
re_memory::accounting_allocator::set_tracking_callstacks(true);
|
||||||
|
|
||||||
let base_path = DataPath::default_base_or_cwd();
|
let base_path = DataPath::default_base_or_cwd();
|
||||||
let path = DataPath::new(base_path.clone());
|
let path = DataPath::new(base_path.clone());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user