{"action":"opened","issue":{"url":"https://api.github.com/repos/nojhan/liquidprompt/issues/530","repository_url":"https://api.github.com/repos/nojhan/liquidprompt","labels_url":"https://api.github.com/repos/nojhan/liquidprompt/issues/530/labels{/name}","comments_url":"https://api.github.com/repos/nojhan/liquidprompt/issues/530/comments","events_url":"https://api.github.com/repos/nojhan/liquidprompt/issues/530/events","html_url":"https://github.com/nojhan/liquidprompt/issues/530","id":254215209,"number":530,"title":"CPU usage can't be computed form load","user":{"login":"pichi","id":45734,"avatar_url":"https://avatars2.githubusercontent.com/u/45734?v=4","gravatar_id":"","url":"https://api.github.com/users/pichi","html_url":"https://github.com/pichi","followers_url":"https://api.github.com/users/pichi/followers","following_url":"https://api.github.com/users/pichi/following{/other_user}","gists_url":"https://api.github.com/users/pichi/gists{/gist_id}","starred_url":"https://api.github.com/users/pichi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pichi/subscriptions","organizations_url":"https://api.github.com/users/pichi/orgs","repos_url":"https://api.github.com/users/pichi/repos","events_url":"https://api.github.com/users/pichi/events{/privacy}","received_events_url":"https://api.github.com/users/pichi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-31T05:32:06Z","updated_at":"2017-08-31T05:32:06Z","closed_at":null,"author_association":"NONE","body":"Shell: bash/zsh\r\nOperating system: Linux\r\nLiquid Prompt version (tag, commit): master 9c80396\r\n\r\n/proc/loadavg contain load but liquidprompt show CPU percentage. There is not a way to transform load into the percentage. The load is traditionally defined in queue theory as an average number of processes waiting for execution. Imagine this hypothetical example. You have 100 processes scheduled at the start of each second and each process takes 10ms to execute and one CPU to run it. Then your load would be 50 but your CPU utilization would be 100%. Then you take one process running non-stop. Your CPU utilization would be 100% but your load would be 0 or 1 depending if you include running process into load calculation which Linux does. But I'm not sure. Anyway, the load could be way over 1 on single CPU system and CPU utilization could never be over 100%. Unfortunately, this is exactly what I see using liquidpromp, CPU over 100% shown in white. It is not right. Correct way how to compute CPU utilization is to read the first line of /proc/stat\r\n\r\nSomething like\r\n```\r\n$ read _ user nice system idle iowait irq softirq steal guest guest_nice eol < /proc/stat\r\n$ old_cpu_sum=$(( user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice ))\r\n$ old_cpu_idle=$idle\r\n# after some while, command, next promptrendering, ...\r\n$ read _ user nice system idle iowait irq softirq steal guest guest_nice eol < /proc/stat\r\n$ new_cpu_sum=$(( user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice ))\r\n$ echo $(( 100 - (old_cpu_idle - idle) * 100 / (old_cpu_sum-new_cpu_sum) ))%\r\n29%\r\n```\r\nAnd now this is right CPU usage value.\r\n"}}
{"actor":{"display_login":"pichi"}}