In NetworkIOMeter, the number strings of bytes per second are formatted
with Meter_humanUnit(). As the numbers are only updated every 500 ms,
it is good to cache the formatted strings. This saves code size.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
In DiskIOMeter, the number strings of bytes per second are formatted
with Meter_humanUnit(). As the numbers are only updated every 500 ms,
it is good to cache the formatted strings. This saves code size.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Since Meter_humanUnit() is often called with floating point values in
Meter objects, rewrite the function to let it process `double` type
natively, and save floating point to integer casts.
The rewritten function:
* Allows higher orders of magnitude including 'R' and 'Q', and
addresses infinity. (The previous version has a maximum value of
(2^64 - 1) representing 16 ZiB.)
* Rounds values when they are in intervals (99.9, 100) and (9.99, 10),
and displays them with correct precision (number of fraction digits).
* Produces assertion error on negative and NaN values (undefined
behavior).
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Always update the `values` member during the call of
NetworkIOMeter_updateValues().
This makes the values of every instance of NetworkIOMeter consistent.
The user might see non-zero bars (or graph) during the "stale" status
of the meter after this commit. The side effect is not a bug.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Always update the `values` member during the call of
DiskIOMeter_updateValues().
This makes the values of every instance of DiskIOMeter consistent.
The user might see non-zero bars (or graph) during the "stale" status
of the meter after this commit. The side effect is not a bug.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
The number of items of a Meter can exceed the length of
BarMeterMode_characters array. (The CPU Meter is an example.)
Item numbers exceeding the length are unplottable in a bar.
Add an assertion to note the fact.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Currently when the runtime configuration is saved to file the true
configuration file is first truncated and then written to with each
available option.
If for any reason htop dies (e.g. program crash, or system shutdown)
while still performing the output the configuration file might end up
empty or corrupted.
Write to a temporary file and rename at the end on success.
As a side effect new configuration files are now created with a mode of
0600.
The `Meter.total` value may be 0 on BatteryMeter, SwapMeter,
linux/HugePageMeter, linux/ZramMeter and others. In case of a zero
total value, print an empty bar in bar meter mode.
Also change GraphMeterMode_draw() so that it no longer writes back the
`total` value if it is zero.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Change variable types of time values from signed to unsigned.
* Change variable naming for consistency: `totalMinutes`, `totalHours`,
`totalDays` for total values and `minutes`, `hours`, `days`, etc. for
remainder values. (`years` remains an exception as there is no larger
unit than years)
* Use `unsigned long long` type for `years` value to prevent a
potential overflow.
* The time units are now evaluated from small to large, in the hopes
that small values would print faster. (There is no performance test
for this claim.)
* The days unit is now printed when `totalHours` is at least 24.
(Issue htop-dev#1317) There is room in the new code to revert to the
old threshold (totalHours < 2400).
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Fixes a regression caused by 74b28849c4.
When a graph meter is too narrow to draw the graph, but the graph data
buffer is allocated, the meter should keep recording new values.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>