Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add human readable closure sizes to nix path-info #2373

Closed

Conversation

bhipple
Copy link
Contributor

@bhipple bhipple commented Aug 26, 2018

Unfortunately, -h is already taken as a short option by --help, so we have to
use a different letter or the capitalized version.

Resolves #2363

@bhipple bhipple force-pushed the feature/human-readable-closure-sizes branch from cc3654a to 09f9cec Compare August 26, 2018 01:12
@bhipple
Copy link
Contributor Author

bhipple commented Aug 26, 2018

Default behavior unchanged, both to maintain compatibility and to be consistent with default unix utility behavior:

λ brh nix →  /nix/store/v2j2pnqyb3pss9z56zai7rgsxgn5wxyw-nix-2.0.4/bin/nix path-info nixpkgs.nix -rsS | sort -nk3 
/nix/store/03wjkacvndsxhp540pgmsxhas8j610lc-libatomic_ops-7.6.0              691488          691488
/nix/store/d54amiggq6bw23jw6mdsgamvs6v1g3bh-glibc-2.25-123                 20761664        20761664
/nix/store/bqd0pk2ryvw0b47r7k23k13jx8ih2165-bzip2-1.0.6.0.1                   72880        20834544
/nix/store/ac082jcsg31763mbgiqlirhgsygimn1x-attr-2.4.47                       75792        20837456
/nix/store/dl66jvc19im9lqslzqszsp2gif2y0y8i-zlib-1.2.11                      104280        20865944
/nix/store/7hdn84ab02qar14qpy5l4z4diw726rb4-bzip2-1.0.6.0.1-bin               66056        20900600
/nix/store/93hb9j4n685dr698qq0j7ip0p2mss4lm-gzip-1.8                         149248        20910912
/nix/store/mcsl18halr6lx9b4d35ghrx71v7mw2k9-acl-2.2.52                        99936        20937392
/nix/store/ifka3vgvakgskl7wjvbaw3x71l2g7bil-nghttp2-1.20.0-lib               187984        20949648
/nix/store/y4p3gg22jjr223r2r681nmfdfvj245lk-xz-5.2.3                         328784        21090448
/nix/store/idgw2sgymddfbj6848mb0rdh3mprwj9f-libseccomp-2.3.2                 359872        21121536
/nix/store/10n172zhpxa1r77dqi6pn0qws4z546p0-libsodium-1.0.15                 406504        21168168
/nix/store/xjpzzdl3mh8v1wcbxrlgm2p9mnhlys6y-xz-5.2.3-bin                     152912        21243360
/nix/store/44pga8rb4ldvijrk853mxf4hqib089wn-sqlite-3.21.0                   1145400        21907064
/nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12                    1164032        21925696
/nix/store/0lyn8v4w3cd70hzg5md0xwhykhlbsq9f-gnutar-1.29                     2523184        23460576
/nix/store/34vrcmdwar08x75k3khr8q7j8klc70ww-openssl-1.0.2o                  3447192        24208856
/nix/store/5ik00dp38q9z8p84vs9svcpnlv6rg39v-libssh2-1.8.0                    211632        24524768
/nix/store/2z15ksqx06fkrxj246xh4ds10dnswsq7-curl-7.59.0                      586432        25299184
/nix/store/id8ljxy387l6d2ih59mwaaz894dmj9k2-perl-WWW-Curl-4.17               125400        25424584
/nix/store/bw39bnxgb52ayi60v409kdxdhvpcjh8s-curl-7.59.0-bin                  152200        25451384
/nix/store/dk0n769l985raba2nrya2q7ivspafj6f-gcc-6.4.0-lib                   5247776        26009440
/nix/store/agiyfa6fj25p52qshx9p4zwb4ks5kw0a-boehm-gc-7.6.0                   251056        26951984
/nix/store/4bh7qhnrjk8cgd1bh7nr0glbga0aasdx-coreutils-8.28                 10736280        31673672
/nix/store/i6xckn2cfmwry0rnyqpxf14xynghsnls-perl-5.24.3                    47095136        78768808
/nix/store/2zcmxrmfh24wz2p0k6qzi4fz6n8xi5xw-perl-DBI-1.636                  1730408        80499216
/nix/store/145q4xmmq9bx5gbczwjyqam52vz558h8-perl-DBD-SQLite-1.55_07          354352        81998968
/nix/store/xd6fvqpnrqd08k9ndi13pm5pcnxr83lv-openssl-1.0.2o-bin               648848        82864848
/nix/store/7c6lh9x8gamslzn4k1xsbcbp14b2v4nm-nix-1.11.16                     3109424       101986152

And with the new option (human sorted to boot!):

λ brh nix →  /nix/store/v2j2pnqyb3pss9z56zai7rgsxgn5wxyw-nix-2.0.4/bin/nix path-info nixpkgs.nix -rsSH | sort -hk3 
/nix/store/03wjkacvndsxhp540pgmsxhas8j610lc-libatomic_ops-7.6.0                 675K            675K
/nix/store/d54amiggq6bw23jw6mdsgamvs6v1g3bh-glibc-2.25-123                     19.8M           19.8M
/nix/store/7hdn84ab02qar14qpy5l4z4diw726rb4-bzip2-1.0.6.0.1-bin                64.5K           19.9M
/nix/store/93hb9j4n685dr698qq0j7ip0p2mss4lm-gzip-1.8                            146K           19.9M
/nix/store/ac082jcsg31763mbgiqlirhgsygimn1x-attr-2.4.47                          74K           19.9M
/nix/store/bqd0pk2ryvw0b47r7k23k13jx8ih2165-bzip2-1.0.6.0.1                    71.2K           19.9M
/nix/store/dl66jvc19im9lqslzqszsp2gif2y0y8i-zlib-1.2.11                         102K           19.9M
/nix/store/ifka3vgvakgskl7wjvbaw3x71l2g7bil-nghttp2-1.20.0-lib                  184K             20M
/nix/store/mcsl18halr6lx9b4d35ghrx71v7mw2k9-acl-2.2.52                         97.6K             20M
/nix/store/idgw2sgymddfbj6848mb0rdh3mprwj9f-libseccomp-2.3.2                    351K           20.1M
/nix/store/y4p3gg22jjr223r2r681nmfdfvj245lk-xz-5.2.3                            321K           20.1M
/nix/store/10n172zhpxa1r77dqi6pn0qws4z546p0-libsodium-1.0.15                    397K           20.2M
/nix/store/xjpzzdl3mh8v1wcbxrlgm2p9mnhlys6y-xz-5.2.3-bin                        149K           20.3M
/nix/store/44pga8rb4ldvijrk853mxf4hqib089wn-sqlite-3.21.0                      1.09M           20.9M
/nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12                       1.11M           20.9M
/nix/store/0lyn8v4w3cd70hzg5md0xwhykhlbsq9f-gnutar-1.29                        2.41M           22.4M
/nix/store/34vrcmdwar08x75k3khr8q7j8klc70ww-openssl-1.0.2o                     3.29M           23.1M
/nix/store/5ik00dp38q9z8p84vs9svcpnlv6rg39v-libssh2-1.8.0                       207K           23.4M
/nix/store/2z15ksqx06fkrxj246xh4ds10dnswsq7-curl-7.59.0                         573K           24.1M
/nix/store/id8ljxy387l6d2ih59mwaaz894dmj9k2-perl-WWW-Curl-4.17                  122K           24.2M
/nix/store/bw39bnxgb52ayi60v409kdxdhvpcjh8s-curl-7.59.0-bin                     149K           24.3M
/nix/store/dk0n769l985raba2nrya2q7ivspafj6f-gcc-6.4.0-lib                         5M           24.8M
/nix/store/agiyfa6fj25p52qshx9p4zwb4ks5kw0a-boehm-gc-7.6.0                      245K           25.7M
/nix/store/4bh7qhnrjk8cgd1bh7nr0glbga0aasdx-coreutils-8.28                     10.2M           30.2M
/nix/store/i6xckn2cfmwry0rnyqpxf14xynghsnls-perl-5.24.3                        44.9M           75.1M
/nix/store/2zcmxrmfh24wz2p0k6qzi4fz6n8xi5xw-perl-DBI-1.636                     1.65M           76.8M
/nix/store/145q4xmmq9bx5gbczwjyqam52vz558h8-perl-DBD-SQLite-1.55_07             346K           78.2M
/nix/store/xd6fvqpnrqd08k9ndi13pm5pcnxr83lv-openssl-1.0.2o-bin                  634K             79M
/nix/store/7c6lh9x8gamslzn4k1xsbcbp14b2v4nm-nix-1.11.16                        2.97M           97.3M

Unfortunately, -h is already taken as a short option by --help, so we have to
use a different letter or the capitalized version.

Resolves NixOS#2363
@bhipple bhipple force-pushed the feature/human-readable-closure-sizes branch from 09f9cec to 2669fee Compare August 26, 2018 01:15
@bhipple
Copy link
Contributor Author

bhipple commented Aug 26, 2018

Is there an easy way to get the path-info subcommand to take -h as this option if you also have -s or -S? Ideally I'd like it to be consistent with what users expect from coreutils, but I suppose -H isn't the end of the world.

++power;
res /= 1024;
}
std::cout << '\t' << std::setw(11) << std::setprecision(3) << res << idents[power];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use iostream manipulators, they're stateful and ugly. Boost format strings are much nicer (e.g. std::cout << fmt("%.3f", ...) or something like that.

idents[power] looks like it could overflow in theory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, updated to be future proof in a > 1024 yottabyte world, and swapped to boost::format 👍

If the user has an object greater than 1024 yottabytes, it'll just display it as
N yottabytes instead of overflowing.

Swaps to use boost::format strings instead of std::setw and std::setprecision.
@bhipple
Copy link
Contributor Author

bhipple commented Aug 26, 2018

Closer inspection of du -h and ls -h output suggests it only ever shows 1 decimal point of output, so I've truncated that as well while swapping and re-testing with boost::format:

λ brh nix →  /nix/store/szisym9qdkr7ll4v8lgkmni5smjjadyx-nix-2.0.4/bin/nix path-info -rsSH nixpkgs.nix | sort -hk3
/nix/store/11fr4327r3rglr4k5smscrmwqg6gz00i-nix-2.0.4-man              65.9K           65.9K
/nix/store/6953iif8k3550lspbrss63w9saprqq8y-busybox-1.28.1            142.2K          142.2K
/nix/store/ldqd4ynsmxz7nsmlx36bap9z96v3vk74-libatomic_ops-7.6.2       680.4K          680.4K
/nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131             20.2M           20.2M
/nix/store/80gpwb4fkvd2rfrpgmlgsq4hjbsz225p-bzip2-1.0.6.0.1            71.0K           20.3M
/nix/store/8c30dl4mmgm4rip1l08fvad9gca5sk2j-zlib-1.2.11               101.9K           20.3M
/nix/store/95yylk9akpg65r32a1sq9qhia4bxzzz2-attr-2.4.47                73.8K           20.3M
/nix/store/35yalbjrb5jh0arjawfxkryppvpip11a-nghttp2-1.24.0-lib        179.4K           20.4M
/nix/store/3cx8jscamhp08hjv6x4lhd1w57ggji0k-gzip-1.9                  142.4K           20.4M
/nix/store/6k794ln3ila2457d9k9fgyyyq7px8aci-acl-2.2.52                 97.3K           20.4M
/nix/store/hqspf7pmaz9s8hjjh3agjdmsn0pdj9xp-bzip2-1.0.6.0.1-bin        64.2K           20.4M
/nix/store/60pn8jnvbb3n70337jvdfkdn2zx7f331-libsodium-1.0.16          384.3K           20.6M
/nix/store/pflp65rydzd4wlywgm39mncw6g9v5cvf-libseccomp-2.3.3          351.7K           20.6M
/nix/store/x1rp4zikbiwjw2x7rvzlny4sj4yc99qw-xz-5.2.3                  320.9K           20.6M
/nix/store/9f4kav8sa4qf3clc61h06ggyvhi2m728-xz-5.2.3-bin              148.8K           20.7M
/nix/store/9pma2rib627l4iq67j6jl32mxq1mrzr9-sqlite-3.23.1               1.1M           21.3M
/nix/store/lw7xaqhakk0i1c631m3cvac3x4lc5gr5-bash-4.4-p12                1.1M           21.3M
/nix/store/w1145178ajs047rbkyclzphxj2g0a3px-brotli-1.0.3-lib            1.5M           21.7M
/nix/store/7zam9d16ml78rb0p1p5gds4p5z99fpyv-gnutar-1.30                 2.5M           22.9M
/nix/store/dkhi4wf3hw0pz1l3ljkjpwwc2m0a7klx-libkrb5-1.15.2              2.2M           23.5M
/nix/store/wqn1vcbm0za87cgxdy86p1ar1risgypr-openssl-1.0.2p              3.3M           23.5M
/nix/store/6p06bw9hggh8vj093a59nib283cs1kbx-libssh2-1.8.0             202.5K           23.8M
/nix/store/12zhmzzhrwszdc8q3fwgifpwjkwi3mzc-gcc-7.3.0-lib               5.3M           25.5M
/nix/store/fzsf72mfsy40l5xbyyrkwb0qjdz8jpl0-boehm-gc-7.6.4            245.0K           26.4M
/nix/store/m2biwb4sla62w7hr7v0nycsyxjyd956p-curl-7.59.0               599.5K           27.9M
/nix/store/920k63py2w97xpfyb5ps9l6wbidvzfjz-coreutils-8.29             10.2M           30.6M
/nix/store/77li23mlg0mvyr41v90c9p2vqj9fnp1q-aws-sdk-cpp-1.3.22          5.0M           38.1M
/nix/store/ddrc6dys25w3hpyng076bvpfb57h4p51-nix-2.0.4                   6.8M           62.9M

The boost::format precision seems to include .0 rather than just showing an integer when it can, but that actually seems fine, since it keeps everything nicely aligned.

@bhipple
Copy link
Contributor Author

bhipple commented Aug 29, 2018

If there are any further suggestions I'm happy to update; otherwise I think this should be good to go as-is.

@edolstra
Copy link
Member

Thanks, merged!

@edolstra edolstra closed this Aug 30, 2018
@vcunat
Copy link
Member

vcunat commented Aug 30, 2018

If we wanted to be "overly" correct, we would show Ki Mi... instead of K M... because SI prefixes denote powers of 1000 and not 1024, strictly speaking.

EDIT: thanks for the PR, BTW.

@bhipple
Copy link
Contributor Author

bhipple commented Aug 30, 2018

Thanks for the merge and the follow-up polishes in 9982824 @edolstra. I'm glad we were able to swap it to -h too! Consistency with other unix tools is much more pleasant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants