Add --export-block-size option + minor man page adjustments

This commit is contained in:
Yorhel 2024-11-15 11:08:26 +01:00
parent 7ed209a8e5
commit 9d51df02c1
3 changed files with 35 additions and 8 deletions

34
ncdu.1
View file

@ -23,6 +23,7 @@
.Op Fl t , \-threads Ar num .Op Fl t , \-threads Ar num
.Op Fl c , \-compress , \-no\-compress .Op Fl c , \-compress , \-no\-compress
.Op Fl \-compress\-level Ar num .Op Fl \-compress\-level Ar num
.Op Fl \-export\-block\-size Ar num
.Op Fl 0 , 1 , 2 .Op Fl 0 , 1 , 2
.Op Fl q , \-slow\-ui\-updates , \-fast\-ui\-updates .Op Fl q , \-slow\-ui\-updates , \-fast\-ui\-updates
.Op Fl \-enable\-shell , \-disable\-shell .Op Fl \-enable\-shell , \-disable\-shell
@ -193,9 +194,18 @@ The binary format (see
.Fl O ) .Fl O )
does not have this problem and supports efficient exporting with any number of does not have this problem and supports efficient exporting with any number of
threads. threads.
.El
.
.Ss Export Options
These options affect behavior when exporting to file with the
.Fl o
or
.Fl O
options.
.Bl -tag -width Ds
.It Fl c , \-compress , \-no\-compress .It Fl c , \-compress , \-no\-compress
Enable or disable Zstandard compression when exporting to JSON (see Enable or disable Zstandard compression when exporting to JSON (see
.Fl o ) .Fl o ) .
.It Fl \-compress\-level Ar num .It Fl \-compress\-level Ar num
Set the Zstandard compression level when using Set the Zstandard compression level when using
.Fl O .Fl O
@ -203,6 +213,17 @@ or
.Fl c . .Fl c .
Valid values are 1 (fastest) to 19 (slowest). Valid values are 1 (fastest) to 19 (slowest).
Defaults to 4. Defaults to 4.
.It Fl \-export\-block\-size Ar num
Set the block size, in kibibytes, for the binary export format (see
.Fl O ) .
Larger blocks require more memory but result in better compression efficiency.
This option can be combined with a higher
.Fl \-compress\-level
for even better compression.
.Pp
Accepted values are between 4 and 16000.
The defaults is to start at 64 KiB and then gradually increase the block size
for large exports.
.El .El
. .
.Ss Interface Options .Ss Interface Options
@ -497,29 +518,28 @@ Empty directory.
.Sh EXAMPLES .Sh EXAMPLES
To scan and browse the directory you're currently in, all you need is a simple: To scan and browse the directory you're currently in, all you need is a simple:
.Dl ncdu .Dl ncdu
If you want to scan a full filesystem, for example your root filesystem, then To scan a full filesystem, for example your root filesystem, you'll want to use
you'll want to use
.Fl x : .Fl x :
.Dl ncdu \-x / .Dl ncdu \-x /
.Pp .Pp
Since scanning a large directory may take a while, you can scan a directory and Since scanning a large directory may take a while, you can scan a directory and
export the results for later viewing: export the results for later viewing:
.Bd -literal -offset indent .Bd -literal -offset indent
ncdu \-1cxo export.json.zst / ncdu \-1xO export.ncdu /
# ...some time later: # ...some time later:
ncdu \-f export.json.zst ncdu \-f export.ncdu
.Ed .Ed
To export from a cron job, make sure to replace To export from a cron job, make sure to replace
.Fl 1 .Fl 1
with with
.Fl 0 .Fl 0
to suppress any unnecessary output. to suppress unnecessary progress output.
.Pp .Pp
You can also export a directory and browse it once scanning is done: You can also export a directory and browse it once scanning is done:
.Dl ncdu \-co\- | tee export.json.zst | ./ncdu \-f\- .Dl ncdu \-co\- | tee export.json.zst | ./ncdu \-f\-
.Pp .Pp
To scan a system remotely, but browse through the files locally: To scan a system remotely, but browse through the files locally:
.Dl ssh user@system ncdu \-co\- / | ./ncdu \-cf\- .Dl ssh user@system ncdu \-co\- / | ./ncdu \-f\-
Remote scanning and local viewing has two major advantages when Remote scanning and local viewing has two major advantages when
compared to running compared to running
.Nm .Nm

View file

@ -72,7 +72,8 @@ inline fn cborByte(major: CborMajor, arg: u5) u8 { return (@as(u8, @intFromEnum(
fn blockSize(num: u32) usize { fn blockSize(num: u32) usize {
// block size uncompressed data in this num range // block size uncompressed data in this num range
// # mil # KiB # GiB // # mil # KiB # GiB
return if (num < ( 1<<20)) 64<<10 // 64 return main.config.export_block_size
orelse if (num < ( 1<<20)) 64<<10 // 64
else if (num < ( 2<<20)) 128<<10 // 128 else if (num < ( 2<<20)) 128<<10 // 128
else if (num < ( 4<<20)) 256<<10 // 512 else if (num < ( 4<<20)) 256<<10 // 512
else if (num < ( 8<<20)) 512<<10 // 2048 else if (num < ( 8<<20)) 512<<10 // 2048

View file

@ -82,6 +82,7 @@ pub const config = struct {
pub var threads: usize = 1; pub var threads: usize = 1;
pub var complevel: u8 = 4; pub var complevel: u8 = 4;
pub var compress: bool = false; pub var compress: bool = false;
pub var export_block_size: ?usize = null;
pub var update_delay: u64 = 100*std.time.ns_per_ms; pub var update_delay: u64 = 100*std.time.ns_per_ms;
pub var scan_ui: ?enum { none, line, full } = null; pub var scan_ui: ?enum { none, line, full } = null;
@ -283,6 +284,11 @@ fn argConfig(args: *Args, opt: Args.Option) bool {
const val = args.arg(); const val = args.arg();
config.complevel = std.fmt.parseInt(u8, val, 10) catch ui.die("Invalid number for --compress-level: {s}.\n", .{val}); config.complevel = std.fmt.parseInt(u8, val, 10) catch ui.die("Invalid number for --compress-level: {s}.\n", .{val});
if (config.complevel <= 0 or config.complevel > 20) ui.die("Invalid number for --compress-level: {s}.\n", .{val}); if (config.complevel <= 0 or config.complevel > 20) ui.die("Invalid number for --compress-level: {s}.\n", .{val});
} else if (opt.is("--export-block-size")) {
const val = args.arg();
const num = std.fmt.parseInt(u14, val, 10) catch ui.die("Invalid number for --export-block-size: {s}.\n", .{val});
if (num < 4 or num > 16000) ui.die("Invalid number for --export-block-size: {s}.\n", .{val});
config.export_block_size = @as(usize, num) * 1024;
} else if (opt.is("--confirm-quit")) config.confirm_quit = true } else if (opt.is("--confirm-quit")) config.confirm_quit = true
else if (opt.is("--no-confirm-quit")) config.confirm_quit = false else if (opt.is("--no-confirm-quit")) config.confirm_quit = false
else if (opt.is("--confirm-delete")) config.confirm_delete = true else if (opt.is("--confirm-delete")) config.confirm_delete = true