cli: Add progress bar for -getinfo #22547

pull klementtan wants to merge 1 commits into bitcoin:master from klementtan:getinfo-progressbar changing 1 files +34 βˆ’1
  1. klementtan commented at 4:28 pm on July 25, 2021: contributor

    Add a progress bar for the Verification progress attribute in -getinfo when verification progress < 99%.

    image

    Motivation:

    • Improve user-friendliness of -getinfo
    • Can be useful with watch -n 1 bitcoin-cli -getinfo(suggested by theStack below)
    • The progress bar is only display when are still syncing to tip(verification progress < 99%)

    Reviewing

    If your verification progress is > 99% you can restart the verification progress with

    0$ ./src/bitcoind -reindex
    1$./src/bitcoin-cli -getinfo
    
  2. klementtan commented at 4:29 pm on July 25, 2021: contributor

    Also address #17314

    Alternative, more human-friendly, format besides JSON? Colors, progress bars πŸ˜„?

  3. hebasto commented at 4:32 pm on July 25, 2021: member

    Motivation: Improve user-friendliness of -getinfo

    Not sure if bitcoin-cli is dedicated to casual users.

  4. klementtan force-pushed on Jul 25, 2021
  5. laanwj added the label RPC/REST/ZMQ on Jul 25, 2021
  6. klementtan commented at 6:31 pm on July 25, 2021: contributor

    Not sure if bitcoin-cli is dedicated to casual users. @hebasto thanks for the feedback! I can see where you are coming from but from #17314 I was under the impression that we want to make bitcoin-cli more friendly to casual users. Will be happy to close this PR if this additional feature is deemed unnecessary.

    Now that getinfo is no longer part of the RPC API, and client-side implementation is not subject to API stability, it’s possible to start thinking about making it more user friendly.

  7. klementtan force-pushed on Jul 25, 2021
  8. ghost commented at 8:41 pm on July 25, 2021: none
    Concept ACK. Will try today.
  9. in src/bitcoin-cli.cpp:910 in da3603c164 outdated
    905+
    906+    for (int i = 0; i < (1 - progress) / INCREMENT; i++) {
    907+        progress_bar += INCOMPLETE_BAR;
    908+    }
    909+
    910+    progress_bar += "|";
    


    unknown commented at 1:24 am on July 26, 2021:
     0    std::string progress_bar = "";
     1    static constexpr double INCREMENT{0.05};
     2    static const std::string COMPLETE_BAR{"\u2588"};
     3    static const std::string INCOMPLETE_BAR{"\u2591"};
     4
     5    for (int i = 0; i < progress / INCREMENT; i++) {
     6        progress_bar += COMPLETE_BAR;
     7    }
     8
     9    for (int i = 0; i < (1 - progress) / INCREMENT; i++) {
    10        progress_bar += INCOMPLETE_BAR;
    11    }
    12
    13    progress_bar += "";
    

    image

    It looks okay even without |


    klementtan commented at 2:32 pm on July 27, 2021:
    Done. Thanks πŸ‘
  10. jarolrod commented at 4:38 am on July 26, 2021: member

    I’m weak NACK on this. I’m concept 0 on this

    First, thanks for all your work on improving -getinfo πŸ₯ƒ

    I think a good way to think about command line tools is how they fit into scripting work flows. We shouldn’t add elements that make it harder for someone to extract the needed information as part of their workflow.

    The progress bar introduced here is an example of an element that makes it slightly more difficult to extract the needed information; The verification progress value in this case.

    Additionally, it is my opinion that the inclusion of this progress bar adds very little value. It doesn’t give me any better insight into the verification progress than the number value does.

  11. theStack commented at 12:55 pm on July 27, 2021: member

    Concept ACK

    Since “getinfo is no longer part of the RPC API, and client-side implementation is not subject to API stability” (quoting the description in #17314) , its output is meant only to be consumed by humans (“the eye”), not for machines and hence using it ever in a script would obviously be a bad idea that shouldn’t be encouraged. For those purposes we have the RPC API.

    I think CLI users deserves to have a nice looking output as well, I can imagine it’s nice to see the verification progress also visually via watch -n 1 bitcoin-cli -getinfo :) that said, I agree of course that this PR is absolutely not high priority.

  12. jonatack commented at 12:56 pm on July 27, 2021: member
    No opinion yet about this change. Just mentioning that there is a distinction between client-side CLI commands and the server-side RPC API. IIRC part of the point of the client-side CLI, along with aggregating multiple RPC calls in some cases, is to be human-friendly and freer of API constraints. We warn about software depending on the client-side CLI (for stability it should use the RPC API instead), for instance ./src/bitcoin-cli -netinfo help states at the top: This human-readable interface will change regularly and is not intended to be a stable API. Now, -getinfo is IIRC the oldest CLI command, as indeed it previously was an RPC, but when it became a client-side command and now has been fully revamped in presentation, anyone who was depending on scraping it with a script may have received the message that it’s better to use the RPC API instead.
  13. klementtan force-pushed on Jul 27, 2021
  14. jarolrod commented at 3:33 pm on July 27, 2021: member
    Thanks @theStack @jonatack, retracted my NACK
  15. Zero-1729 commented at 6:36 pm on July 27, 2021: contributor

    Concept ACK, nice UX addition for the CLI.

    Especially neat with watch -n 1 bitcoin-cli -getinfo as @theStack mentioned above.

  16. jonatack commented at 8:56 am on July 28, 2021: member
    Ok, I tested and TBH find it distracting, somewhat blinding with the large patch of white, and inaccurate. It just adds noise here. Might make more sense in the GUI. If you do keep it, maybe a muted grey instead and not displayed if > 99%.
  17. klementtan force-pushed on Jul 28, 2021
  18. klementtan commented at 2:08 pm on July 28, 2021: contributor

    Thanks, reviewers for the feedback and insights!

    It seems there is a mixed response to this feature. I will leave this PR open for a few more days to get more feedback and close it afterward if there is still no strong demand for it.

    If you do keep it, maybe a muted grey instead and not displayed if > 99%. @jonatack thanks for the suggestion! Implemented it in e75ee3e to a94d991

    • Progress bar will only be displayed when verification progress < 99%
    • Change filled bar to make it less blinding

    image

  19. ghost commented at 4:10 pm on July 28, 2021: none

    Progress bar will only be displayed when verification progress < 99% Change filled bar to make it less blinding

    No progress bar for >= 99% verification makes sense.

    0-\u2588
    1+\u2592
    

    New Unicode for COMPLETE BAR looks good.

    Tested with command: watch -c -t -n 1 bitcoin-cli -getinfo (Don’t see colors using watch but the progress bar and other things LGTM.

    Progress-Bar

    tACK https://github.com/bitcoin/bitcoin/commit/a94d99199f17c667ba76fdb77c48ce6136afa81f

  20. theStack approved
  21. theStack commented at 2:22 pm on July 30, 2021: member

    Tested ACK a94d99199f17c667ba76fdb77c48ce6136afa81f πŸ“Š

    Agree that the new (in)complete characters look way better and are less blinding, also displaying the bar only on <99% progress makes sense.

  22. klementtan commented at 10:50 am on July 31, 2021: contributor
    @prayank23 Thanks for testing it! I think you’re not seeing colour because your stdout is not connected to the terminal. You can get colour if you set -color=always
  23. jonatack commented at 5:27 pm on July 31, 2021: member
    This seems to be a nice improvement over the last version. Some code review feedback here: https://github.com/jonatack/bitcoin/commit/b640049
  24. Zero-1729 commented at 6:12 pm on July 31, 2021: contributor

    tACK a94d99199f17c667ba76fdb77c48ce6136afa81f

    Nice update. However, @klementtan I’d strongly suggest adding @jonatack’s suggestions. For example, I just noticed the lack of space between the progress bar and the percentage value. Additionally, I think the other suggestions there would greatly help readability and simplify future code reviews.

    Note: I also wasn’t getting color from watch --color -n 1 so I prefixed bitcoin-cli -getinfo with unbuffer (from the expect package) to get it working.

    pr-getinfo

  25. klementtan force-pushed on Aug 1, 2021
  26. klementtan force-pushed on Aug 1, 2021
  27. in src/bitcoin-cli.cpp:891 in 71c1556f14 outdated
    883@@ -884,6 +884,29 @@ static void GetWalletBalances(UniValue& result)
    884     result.pushKV("balances", balances);
    885 }
    886 
    887+/**
    888+ * GetProgressBar contructs a progress bar with 5% intervals.
    889+ *
    890+ * @param[in]   progress      The proportion of the progress bar to be filled between 0 and 1.
    891+ * @params[out] progress_bar  String representation of the progress bar.
    


    jonatack commented at 7:37 pm on August 1, 2021:
    0 * [@param](/bitcoin-bitcoin/contributor/param/)[out] progress_bar  String representation of the progress bar.
    
  28. jonatack commented at 7:37 pm on August 1, 2021: member
    almost-ACK
  29. ghost commented at 7:53 pm on August 1, 2021: none

    crACK https://github.com/bitcoin/bitcoin/commit/71c1556f1476abb61f3faca239e2f2eb857b72cb. Will test this week.

    Changes that I see since last review:

    1. Changed GetProgressBar() function from static to void. Reason is explained by @jonatack in this comment
    0-static std::string GetProgressBar(const double progress)
    1+void GetProgressBar(double progress, std::string& progress_bar)
    2
    3-return progress_bar;
    
    1. It is better to stop executing if progress is less than zero(min) or greater than 1(max) instead of printing empty string.
    0-if (progress < 0 || progress > 1) return "";
    1+if (progress < 0 || progress > 1) return;
    
    1. Makes sense because std::string initializes an empty string ("") by default. In few other languages, devs prefer to initialize it to avoid null exceptions.
    0-std::string progress_bar = "";
    1+std::string ibd_progress_bar;
    
    1. According to developer notes ++i should be used.
    0-for (int i = 0; i < progress / INCREMENT; i++) {
    1+for (int i = 0; i < progress / INCREMENT; ++i) {
    2
    3-for (int i = 0; i < (1 - progress) / INCREMENT; i++) {
    4+for (int i = 0; i < (1 - progress) / INCREMENT; ++i) {
    

    ++i increments then return i++ returns then increment

    I had recently read one post on reddit and found it interesting because of 2 reasons:

    a. Helped me understand different operators b. This comment: i -=- 1

    1. Add padding between progress bar and IBD progress
    0-verification_progress_bar = GetProgressBar(verification_progress);
    1+GetProgressBar(ibd_progress, ibd_progress_bar);
    2+ibd_progress_bar += " ";
    
  30. klementtan force-pushed on Aug 1, 2021
  31. klementtan commented at 8:14 pm on August 1, 2021: contributor

    a94d991 … dba61d0

    • Added whitespace between the progress bar and percentage
    • Used suggestions in jonatack@b640049

    Note: I also wasn’t getting color from watch –color -n 1 so I prefixed bitcoin-cli -getinfo with unbuffer (from the expect package) to get it working. @Zero-1729 Thanks for testing! I think you will need to use watch -c -t -n 1 ./src/bitcoin-cli -signet -color=always -getinfo. Currently -getinfo will not print color if the stdout is not connected to a terminal(watch).

  32. Zero-1729 approved
  33. Zero-1729 commented at 10:05 pm on August 1, 2021: contributor

    re-tACK dba61d0cd1226fedaef194b6851c34674fda4bd6 πŸ§ͺ

    LGTM, great work @klementtan!

    Note: Yeah, appending -color=always to bitcoin-cli did the trick, no need for unbuffer again.

    pr-getinfo-updated

  34. ghost commented at 2:18 am on August 2, 2021: none

    @prayank23 Thanks for testing it! I think you’re not seeing colour because your stdout is not connected to the terminal. You can get colour if you set -color=always

    Yes this works. I forgot the option that you added in last PR.

    watch -c -t -n 1 bitcoin-cli -getinfo color=always

    image

    image

  35. unknown approved
  36. theStack commented at 1:48 pm on August 2, 2021: member

    Some nits after the latest change:

    • there is no reason to remove the static attribute from GetProgressBar; the function still only needs to be visible in the same compilation unit
    • the new interface implictely assumes now that the passed string is already empty, as it only appends to progress_bar, but never initializes (could either clear the string in the beginning or assert that it is empty?)
    • I don’t think returning a string by value necessarily leads to a copy – this is a typical case where move semantics potentially kick in and a copy is avoided (see e.g. https://stackoverflow.com/questions/48160292/in-c11-does-returning-a-stdstring-in-a-function-move-or-copy-it); there are also techniques like copy elision and (N)RVO (https://www.fluentcpp.com/2016/11/28/return-value-optimizations/), though I’m not sure if we have any guarantees here with C++17; maybe someone deeper in C++ can shed some light here

    Not any blockers though. Will re-test later.

  37. jonatack commented at 3:26 pm on August 2, 2021: member

    there is no reason to remove the static attribute from GetProgressBar; the function still only needs to be visible in the same compilation unit

    Agree!

    the new interface implictely assumes now that the passed string is already empty, as it only appends to progress_bar

    IIUC this seems fine, insofar that one might want to append a progress bar to a result string that already has some content.

    I don’t think returning a string by value necessarily leads to a copy – this is a typical case where move semantics potentially kick in and a copy is avoided (see e.g. stackoverflow.com/questions/48160292/in-c11-does-returning-a-stdstring-in-a-function-move-or-copy-it); there are also techniques like copy elision and (N)RVO (fluentcpp.com/2016/11/28/return-value-optimizations), though I’m not sure if we have any guarantees here with C++17; maybe someone deeper in C++ can shed some light here

    I hadn’t noticed this codebase depending on the compiler for it, though perhaps we already do somewhere.

  38. cli: Add progress bar for -getinfo
    Co-authored-by: jonatack <jon@atack.com>
    b851a92c06
  39. klementtan force-pushed on Aug 2, 2021
  40. theStack approved
  41. theStack commented at 5:10 pm on August 2, 2021: member
    re-ACK b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 🍹 (quickly tested watching verification from 0 to 100% on signet)
  42. klementtan commented at 6:57 pm on August 2, 2021: contributor
    dba61d0 to b851a92: Add static attribute to GetProgressBar
  43. ghost commented at 9:35 pm on August 2, 2021: none

    there is no reason to remove the static attribute from GetProgressBar; the function still only needs to be visible in the same compilation unit

    Agree. It can be changed to non-static if required later.

    reACK https://github.com/bitcoin/bitcoin/commit/b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9

  44. Zero-1729 approved
  45. Zero-1729 commented at 10:15 pm on August 2, 2021: contributor

    re-tACK b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 (re-tested, works as expected 🍾)

    It’s a clean push πŸͺ„βœ¨

    0$ git range-diff dba61d0...b851a92 
    
    01:  dba61d0cd ! 1:  b851a92c0 cli: Add progress bar for -getinfo
    1    ...
    2    -+void GetProgressBar(double progress, std::string& progress_bar)
    3    ++static void GetProgressBar(double progress, std::string& progress_bar)
    
  46. jonatack commented at 9:32 am on August 3, 2021: member

    ACK b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9

    Tested by manually setting progress inside the new function with values between 0 and 1 and also with

    0$ ./src/bitcoind -signet -reindex -daemon
    1$ watch -c -t -n 1 ./src/bitcoin-cli -signet -color=always -getinfo
    
  47. lsilva01 approved
  48. lsilva01 commented at 5:42 am on August 4, 2021: contributor

    Tested ACK https://github.com/bitcoin/bitcoin/pull/22547/commits/b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 on mainnet and signet on Ubuntu 20.04.

    Good UX improvement.

  49. shaavan commented at 4:33 pm on August 6, 2021: contributor

    No strong opinion Tested b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 on Ubuntu 20.04

    This PR intends on adding a new progress bar in the output of command ./bitcoin-cli -signet -daemon. By adding new functions that create a string of greyscale Unicode characters to give a perception of the progress bar. The ratio of lighter and darker grey tones of these characters is a function of the ratio of the verification process that has been completed.

    Tested the PR by the command bitcoind -signet -reindex followed by ./src/bitcoin-cli -signet -getinfo. The PR is successful in adding the changes it intends to add.

    Attaching a screenshot to show the proper working of the progress bar in the result of -getinfo

    image1

    I neither support nor disagree with the changes intended by this PR. Adding a progress bar does make the result of -getinfo command more eye-pleasing, but it doesn’t feel like an important or crucial addition to the result. As the purpose of bitcoin-cli is to be rather highly efficient than being eye-pleasing. If there is some way of adding the progress bar as a suboption of -getinfo then I am ACKed on that, because then the bitcoin-cli user has the choice to rather display the progress bar or not while calling -getinfo.

  50. meshcollider merged this on Aug 10, 2021
  51. meshcollider closed this on Aug 10, 2021

  52. sidhujag referenced this in commit bd44ba63c8 on Aug 10, 2021
  53. klementtan deleted the branch on Aug 11, 2021
  54. klementtan commented at 9:38 am on August 15, 2021: contributor

    @ShaMan239 Thanks for the detailed review! πŸ‘

    I agree that this feature is definitely not essential but from the feedback of other reviewers, it seems that it would make the user experience of using bitcoin-cli better.

    adding the progress bar as a suboption

    For now, I am not really inclined towards adding that because it would make -getinfo more complicated than necessary but if there is enough demand for it I would be more than happy to add it.

  55. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-19 00:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me