Skip to content

Commit

Permalink
Merge pull request #229 from KSXGitHub/correct-block-size
Browse files Browse the repository at this point in the history
Change the measured quantities
  • Loading branch information
KSXGitHub authored Mar 10, 2023
2 parents 3abdb09 + 0572a38 commit ef89489
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 60 deletions.
32 changes: 16 additions & 16 deletions ci/github-actions/benchmark/matrix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getReleasedPduName } from './pdu-programs'

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

export const RELEASED_PDU_VERSIONS = [
'0.0.0',
'0.9.0',
] as const

export const ACCEPTABLE_PERFORMANCE_REGRESSION = 1.1 // 10%
Expand Down Expand Up @@ -90,8 +90,8 @@ export interface CompetingBenchmarkCategory {

export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] = [
{
id: 'len',
pduCliArgs: ['--quantity=len'],
id: 'apparent-size',
pduCliArgs: ['--quantity=apparent-size'],
competitors: [
['dust', '--apparent-size'],
['dua', '--apparent-size'],
Expand All @@ -101,8 +101,8 @@ export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] =
],
},
{
id: 'blksize',
pduCliArgs: ['--quantity=blksize'],
id: 'block-size',
pduCliArgs: ['--quantity=block-size'],
competitors: [
['dust'],
['dua'],
Expand All @@ -115,16 +115,16 @@ export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] =
id: 'top-down',
pduCliArgs: ['--top-down'],
competitors: [
['dust', '--apparent-size', '--reverse'],
['dust', '--reverse'],
],
},
{
id: 'summary',
pduCliArgs: ['--max-depth=1'],
competitors: [
['dutree', '--summary'],
['dua', '--apparent-size'],
['du', '--apparent-size', '--summarize'],
['dua'],
['du', '--summarize'],
],
},
{
Expand All @@ -140,28 +140,28 @@ export const COMPETING_BENCHMARK_MATRIX: readonly CompetingBenchmarkCategory[] =
id: 'no-sort',
pduCliArgs: ['--no-sort'],
competitors: [
['du', '--apparent-size'],
['dua', '--apparent-size'],
['du'],
['dua'],
['ncdu', '-o', '/dev/stdout', '-0'],
['gdu', '--show-apparent-size', '--non-interactive', '--no-progress'],
['gdu', '--non-interactive', '--no-progress'],
],
},
{
id: 'no-sort+summary',
pduCliArgs: ['--no-sort', '--max-depth=1'],
competitors: [
['dua', '--apparent-size'],
['dua'],
['ncdu', '-o', '/dev/null', '-0'],
['gdu', '--show-apparent-size', '--non-interactive', '--no-progress'],
['du', '--apparent-size', '--summarize'],
['gdu', '--non-interactive', '--no-progress'],
['du', '--summarize'],
],
},
{
id: 'progress',
pduCliArgs: ['--progress'],
competitors: [
['ncdu', '-o', '/dev/stdout', '-1'],
['gdu', '--show-apparent-size', '--non-interactive'],
['gdu', '--non-interactive'],
],
},
]
2 changes: 1 addition & 1 deletion exports/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _pdu() {
return 0
;;
--quantity)
COMPREPLY=($(compgen -W "len blksize blocks" -- "${cur}"))
COMPREPLY=($(compgen -W "apparent-size block-size block-count" -- "${cur}"))
return 0
;;
--max-depth)
Expand Down
2 changes: 1 addition & 1 deletion exports/completion.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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}"
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}"
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}"
complete -c pdu -l max-depth -d 'Maximum depth to display the data (must be greater than 0)' -r
complete -c pdu -l total-width -d 'Width of the visualization' -r
complete -c pdu -l column-width -d 'Maximum widths of the tree column and width of the bar column' -r
Expand Down
6 changes: 3 additions & 3 deletions exports/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ _pdu() {
'--bytes-format=[How to display the numbers of bytes]:BYTES_FORMAT:((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"))' \
'--quantity=[Aspect of the files/directories to be measured]:QUANTITY:((len\:"Measure apparent sizes"
blksize\:"Measure blksize"
blocks\:"Count number of blocks"))' \
'--quantity=[Aspect of the files/directories to be measured]:QUANTITY:((apparent-size\:"Measure apparent sizes"
block-size\:"Measure block sizes (block-count * 512B)"
block-count\:"Count numbers of blocks"))' \
'--max-depth=[Maximum depth to display the data (must be greater than 0)]:MAX_DEPTH: ' \
'(--column-width)--total-width=[Width of the visualization]:TOTAL_WIDTH: ' \
'*--column-width=[Maximum widths of the tree column and width of the bar column]:TREE_WIDTH: :TREE_WIDTH: ' \
Expand Down
8 changes: 4 additions & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use text_block_macros::text_block;
" $ pdu"
" $ pdu path/to/file/or/directory"
" $ pdu file.txt dir/"
" $ pdu --quantity=blksize"
" $ pdu --quantity=apparent-size"
" $ pdu --bytes-format=plain"
" $ pdu --bytes-format=binary"
" $ pdu --min-ratio=0"
Expand All @@ -49,8 +49,8 @@ use text_block_macros::text_block;
" Compare disk usages of multiple files and/or directories"
" $ pdu file.txt dir/"
""
" Show chart in block sizes instead of apparent sizes"
" $ pdu --quantity=blksize"
" Show chart in apparent sizes instead of block sizes"
" $ pdu --quantity=apparent-size"
""
" Show data in plain numbers instead of metric units"
" $ pdu --bytes-format=plain"
Expand Down Expand Up @@ -98,7 +98,7 @@ pub struct Args {
pub align_left: bool,

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

/// Maximum depth to display the data (must be greater than 0).
Expand Down
24 changes: 12 additions & 12 deletions src/args/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ use clap::ValueEnum;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "cli", derive(ValueEnum))]
pub enum Quantity {
/// Measure apparent sizes, equivalent to the
/// [len](std::fs::Metadata::len) method.
#[cfg_attr(feature = "cli", clap(name = "len", help = "Measure apparent sizes"))]
/// Measure apparent sizes.
ApparentSize,
/// Measure block sizes, equivalent to the
/// [blksize](std::os::unix::prelude::MetadataExt::blksize) method (POSIX only).
/// Measure block sizes (block-count * 512B).
#[cfg(unix)]
#[cfg_attr(feature = "cli", clap(name = "blksize", help = "Measure blksize"))]
BlockSize,
/// Count numbers of blocks, equivalent to the
/// [blocks](std::os::unix::prelude::MetadataExt::blocks) method (POSIX only).
/// Count numbers of blocks.
#[cfg(unix)]
#[cfg_attr(
feature = "cli",
clap(name = "blocks", help = "Count number of blocks")
)]
BlockCount,
}

impl Quantity {
/// Default value of the `--quantity` flag.
#[cfg(unix)]
pub(crate) const DEFAULT: Self = Quantity::BlockSize;
/// Default value of the `--quantity` flag.
#[cfg(not(unix))]
pub(crate) const DEFAULT: Self = Quantity::ApparentSize;
}
4 changes: 2 additions & 2 deletions src/size_getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::os::unix::prelude::MetadataExt;
pub type SizeGetter<Size> = fn(&Metadata) -> Size;
/// Returns [`metadata.len()`](Metadata::len).
pub const GET_APPARENT_SIZE: SizeGetter<Bytes> = |metadata| metadata.len().into();
/// Returns [`metadata.blksize()`](Metadata::blksize) (POSIX only).
/// Returns [`metadata.blocks() * 512`](Metadata::blksize) (POSIX only).
#[cfg(unix)]
pub const GET_BLOCK_SIZE: SizeGetter<Bytes> = |metadata| metadata.blksize().into();
pub const GET_BLOCK_SIZE: SizeGetter<Bytes> = |metadata| (metadata.blocks() * 512).into();
/// Returns [`metadata.blocks()`](Metadata::blocks) (POSIX only).
#[cfg(unix)]
pub const GET_BLOCK_COUNT: SizeGetter<Blocks> = |metadata| metadata.blocks().into();
10 changes: 9 additions & 1 deletion tests/_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use parallel_disk_usage::{
fs_tree_builder::FsTreeBuilder,
os_string_display::OsStringDisplay,
reporter::ErrorOnlyReporter,
size::Size,
size::{Bytes, Size},
size_getters::{self, SizeGetter},
};
use pipe_trait::Pipe;
use pretty_assertions::assert_eq;
Expand All @@ -20,6 +21,13 @@ use std::{
process::{Command, Output},
};

/// Default size getter method.
#[cfg(unix)]
pub const DEFAULT_GET_SIZE: SizeGetter<Bytes> = size_getters::GET_BLOCK_SIZE;
/// Default size getter method.
#[cfg(not(unix))]
pub const DEFAULT_GET_SIZE: SizeGetter<Bytes> = size_getters::GET_APPARENT_SIZE;

/// Representation of a temporary filesystem item.
///
/// **NOTE:** Delete this once https://github.com/samgiles/rs-mktemp/issues/8 is resolved.
Expand Down
1 change: 1 addition & 0 deletions tests/cli_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fn fs_errors() {
.with_current_dir(workspace.as_path())
.with_arg("--min-ratio=0")
.with_arg("--total-width=100")
.with_arg("--quantity=apparent-size")
.pipe(stdio)
.output()
.expect("spawn command");
Expand Down
4 changes: 2 additions & 2 deletions tests/flag_combinations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use std::process::Stdio;
#[test]
fn flag_combinations() {
#[cfg(unix)]
let quantity = ["len", "blksize", "blocks"];
let quantity = ["apparent-size", "block-size", "block-count"];
#[cfg(windows)]
let quantity = ["len"];
let quantity = ["apparent-size"];

let list = CommandList::default()
.option_matrix("--quantity", quantity)
Expand Down
4 changes: 2 additions & 2 deletions tests/fs_tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn len_as_bytes() {

#[cfg(unix)]
#[test]
fn blksize_as_bytes() {
fn blocks_as_bytes() {
let workspace = SampleWorkspace::default();
test_sample_tree::<Bytes, _>(&workspace, |metadata| metadata.blksize());
test_sample_tree::<Bytes, _>(&workspace, |metadata| metadata.blocks() * 512);
}

#[cfg(unix)]
Expand Down
5 changes: 3 additions & 2 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn json_output() {
let actual = Command::new(PDU)
.with_current_dir(workspace.as_path())
.with_arg("--json-output")
.with_arg("--quantity=len")
.with_arg("--quantity=apparent-size")
.with_arg("--min-ratio=0")
.with_arg(workspace.as_path())
.with_stdin(Stdio::null())
Expand Down Expand Up @@ -149,7 +149,7 @@ fn json_output_json_input() {
let json_output = Command::new(PDU)
.with_current_dir(workspace.as_path())
.with_arg("--json-output")
.with_arg("--quantity=len")
.with_arg("--quantity=apparent-size")
.with_arg(workspace.as_path())
.with_stdin(Stdio::null())
.with_stdout(Stdio::piped())
Expand Down Expand Up @@ -180,6 +180,7 @@ fn json_output_json_input() {
.with_arg("--bytes-format=metric")
.with_arg("--total-width=100")
.with_arg("--max-depth=10")
.with_arg("--quantity=apparent-size")
.with_arg(workspace.as_path())
.with_stdin(Stdio::piped())
.with_stdout(Stdio::piped())
Expand Down
Loading

0 comments on commit ef89489

Please sign in to comment.