tobert / pcstat

Page Cache stat: get page cache stats for files on Linux
Apache License 2.0
1.23k stars 153 forks source link

Formatting percentages without leading zeroes #24

Closed kokes closed 3 years ago

kokes commented 3 years ago

First and foremost thanks for the wonderful tool, it works great. Here's just one readability nitpick:

The output is kinda hard to read for small percentages due to the leading zeroes:

+------------------------+----------------+------------+-----------+---------+
| Name                   | Size (bytes)   | Pages      | Cached    | Percent |
|------------------------+----------------+------------+-----------+---------|
| LICENSE                | 11323          | 3          | 0         | 000.000 |
| README.md              | 7114           | 2          | 0         | 000.000 |
| go.mod                 | 102            | 1          | 1         | 100.000 |
| go.sum                 | 207            | 1          | 0         | 000.000 |
| mincore.go             | 2449           | 1          | 0         | 000.000 |
| mnt_ns_linux.go        | 1779           | 1          | 0         | 000.000 |
| mnt_ns_unix.go         | 741            | 1          | 0         | 000.000 |
| pc                     | 2535856        | 620        | 267       | 043.065 |
| pcstatus.go            | 2735           | 1          | 0         | 000.000 |
| syscall_linux_386.go   | 746            | 1          | 0         | 000.000 |
| syscall_linux_amd64.go | 752            | 1          | 0         | 000.000 |
+------------------------+----------------+------------+-----------+---------+

I think it would be more scannable if the leading zeroes weren't there

+------------------------+----------------+------------+-----------+---------+
| Name                   | Size (bytes)   | Pages      | Cached    | Percent |
|------------------------+----------------+------------+-----------+---------|
| LICENSE                | 11323          | 3          | 0         |   0.000 |
| README.md              | 7114           | 2          | 0         |   0.000 |
| go.mod                 | 102            | 1          | 1         | 100.000 |
| go.sum                 | 207            | 1          | 0         |   0.000 |
| mincore.go             | 2449           | 1          | 0         |   0.000 |
| mnt_ns_linux.go        | 1779           | 1          | 0         |   0.000 |
| mnt_ns_unix.go         | 741            | 1          | 0         |   0.000 |
| pc                     | 2535856        | 620        | 460       |  74.194 |
| pcstatus.go            | 2735           | 1          | 0         |   0.000 |
| syscall_linux_386.go   | 746            | 1          | 0         |   0.000 |
| syscall_linux_amd64.go | 752            | 1          | 0         |   0.000 |
+------------------------+----------------+------------+-----------+---------+

I just changed all the %07.3f to %7.3f, so that a space would be used to fill it from the left.

I did see the comment

        // %07.3f was chosen to make it easy to scan the percentages vertically
        // I tried a few different formats only this one kept the decimals aligned

So I don't know if this suggested implementation solves your issue or not - I certainly find it more scannable vertically, but that's just me.

tobert commented 3 years ago

Applied in 7e448c021d391994ac6c47b7ec1c8d5f42f21240 :)