user: replace third-party humansize
This commit is contained in:
parent
6abea7ef22
commit
d910e8c1a0
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1357,6 +1357,10 @@ dependencies = [
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libutil"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "libyalloc"
|
||||
version = "0.1.0"
|
||||
|
@ -17,7 +17,8 @@ members = [
|
||||
"lib/libyalloc",
|
||||
"lib/runtime",
|
||||
"lib/qemu",
|
||||
"lib/abi-serde"
|
||||
"lib/abi-serde",
|
||||
"lib/libutil"
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
|
15
userspace/Cargo.lock
generated
15
userspace/Cargo.lock
generated
@ -1053,15 +1053,6 @@ dependencies = [
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humansize"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
|
||||
dependencies = [
|
||||
"libm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
@ -1371,6 +1362,10 @@ dependencies = [
|
||||
"yggdrasil-rt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libutil"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
@ -2654,9 +2649,9 @@ dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"cross",
|
||||
"humansize",
|
||||
"init",
|
||||
"libterm",
|
||||
"libutil",
|
||||
"log",
|
||||
"logsink",
|
||||
"pci-ids",
|
||||
|
@ -19,8 +19,9 @@ members = [
|
||||
"crypt",
|
||||
"lib/runtime",
|
||||
"lib/uipc",
|
||||
"lib/logsink"
|
||||
, "lib/libpsf"]
|
||||
"lib/logsink",
|
||||
"lib/libpsf"
|
||||
]
|
||||
exclude = ["dynload-program", "test-kernel-module", "lib/ygglibc"]
|
||||
|
||||
[workspace.dependencies]
|
||||
@ -57,6 +58,7 @@ yggdrasil-rt.path = "../lib/runtime"
|
||||
yggdrasil-abi = { path = "../lib/abi", features = ["serde", "alloc", "bytemuck"] }
|
||||
abi-serde = { path = "../lib/abi-serde" }
|
||||
logsink.path = "lib/logsink"
|
||||
libutil.path = "../lib/libutil"
|
||||
|
||||
[workspace.lints.rust]
|
||||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(rust_analyzer)'] }
|
||||
|
@ -12,6 +12,7 @@ yggdrasil-abi.workspace = true
|
||||
yggdrasil-rt.workspace = true
|
||||
cross.workspace = true
|
||||
logsink.workspace = true
|
||||
libutil.workspace = true
|
||||
|
||||
log.workspace = true
|
||||
rand.workspace = true
|
||||
@ -22,8 +23,6 @@ serde_json.workspace = true
|
||||
sha2.workspace = true
|
||||
chrono.workspace = true
|
||||
|
||||
# TODO own impl
|
||||
humansize = { version = "2.1.3", features = ["impl_style"] }
|
||||
pci-ids = { version = "0.2.5" }
|
||||
|
||||
init = { path = "../init" }
|
||||
|
@ -5,6 +5,7 @@ use std::{
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use libutil::fmt::FormatSize;
|
||||
use sysutils::{Input, Output};
|
||||
|
||||
#[derive(Parser)]
|
||||
@ -67,10 +68,10 @@ fn dump_block(offset: u64, data: &[u8]) {
|
||||
}
|
||||
|
||||
fn print_throughput(duration: Duration, bytes_read: usize) {
|
||||
let read_total = humansize::format_size(bytes_read as u64, humansize::FormatSizeOptions::default());
|
||||
let ms = duration.as_millis() as u64;
|
||||
let read_per_ms = bytes_read as u64 / ms;
|
||||
let read_speed = humansize::format_size(read_per_ms * 1000, humansize::FormatSizeOptions::default());
|
||||
let read_total = FormatSize::default(bytes_read as u64);
|
||||
let read_speed = FormatSize::default(read_per_ms * 1000);
|
||||
|
||||
eprintln!("{read_speed}/s ({read_total} in {duration:?})");
|
||||
}
|
||||
|
@ -2,7 +2,14 @@
|
||||
#![feature(let_chains, decl_macro)]
|
||||
|
||||
use std::{
|
||||
cmp::Ordering, ffi::OsString, fmt, fs::{read_dir, FileType, Metadata}, io, path::{Path, PathBuf}, process::ExitCode, time::SystemTime
|
||||
cmp::Ordering,
|
||||
ffi::OsString,
|
||||
fmt,
|
||||
fs::{read_dir, FileType, Metadata},
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
process::ExitCode,
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
@ -12,7 +19,7 @@ use std::os::yggdrasil::fs::MetadataExt;
|
||||
|
||||
use chrono::{Datelike, Timelike};
|
||||
use clap::Parser;
|
||||
use humansize::{FormatSize, BINARY};
|
||||
use libutil::fmt::FormatSize;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(disable_help_flag = true)]
|
||||
@ -60,7 +67,7 @@ trait MetadataImpl {
|
||||
impl DisplaySizeBit for u64 {
|
||||
fn display_size_bit(self, opts: &Args, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if opts.human_readable {
|
||||
fmt::Display::fmt(&self.format_size(BINARY), f)
|
||||
fmt::Display::fmt(&FormatSize::default(self), f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self, f)
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ use std::{
|
||||
fmt::Write
|
||||
};
|
||||
|
||||
use humansize::FormatSize;
|
||||
use libterm::{Clear, Term};
|
||||
use libutil::fmt::FormatSize;
|
||||
use yggdrasil_rt::system;
|
||||
|
||||
fn get_memory_stats() -> system::SystemMemoryStats {
|
||||
@ -50,12 +50,15 @@ fn main() {
|
||||
let free_bytes = stats.free_pages * stats.page_size;
|
||||
let total_usable_bytes = stats.total_usable_pages * stats.page_size;
|
||||
|
||||
let allocated_mem = FormatSize::default(allocated_bytes as u64);
|
||||
let free_mem = FormatSize::default(free_bytes as u64);
|
||||
let total_usable_mem = FormatSize::default(total_usable_bytes as u64);
|
||||
write!(
|
||||
term,
|
||||
"U: {} F: {} T: {} ({}%)",
|
||||
allocated_bytes.format_size(Default::default()),
|
||||
free_bytes.format_size(Default::default()),
|
||||
total_usable_bytes.format_size(Default::default()),
|
||||
allocated_mem,
|
||||
free_mem,
|
||||
total_usable_mem,
|
||||
100 * stats.allocated_pages / stats.total_usable_pages
|
||||
)
|
||||
.ok();
|
||||
|
Loading…
x
Reference in New Issue
Block a user