tmux-plugins / tmux-cpu

Plug and play cpu percentage and icon indicator for Tmux.
MIT License
444 stars 69 forks source link

use correct value if running on FreeBSD #7

Closed Wayneoween closed 8 years ago

Wayneoween commented 8 years ago

One can now have that feature working even on FreeBSD machines. Tested on OSX 10.11.2 and FreeBSD 10.2.

ctjhoa commented 8 years ago

Thanks for your PR @Wayneoween , you give me the idea to generally use the iostat method and fallback on the old way if there's no iostat installed. I'm currently working on a common method. Now I can test on OSX and ArchLinux but I can't check my command on FreeBSD. Please can you confirm the ouput of this on FreeBSD:

iostat -c | tr -s ' ' ';' | grep -e '^;' | cut -d ';' -f 2

Thanks

Wayneoween commented 8 years ago

A common method is a better idea indeed.

The -c without a 1 as argument does not work (neither on OSX nor on FBSD).

[me@freebsd ~]$ iostat -c | tr -s ' ' ';' | grep -e '^;' | cut -d ';' -f 2
iostat: option requires an argument -- c
usage: iostat [-CdhIKoTxz?] [-c count] [-M core] [-n devs] [-N system]
          [-t type,if,pass] [-w wait] [drives]

The iostat output with the least possible output without omitting the values we are interested in seems to be iostat -c 1 cpu but this does not work on OSX.

I figure I give you the iostat ouput:

[me@freebsd ~]$ iostat -c 1
       tty            ada0            pass0             cpu
 tin  tout  KB/t tps  MB/s   KB/t tps  MB/s  us ni sy in id
   2  1262 23.20  13  0.30   0.00   0  0.00   2  1  1  0 97

for comparison this is the same call on OSX:

[me@osx ~]$ iostat -c 1
          disk0           disk1       cpu     load average
    KB/t tps  MB/s     KB/t tps  MB/s  us sy id   1m   5m   15m
   56.67   1  0.05    25.09  23  0.55   3  1 96  1.36 1.22 1.16

In either case one could invert the id value or has to sum up us and sy.

ctjhoa commented 8 years ago

Ok I found the FreeBSD man page of iostat and options are quit different from the linux version.

-c on linux is for display only CPU but in BSD it's for delay.

Here is my ouput from iostat:

ctjhoa@localhost ~ % iostat                                                                                              
Linux 4.3.3-2-ARCH (localhost)  01/13/2016      _x86_64_        (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           7.80    0.03    1.30    0.14    0.00   90.72

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
scd0              0.00         0.02         0.00         80          0
sdb              11.39       115.93       554.53     504452    2413009
sda               0.03         0.96         0.00       4172          0
sdc               0.02         0.48         0.00       2108          0
Wayneoween commented 8 years ago

I got the idle value with the following line:

[me@freebsd ~]$ iostat |tail -1 |tr -s ' ' ';' |sed -e 's/^;//' | cut -d ';' -f 13
97

Since grep -e does behave differently on FreeBSD, too.

With OSX the line could read like this:

[me@osx ~]$ iostat |tail -1 |tr -s ' ' ';' |sed -e 's/^;//' | cut -d ';' -f 9
97
ctjhoa commented 8 years ago

Damn that's so incredible in 2016 that's so difficult to get this basic information... Anyway I merge your PR and I'll try to find something for Linux.

Thank you