Refactor the sample time code to make one call to gettimeofday
(aka the realtime clock in clock_gettime, when available) and
one to the monotonic clock. Stores each in more appropriately
named ProcessList fields for ready access when needed. Every
platform gets the opportunity to provide their own clock code,
and the existing Mac OS X specific code is moved below darwin
instead of in Compat.
A couple of leftover time(2) calls are converted to use these
ProcessList fields as well, instead of yet again sampling the
system clock.
Related to https://github.com/htop-dev/htop/pull/574
The end goal is to consolidate all the points in htop that can only work in
live-only mode today, so that will be able to inject PCP archive mode and have
a chance at it working.
The biggest problem we've got at this moment is all the places that are
independently asking the kernel to 'give me the time right now'.
Each of those needs to be audited and ultimately changed to allow platforms to
manage their own idea of time.
So, all the calls to gettimeofday(2) and time(2) are potential problems.
Ultimately I want to get these down to just one or two.
Related to https://github.com/htop-dev/htop/pull/574
The local stack buffer does not need to be cleaned to zeros when
- just initialized, cause the length is set to 0 and the first
character is set to '\0', so all printing functions will safely stop
- no further used, i.e. the variable goes out of scope
Print wide characters, like degree sign, properly via mvadd_wch().
Ignore attributes when returning value from RichString_getCharVal() in
non-wide ncurses mode to test against raw characters.
Change the color and total based on the actual 1min load value:
< 1 : green and total of 1.0
< cpu-count : yellow and total of cpu-count
else : red and total of 2*cpu-count
Closes: #32
In case the text is too long for the bar, try to fit by truncating at a
space character.
E.g.
[|24.1% 2000Mhz 40°C]
[24.1% 2000Mhz 40°C]
[||||24.1% 2000Mhz]
[|||24.1% 2000Mhz]
[||24.1% 2000Mhz]
[|24.1% 2000Mhz]
[24.1% 2000Mhz]
[|||| 24.1%]
[|||| 24.1%]
[|||| 24.1%]
[||||24.1%]
[|||24.1%]
[||24.1%]
[|24.1%]
[24.1%]
[24.1]
[24.]
[24]
[2]
RichString_writeFrom takes a top spot during performance analysis due to the
calls to mbstowcs() and iswprint().
Most of the time we know in advance that we are only going to print regular
ASCII characters.
Currently the code does not handle multi-byte characters, so length-
computations take the raw count of C characters and not the to displayed
size into account.
An example is the degree sign for temperatures.
Closes: #329
Allocating zero size memory results in implementation-defined behavior:
man:malloc(3) :
If size is 0, then malloc() returns either NULL, or a unique pointer
value that can later be successfully passed to free().