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

CPU load scale is off on MacOS #499

Closed
alyssais opened this issue Jan 23, 2017 · 3 comments
Closed

CPU load scale is off on MacOS #499

alyssais opened this issue Jan 23, 2017 · 3 comments
Labels
CPU load Related to the CPU load data or display MacOS X Related to MacOS X specific implementation

Comments

@alyssais
Copy link

alyssais commented Jan 23, 2017

Shell: zsh
Operating system: macOS
Liquid Prompt version (tag, commit): 1.11


Often the CPU load percentage reported by liquidprompt is well over 100%. This means it won't be coloured by the gradient scale.

I've investigated a bit and found that liquidprompt uses sysctl -n vm.loadavg to find the current CPU usage, then it divides it by the number returned from sysctl -n ncpu (in my case this is 4) and multiplies by 100.

The values from sysctl -n vm.loadavg can be well over 400%, though. I've seen it as high as 10.88. So, it looks like liquidprompt is using the wrong value as the upper bound (though I couldn't tell you what that should be).

@alyssais
Copy link
Author

#455 would partially fix this because then the load would at least be coloured.

@dolmen dolmen added CPU load Related to the CPU load data or display MacOS X Related to MacOS X specific implementation labels Jan 30, 2017
@dolmen
Copy link
Collaborator

dolmen commented Jan 30, 2017

The main issue is that loadavg is used with an incorrect expectation of a [0,1] range. See #391 where the bug was introduced.

toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 7, 2020
Liquidprompt's load feature currently assumes, incorrectly, that the
load average is a percentage (it isn't) that can be converted directly
to CPU utilisation (it can't).

Because the load average is a gauge reading with an essentially
unlimited ceiling, ensure the colouring function is passed an
appropriate ceiling instead of the default value of 100. This ceiling is
now set (rather arbitrarily) at 20*$LP_LOAD_THRESHOLD, meaning the
"highest" colour starts being used at 18*$LP_LOAD_THRESHOLD.

To handle the case where the actual load exceeds the
20*$LP_LOAD_THRESHOLD ceiling, the _lp_color_map() function is changed
to apply the "highest" colour (instead of no colour) whenever the
supplied value exceeds the ceiling of the scale. This change is an
alternative implementation of what has already been proposed in liquidprompt#455.

Closes liquidprompt#499, liquidprompt#530.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 7, 2020
Liquidprompt's load feature currently assumes, incorrectly, that the
load average is a percentage (it isn't) that can be converted directly
to CPU utilisation (it can't).

Because the load average is a gauge reading with an essentially
unlimited ceiling, ensure the colouring function is passed an
appropriate ceiling instead of the default value of 100. This ceiling is
now set (rather arbitrarily) at 20*$LP_LOAD_THRESHOLD, meaning the
"highest" colour starts being used at 18*$LP_LOAD_THRESHOLD.

To handle the case where the actual load exceeds the
20*$LP_LOAD_THRESHOLD ceiling, the _lp_color_map() function is changed
to apply the "highest" colour (instead of no colour) whenever the
supplied value exceeds the ceiling of the scale. This change is an
alternative implementation of what has already been proposed in liquidprompt#455.

Finally, it improves the documentation of the LP_LOAD_THRESHOLD value to make
it clear that it represents a centiload value that will be multiplied with the
number of CPUs in the system to calculate the actual load average threshold
that will be compared with the system's representation of the load average.

Closes liquidprompt#499, liquidprompt#530.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 7, 2020
Liquidprompt's load feature currently assumes, incorrectly, that the
load average is a percentage (it isn't) that can be converted directly
to CPU utilisation (it can't).

Because the load average is a gauge reading with an essentially
unlimited ceiling, ensure the colouring function is passed an
appropriate ceiling instead of the default value of 100. This ceiling is
now set (rather arbitrarily) at 20*$LP_LOAD_THRESHOLD, meaning the
"highest" colour starts being used at 18*$LP_LOAD_THRESHOLD.

To handle the case where the actual load exceeds the
20*$LP_LOAD_THRESHOLD ceiling, the _lp_color_map() function is changed
to apply the "highest" colour (instead of no colour) whenever the
supplied value exceeds the ceiling of the scale. This change is an
alternative implementation of what has already been proposed in liquidprompt#455.

Finally, it improves the documentation of the LP_LOAD_THRESHOLD value to
make it clear that it represents a centiload value that will be
multiplied with the number of CPUs in the system to calculate the actual
load average threshold that will be compared with the system's
representation of the load average.

Closes liquidprompt#499, liquidprompt#530.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 7, 2020
Liquidprompt's load feature currently assumes, incorrectly, that the
load average is a percentage (it isn't) that can be converted directly
to CPU utilisation (it can't).

Because the load average is a gauge reading with an essentially
unlimited ceiling, ensure the colouring function is passed an
appropriate ceiling instead of the default value of 100. This ceiling is
now set (rather arbitrarily) at 20*$LP_LOAD_THRESHOLD, meaning the
"highest" colour starts being used at 18*$LP_LOAD_THRESHOLD.

To handle the case where the actual load exceeds the
20*$LP_LOAD_THRESHOLD ceiling, the _lp_color_map() function is changed
to apply the "highest" colour (instead of no colour) whenever the
supplied value exceeds the ceiling of the scale. This change is an
alternative implementation of what has already been proposed in liquidprompt#455.

Finally, it improves the documentation of the LP_LOAD_THRESHOLD value to
make it clear that it represents a centiload value that will be
multiplied with the number of CPUs in the system to calculate the actual
load average threshold that will be compared with the system's
representation of the load average.

Closes liquidprompt#499, liquidprompt#530.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 7, 2020
Liquidprompt's load feature currently assumes, incorrectly, that the
load average is a percentage (it isn't) that can be converted directly
to CPU utilisation (it can't).

Because the load average is a gauge reading with an essentially
unlimited ceiling, ensure the colouring function is passed an
appropriate ceiling instead of the default value of 100. This ceiling is
now set (rather arbitrarily) at 20*$LP_LOAD_THRESHOLD, meaning the
"highest" colour starts being used at 18*$LP_LOAD_THRESHOLD.

To handle the case where the actual load exceeds the
20*$LP_LOAD_THRESHOLD ceiling, the _lp_color_map() function is changed
to apply the "highest" colour (instead of no colour) whenever the
supplied value exceeds the ceiling of the scale. This change is an
alternative implementation of what has already been proposed in liquidprompt#455.

Finally, it improves the documentation of the LP_LOAD_THRESHOLD value to
make it clear that it represents a centiload value that will be
multiplied with the number of CPUs in the system to calculate the actual
load average threshold that will be compared with the system's
representation of the load average.

Closes liquidprompt#499, closes liquidprompt#530.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 7, 2020
Liquidprompt's load feature currently assumes, incorrectly, that the
load average is a percentage (it isn't) that can be converted directly
to CPU utilisation (it can't).

Because the load average is a gauge reading with an essentially
unlimited ceiling, ensure the colouring function is passed an
appropriate ceiling instead of the default value of 100. This ceiling is
now set (rather arbitrarily) at 20*$LP_LOAD_THRESHOLD, meaning the
"highest" colour starts being used at 18*$LP_LOAD_THRESHOLD.

To handle the case where the actual load exceeds the
20*$LP_LOAD_THRESHOLD ceiling, the _lp_color_map() function is changed
to apply the "highest" colour (instead of no colour) whenever the
supplied value exceeds the ceiling of the scale. This change is an
alternative implementation of what has already been proposed in liquidprompt#455.

Finally, it improves the documentation of the LP_LOAD_THRESHOLD value to
make it clear that it represents a centiload value that will be
multiplied with the number of CPUs in the system to calculate the actual
load average threshold that will be compared with the system's
representation of the load average.

Closes liquidprompt#499, closes liquidprompt#530.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jun 11, 2020
In some cases, scales have no upper ceiling. In that case the supplied value
might exceed the (arbitrary) ceiling used by `_lp_color_map()`. Ensure that the
"reddest" possible colour is output in such cases.

Closes liquidprompt#455, closes liquidprompt#499.

Signed-off-by: Tore Anderson <[email protected]>
@Rycieos Rycieos added this to the v1.12 milestone Jun 30, 2020
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jul 3, 2020
In some cases, scales have no upper ceiling. In that case the supplied value
might exceed the (arbitrary) ceiling used by `_lp_color_map()`. Ensure that the
"reddest" possible colour is output in such cases.

Closes liquidprompt#455, closes liquidprompt#499.

Signed-off-by: Tore Anderson <[email protected]>
toreanderson added a commit to toreanderson/liquidprompt that referenced this issue Jul 3, 2020
In some cases, scales have no upper ceiling. In that case the supplied value
might exceed the (arbitrary) ceiling used by `_lp_color_map()`. Ensure that the
"reddest" possible colour is output in such cases.

Closes liquidprompt#455, closes liquidprompt#499.

Signed-off-by: Tore Anderson <[email protected]>
@Rycieos Rycieos removed this from the v1.12 milestone Jul 3, 2020
@Rycieos
Copy link
Collaborator

Rycieos commented Jul 4, 2020

The no colors problem has been fixed in a70e80f.

I'm consolidating the discussion for the load scale being off on #530. Despite this issue being made first, the other has some suggested fixes already. Please continue the discussion there.

@Rycieos Rycieos closed this as completed Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CPU load Related to the CPU load data or display MacOS X Related to MacOS X specific implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants