htop icon indicating copy to clipboard operation
htop copied to clipboard

Implement Network & Disk IO support on MacOS

Open pbrena opened this issue 3 years ago • 22 comments

Hello the sudo htop running in my MacMini, macOS Catalina cannot be setup to display Network & Disk IO as the one running in my raspberry Linux can. How do I enable it?

pbrena avatar Nov 26 '22 21:11 pbrena

For MacOS, the necessary functions to determine the disk and network I/O are not implement.

Thus in order to activate these meters, a working implementation for Platform_getDiskIO and Platform_getNetworkIO in darwin/Platform.c is required.

BenBE avatar Nov 28 '22 09:11 BenBE

I see... Should I close this?

Is it still possible installing any (maybe 3rd party) SW? or... is it something that could be suggested as improvement?

pbrena avatar Nov 28 '22 16:11 pbrena

We can just update this ticket as a feature request to implement these missing functions, although I doubt there will be any work from inside the core team as noone here really works on darwin …

BenBE avatar Nov 28 '22 17:11 BenBE

ok, Thx!

pbrena avatar Nov 28 '22 18:11 pbrena

I'll try to implement Platform_getDiskIO for Darwin. This may take some time, since I'm kind of busy recently.

UeiWang avatar Apr 16 '23 10:04 UeiWang

That sounds great, please keep me posted. On Sunday, 16 April 2023, 04:45:16 AM GMT-6, UeiWang @.***> wrote:

I'm interested in implementing Platform_getDiskIO for Darwin. This may take some time, since I'm kind of busy recently.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

pbrena avatar Apr 16 '23 21:04 pbrena

@pbrena you can now test the Disk IO Meter for Darwin by building the latest commit of #1228 (if your local repository is already configured, run ./autogen.sh and ./configure before building). Please pay special attention to if "Disk IO" in the Disk IO Meter may exceed 100% even when no external drive is connected to your machine.

UeiWang avatar Apr 18 '23 14:04 UeiWang

i will, thx On Tuesday, 18 April 2023, 08:10:14 AM GMT-6, UeiWang @.***> wrote:

@pbrena you can now test the Disk IO Meter for Darwin by building the latest commit of #1228 (if your local repository is already configured, run ./autogen.sh and ./configure before building). Please pay special attention to if "Disk IO" in the Disk IO Meter may exceed 100% even when no external drive is connected to your machine.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

pbrena avatar Apr 19 '23 06:04 pbrena

I'll also work on the Network IO Meter for Darwin :)

UeiWang avatar Apr 23 '23 05:04 UeiWang

geat, thx On Saturday, 22 April 2023, 11:33:10 PM GMT-6, UeiWang @.***> wrote:

I'll also work on the Network IO Meter for Darwin :)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

pbrena avatar Apr 23 '23 19:04 pbrena

Hello Uei, Here I attach some screenshots of Htop dev and macos disk activity monitor, to show htop indeed often reports above 100% (even 2000%, that looks strange)... My particular HW is odd, I guess... its a Monterey running in macmini 2011 (with Opencore patch) with a Fusion drive = (SATA SDD plus a Sata HDD) for Systems drive and a USB HDD for User Data. Thx Pablo

On Tuesday, 18 April 2023, 08:10:14 AM GMT-6, UeiWang ***@***.***> wrote:  

@pbrena you can now test the Disk IO Meter for Darwin by building the latest commit of #1228 (if your local repository is already configured, run ./autogen.sh and ./configure before building). Please pay special attention to if "Disk IO" in the Disk IO Meter may exceed 100% even when no external drive is connected to your machine.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

pbrena avatar Apr 24 '23 22:04 pbrena

@pbrena Unfortunately there are no screenshots visible in your comment. Also the borked filtering of email-to-GH comment makes your notes hard to read. Please prefer to use the web UI (or the app) as comments done that way don't end up with loads of gibberish between the signal …

BenBE avatar Apr 24 '23 22:04 BenBE

sorry, about it...

unfortunatelly, i found no way to attach images...


Hello Uei,

Here I attach some screenshots of Htop dev and macos disk activity monitor, to show htop indeed often reports above 100% (even 2000%, that looks strange)... My particular HW is odd, I guess... its a Monterey running in macmini 2011 (with Opencore patch) with a Fusion drive = (SATA SDD plus a Sata HDD) for Systems drive and a USB HDD for User Data.

Thx Pablo

pbrena avatar Apr 24 '23 23:04 pbrena

Hello Uei, Here I attach some screenshots of Htop dev and macos disk activity monitor, to show htop indeed often reports above 100% (even 2000%, that looks strange)... My particular HW is odd, I guess... its a Monterey running in macmini 2011 (with Opencore patch) with a Fusion drive = (SATA SDD plus a Sata HDD) for Systems drive and a USB HDD for User Data.

@pbrena Hello Pablo, I can reproduce the problem on my MacBook Pro 2019 running macOS Ventura 13.3.1 (see #1228). I'll try to debug this.

UeiWang avatar Apr 25 '23 03:04 UeiWang

thx, it seems drag and drop may attach them.....so far it looks awesome

Screen Shot 2023-04-24 at 15 50 54 Screen Shot 2023-04-24 at 15 51 32

pbrena avatar Apr 25 '23 04:04 pbrena

sometimes they drop bellow 100%, no git update has been done

Screen Shot 2023-04-26 at 11 49 44 Screen Shot 2023-04-26 at 11 49 19

pbrena avatar Apr 26 '23 18:04 pbrena

I used fprintf to print the values of relevant variables (for the source code see branch debug of UeiWang/htop, for sample debug outputs which reproduce the bug see diskio.log), and found out that the problem may be that during an interval, the increase in the total read/write time of a disk obtained by I/O Kit may be much (sometimes more than 10x) larger than the length of the interval obtained by clock_gettime....

Replacing clock_gettime with clock_gettime_nsec_np (a non-portable Darwin alternative to clock_gettime) doesn't fix the problem, and the affected disks include the built-in SSD of my laptop and my portable SSD (in diskio.log mentioned above, there are consecutive lines starting with "read time: ", "write time: ", "read time: ", "write time: ", "read time: ", and "write time: ". The first two lines correspond to the built-in SSD, and lines 3-4 to my portable SSD.).

UeiWang avatar Apr 27 '23 13:04 UeiWang

Looking at the values in your diskio.log it seems as if you have a value type confusion in your calculation. The values are given in nanoseconds, but scaled by your code to be in milliseconds (so far so good). The output to the user then tries to convert that difference of milliseconds to a percentage value. Instead you would need to calculate the difference between the old (cached total time) value to the new (queried total time) one in relation to the old timestamp vs. the current one (scaled by 100 to get %). Further scaling has to be done to account for the number of disks in the system (e.g. for 2 disks divide by 2 accordingly).

BenBE avatar Apr 27 '23 19:04 BenBE

Thank you for you help!

The output to the user then tries to convert that difference of milliseconds to a percentage value. Instead you would need to calculate the difference between the old (cached total time) value to the new (queried total time) one in relation to the old timestamp vs. the current one (scaled by 100 to get %).

But I think DiskIOMeter_updateValues in DiskIOMeter.c is correct in calculating "Disk IO" by the formula 100 * (queried disk time - cached disk time) / (new timestamp - old timestamp).

Further scaling has to be done to account for the number of disks in the system (e.g. for 2 disks divide by 2 accordingly).

But htop doesn't do such scaling on Linux, and I think it's important to be consistent on different platforms.

IMHO the problem may lie in the disk read/write time returned by I/O Kit, since the intervals between the timestamps (passedTimeInMs in diskio.log in my previous comment) are stable, it's not likely that system timestamps can be wrong, and it's the disk read/write time that sometimes becomes abnormally large. Maybe some bugs in the disk drivers?

UeiWang avatar Apr 30 '23 07:04 UeiWang

Hello Uei, I just issued a git pull but failed to find the Netmeter +++++++++++++++++ On branch main Your branch is up to date with 'origin/main’. ++++++++++++++++

reading the link above... IIUC, it was added to the tag 3.3.0 but the last tag I find is 3.2. x, Am I missing something?

Screen Shot 2023-05-20 at 16 01 55

pbrena avatar May 20 '23 22:05 pbrena

Hello Uei, I just issued a git pull but failed to find the Netmeter +++++++++++++++++ On branch main Your branch is up to date with 'origin/main’. ++++++++++++++++

Note, that the new feature is not yet merged in this repository of htop and thus you need to import those changes from cloning https://github.com/UeiWang/htop (branch main) instead. Also new meters aren't added automatically, thus you need to add this new meter via the setup screen manually.

You can check you've got the right repository by running git remote -v show, which will list all the sources git is importing commits from.

reading the link above... IIUC, it was added to the tag 3.3.0 but the last tag I find is 3.2. x, Am I missing something?

3.3.0 is the version where this is planned to be added; once the PR passed review and any remaining issues have been cleared. As you can see in the progress bar below the "Milestone", this overall release is still WIP.

BenBE avatar May 21 '23 08:05 BenBE

Im so sorry Uei,

All my fault, my confusion started by my complete forgeting of how I managed to add the diskIO in the 1rst place this time I hadnt even compiled the source and expected the change to magically pop up in the setup menu (embarrassing and scary).

I can confirm that the NetIO is up and running, lovely!, nevertheless DiskIO dont go to beyond the 1000s/100 as before, but still can peak in the 100s now as seen in the image .

Thanks so much Screen Shot 2023-05-21 at 11 20 38

pbrena avatar May 21 '23 17:05 pbrena