Skip to content

Commit ef89489

Browse files
authored
Merge pull request #229 from KSXGitHub/correct-block-size
Change the measured quantities
2 parents 3abdb09 + 0572a38 commit ef89489

13 files changed

+75
-60
lines changed

ci/github-actions/benchmark/matrix.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getReleasedPduName } from './pdu-programs'
22

3-
export const QUANTITY = ['len', 'blksize', 'blocks'] as const
3+
export const QUANTITY = ['apparent-size', 'block-size', 'block-count'] as const
44
export const MAX_DEPTH = ['1', '10'] as const
55
export const MIN_RATIO = ['0.01', '0'] as const
66
export const PROGRESS = [false, true] as const
@@ -39,7 +39,7 @@ export function parseSelfBenchmarkCategory(category: SelfBenchmarkCategory) {
3939
}
4040

4141
export const RELEASED_PDU_VERSIONS = [
42-
'0.0.0',
42+
'0.9.0',
4343
] as const
4444

4545
export const ACCEPTABLE_PERFORMANCE_REGRESSION = 1.1 // 10%
@@ -90,8 +90,8 @@ export interface CompetingBenchmarkCategory {
9090

9191
export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] = [
9292
{
93-
id: 'len',
94-
pduCliArgs: ['--quantity=len'],
93+
id: 'apparent-size',
94+
pduCliArgs: ['--quantity=apparent-size'],
9595
competitors: [
9696
['dust', '--apparent-size'],
9797
['dua', '--apparent-size'],
@@ -101,8 +101,8 @@ export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] =
101101
],
102102
},
103103
{
104-
id: 'blksize',
105-
pduCliArgs: ['--quantity=blksize'],
104+
id: 'block-size',
105+
pduCliArgs: ['--quantity=block-size'],
106106
competitors: [
107107
['dust'],
108108
['dua'],
@@ -115,16 +115,16 @@ export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] =
115115
id: 'top-down',
116116
pduCliArgs: ['--top-down'],
117117
competitors: [
118-
['dust', '--apparent-size', '--reverse'],
118+
['dust', '--reverse'],
119119
],
120120
},
121121
{
122122
id: 'summary',
123123
pduCliArgs: ['--max-depth=1'],
124124
competitors: [
125125
['dutree', '--summary'],
126-
['dua', '--apparent-size'],
127-
['du', '--apparent-size', '--summarize'],
126+
['dua'],
127+
['du', '--summarize'],
128128
],
129129
},
130130
{
@@ -140,28 +140,28 @@ export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] =
140140
id: 'no-sort',
141141
pduCliArgs: ['--no-sort'],
142142
competitors: [
143-
['du', '--apparent-size'],
144-
['dua', '--apparent-size'],
143+
['du'],
144+
['dua'],
145145
['ncdu', '-o', '/dev/stdout', '-0'],
146-
['gdu', '--show-apparent-size', '--non-interactive', '--no-progress'],
146+
['gdu', '--non-interactive', '--no-progress'],
147147
],
148148
},
149149
{
150150
id: 'no-sort+summary',
151151
pduCliArgs: ['--no-sort', '--max-depth=1'],
152152
competitors: [
153-
['dua', '--apparent-size'],
153+
['dua'],
154154
['ncdu', '-o', '/dev/null', '-0'],
155-
['gdu', '--show-apparent-size', '--non-interactive', '--no-progress'],
156-
['du', '--apparent-size', '--summarize'],
155+
['gdu', '--non-interactive', '--no-progress'],
156+
['du', '--summarize'],
157157
],
158158
},
159159
{
160160
id: 'progress',
161161
pduCliArgs: ['--progress'],
162162
competitors: [
163163
['ncdu', '-o', '/dev/stdout', '-1'],
164-
['gdu', '--show-apparent-size', '--non-interactive'],
164+
['gdu', '--non-interactive'],
165165
],
166166
},
167167
]

exports/completion.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _pdu() {
3030
return 0
3131
;;
3232
--quantity)
33-
COMPREPLY=($(compgen -W "len blksize blocks" -- "${cur}"))
33+
COMPREPLY=($(compgen -W "apparent-size block-size block-count" -- "${cur}"))
3434
return 0
3535
;;
3636
--max-depth)

exports/completion.fish

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
complete -c pdu -l bytes-format -d 'How to display the numbers of bytes' -r -f -a "{plain Display plain number of bytes without units,metric Use metric scale\, i.e. 1K = 1000B\, 1M = 1000K\, and so on,binary Use binary scale\, i.e. 1K = 1024B\, 1M = 1024K\, and so on}"
2-
complete -c pdu -l quantity -d 'Aspect of the files/directories to be measured' -r -f -a "{len Measure apparent sizes,blksize Measure blksize,blocks Count number of blocks}"
2+
complete -c pdu -l quantity -d 'Aspect of the files/directories to be measured' -r -f -a "{apparent-size Measure apparent sizes,block-size Measure block sizes (block-count * 512B),block-count Count numbers of blocks}"
33
complete -c pdu -l max-depth -d 'Maximum depth to display the data (must be greater than 0)' -r
44
complete -c pdu -l total-width -d 'Width of the visualization' -r
55
complete -c pdu -l column-width -d 'Maximum widths of the tree column and width of the bar column' -r

exports/completion.zsh

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ _pdu() {
1818
'--bytes-format=[How to display the numbers of bytes]:BYTES_FORMAT:((plain\:"Display plain number of bytes without units"
1919
metric\:"Use metric scale, i.e. 1K = 1000B, 1M = 1000K, and so on"
2020
binary\:"Use binary scale, i.e. 1K = 1024B, 1M = 1024K, and so on"))' \
21-
'--quantity=[Aspect of the files/directories to be measured]:QUANTITY:((len\:"Measure apparent sizes"
22-
blksize\:"Measure blksize"
23-
blocks\:"Count number of blocks"))' \
21+
'--quantity=[Aspect of the files/directories to be measured]:QUANTITY:((apparent-size\:"Measure apparent sizes"
22+
block-size\:"Measure block sizes (block-count * 512B)"
23+
block-count\:"Count numbers of blocks"))' \
2424
'--max-depth=[Maximum depth to display the data (must be greater than 0)]:MAX_DEPTH: ' \
2525
'(--column-width)--total-width=[Width of the visualization]:TOTAL_WIDTH: ' \
2626
'*--column-width=[Maximum widths of the tree column and width of the bar column]:TREE_WIDTH: :TREE_WIDTH: ' \

src/args.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use text_block_macros::text_block;
2929
" $ pdu"
3030
" $ pdu path/to/file/or/directory"
3131
" $ pdu file.txt dir/"
32-
" $ pdu --quantity=blksize"
32+
" $ pdu --quantity=apparent-size"
3333
" $ pdu --bytes-format=plain"
3434
" $ pdu --bytes-format=binary"
3535
" $ pdu --min-ratio=0"
@@ -49,8 +49,8 @@ use text_block_macros::text_block;
4949
" Compare disk usages of multiple files and/or directories"
5050
" $ pdu file.txt dir/"
5151
""
52-
" Show chart in block sizes instead of apparent sizes"
53-
" $ pdu --quantity=blksize"
52+
" Show chart in apparent sizes instead of block sizes"
53+
" $ pdu --quantity=apparent-size"
5454
""
5555
" Show data in plain numbers instead of metric units"
5656
" $ pdu --bytes-format=plain"
@@ -98,7 +98,7 @@ pub struct Args {
9898
pub align_left: bool,
9999

100100
/// Aspect of the files/directories to be measured.
101-
#[clap(long, value_enum, default_value_t = Quantity::ApparentSize)]
101+
#[clap(long, value_enum, default_value_t = Quantity::DEFAULT)]
102102
pub quantity: Quantity,
103103

104104
/// Maximum depth to display the data (must be greater than 0).

src/args/quantity.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ use clap::ValueEnum;
55
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66
#[cfg_attr(feature = "cli", derive(ValueEnum))]
77
pub enum Quantity {
8-
/// Measure apparent sizes, equivalent to the
9-
/// [len](std::fs::Metadata::len) method.
10-
#[cfg_attr(feature = "cli", clap(name = "len", help = "Measure apparent sizes"))]
8+
/// Measure apparent sizes.
119
ApparentSize,
12-
/// Measure block sizes, equivalent to the
13-
/// [blksize](std::os::unix::prelude::MetadataExt::blksize) method (POSIX only).
10+
/// Measure block sizes (block-count * 512B).
1411
#[cfg(unix)]
15-
#[cfg_attr(feature = "cli", clap(name = "blksize", help = "Measure blksize"))]
1612
BlockSize,
17-
/// Count numbers of blocks, equivalent to the
18-
/// [blocks](std::os::unix::prelude::MetadataExt::blocks) method (POSIX only).
13+
/// Count numbers of blocks.
1914
#[cfg(unix)]
20-
#[cfg_attr(
21-
feature = "cli",
22-
clap(name = "blocks", help = "Count number of blocks")
23-
)]
2415
BlockCount,
2516
}
17+
18+
impl Quantity {
19+
/// Default value of the `--quantity` flag.
20+
#[cfg(unix)]
21+
pub(crate) const DEFAULT: Self = Quantity::BlockSize;
22+
/// Default value of the `--quantity` flag.
23+
#[cfg(not(unix))]
24+
pub(crate) const DEFAULT: Self = Quantity::ApparentSize;
25+
}

src/size_getters.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use std::os::unix::prelude::MetadataExt;
1010
pub type SizeGetter<Size> = fn(&Metadata) -> Size;
1111
/// Returns [`metadata.len()`](Metadata::len).
1212
pub const GET_APPARENT_SIZE: SizeGetter<Bytes> = |metadata| metadata.len().into();
13-
/// Returns [`metadata.blksize()`](Metadata::blksize) (POSIX only).
13+
/// Returns [`metadata.blocks() * 512`](Metadata::blksize) (POSIX only).
1414
#[cfg(unix)]
15-
pub const GET_BLOCK_SIZE: SizeGetter<Bytes> = |metadata| metadata.blksize().into();
15+
pub const GET_BLOCK_SIZE: SizeGetter<Bytes> = |metadata| (metadata.blocks() * 512).into();
1616
/// Returns [`metadata.blocks()`](Metadata::blocks) (POSIX only).
1717
#[cfg(unix)]
1818
pub const GET_BLOCK_COUNT: SizeGetter<Blocks> = |metadata| metadata.blocks().into();

tests/_utils.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use parallel_disk_usage::{
66
fs_tree_builder::FsTreeBuilder,
77
os_string_display::OsStringDisplay,
88
reporter::ErrorOnlyReporter,
9-
size::Size,
9+
size::{Bytes, Size},
10+
size_getters::{self, SizeGetter},
1011
};
1112
use pipe_trait::Pipe;
1213
use pretty_assertions::assert_eq;
@@ -20,6 +21,13 @@ use std::{
2021
process::{Command, Output},
2122
};
2223

24+
/// Default size getter method.
25+
#[cfg(unix)]
26+
pub const DEFAULT_GET_SIZE: SizeGetter<Bytes> = size_getters::GET_BLOCK_SIZE;
27+
/// Default size getter method.
28+
#[cfg(not(unix))]
29+
pub const DEFAULT_GET_SIZE: SizeGetter<Bytes> = size_getters::GET_APPARENT_SIZE;
30+
2331
/// Representation of a temporary filesystem item.
2432
///
2533
/// **NOTE:** Delete this once https://github.com/samgiles/rs-mktemp/issues/8 is resolved.

tests/cli_errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn fs_errors() {
119119
.with_current_dir(workspace.as_path())
120120
.with_arg("--min-ratio=0")
121121
.with_arg("--total-width=100")
122+
.with_arg("--quantity=apparent-size")
122123
.pipe(stdio)
123124
.output()
124125
.expect("spawn command");

tests/flag_combinations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use std::process::Stdio;
1212
#[test]
1313
fn flag_combinations() {
1414
#[cfg(unix)]
15-
let quantity = ["len", "blksize", "blocks"];
15+
let quantity = ["apparent-size", "block-size", "block-count"];
1616
#[cfg(windows)]
17-
let quantity = ["len"];
17+
let quantity = ["apparent-size"];
1818

1919
let list = CommandList::default()
2020
.option_matrix("--quantity", quantity)

tests/fs_tree_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ fn len_as_bytes() {
1616

1717
#[cfg(unix)]
1818
#[test]
19-
fn blksize_as_bytes() {
19+
fn blocks_as_bytes() {
2020
let workspace = SampleWorkspace::default();
21-
test_sample_tree::<Bytes, _>(&workspace, |metadata| metadata.blksize());
21+
test_sample_tree::<Bytes, _>(&workspace, |metadata| metadata.blocks() * 512);
2222
}
2323

2424
#[cfg(unix)]

tests/json.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn json_output() {
6262
let actual = Command::new(PDU)
6363
.with_current_dir(workspace.as_path())
6464
.with_arg("--json-output")
65-
.with_arg("--quantity=len")
65+
.with_arg("--quantity=apparent-size")
6666
.with_arg("--min-ratio=0")
6767
.with_arg(workspace.as_path())
6868
.with_stdin(Stdio::null())
@@ -149,7 +149,7 @@ fn json_output_json_input() {
149149
let json_output = Command::new(PDU)
150150
.with_current_dir(workspace.as_path())
151151
.with_arg("--json-output")
152-
.with_arg("--quantity=len")
152+
.with_arg("--quantity=apparent-size")
153153
.with_arg(workspace.as_path())
154154
.with_stdin(Stdio::null())
155155
.with_stdout(Stdio::piped())
@@ -180,6 +180,7 @@ fn json_output_json_input() {
180180
.with_arg("--bytes-format=metric")
181181
.with_arg("--total-width=100")
182182
.with_arg("--max-depth=10")
183+
.with_arg("--quantity=apparent-size")
183184
.with_arg(workspace.as_path())
184185
.with_stdin(Stdio::piped())
185186
.with_stdout(Stdio::piped())

0 commit comments

Comments
 (0)