The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Phoenix on March 26, 2006, 12:06:37 AM

Title: Another HDD Activity Monitor
Post by: Phoenix on March 26, 2006, 12:06:37 AM
Based on MichaelW's HDD Activity Monitor code, i tried to find another way to show hdd activity without using pdh.dll-functions.

The attachment is another HDD Activity Monitor, based on DeviceIoControl from kernel32.dll using IOCTL_DISK_PERFORMANCE control code. It works on my WinXP Pro SP2-box and should also work on W2K boxes (the icons might look strange there, i was not able to test it yet).

ATA-, SATA and USB-Devices are monitored on my system in summary. Changes of USB-Devices caused problems (WM_DEVICECHANGE does not report DBT_DEVICEQUERYREMOVE/DBT_DEVICEREMOVEPENDING without a registration for device event notification) so the handles are retrieved in each timer procedure call as a workaround.

BTW, i needed to add four extra bytes to the DISK_PERFORMANCE struct, does somebody know the reason? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/disk_performance_str.asp

Regards, Phoenix

[attachment deleted by admin]
Title: Re: Another HDD Activity Monitor
Post by: Mark Jones on March 26, 2006, 03:02:10 AM
Nice Phoenix! I just noticed that "DiskMon" from System Internals has a "minimize to tray icon" feature, but it's nowhere near as fast or nice as HDDMon. That said, thier "FileMon" product doesn't exactly sync with HDDMon - sometimes FileMon shows activity when HDDMon doesn't, and vice-versa. HDDMon seems to be showing writes which are reads according to FileMon.

Curious, would it be possible to log which applications or threads read or write in HDDMon?
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on March 26, 2006, 09:13:15 AM
QuoteThat said, thier "FileMon" product doesn't exactly sync with HDDMon

Mark, it seems to me that DiskMon from System Internals logs requests for read/write operations, while HddMon ist reporting what has happend physically on the disk (MSDN: DeviceIoCcontrol: Number of Bytes written i. e.). This could possibly cause asynchronous behaviour (?)

AFAIK, DeviceIoControl has no options to trace applications or threads that cause disk activity.
Title: Re: Another HDD Activity Monitor
Post by: MichaelW on March 26, 2006, 10:45:43 AM
Phoenix,

Nice work, I like the ability to differentiate between reads and writes.

After experimenting with your code the only reason I can see that the four fill bytes would be required is that the function is returning the 8-character Unicode string "PhysDisk" in the StorageManagerName member, and the terminating 00 word overflows the structure. I have no idea why appending a word to the end of the structure will not correct the problem.

For my version I am now using a timer period of 30ms. I tested shorter timer periods but the apparent disk activity decreased, I think because for the shorter disk activity periods the indicator "on" time was too short to be readily visible. Compared to your version mine shows considerably more disk activity. After changing the timer period for your code to 30ms, both versions show, as nearly as I can tell, the same level of disk activity.

Under Windows 2000 the icons work OK, but on my system they are sized for young eyeballs. When I was experimenting with icons I tried an animated icon that was modeled after the icon that ZoneAlarm displays when there is Internet activity. Basically, the ZoneAlarm icon is two stacks with up to 5 bars each, with green bars for IN and red bars for OUT, and with the number of bars in each stack indicating the level of activity. My icon used just a single stack of green bars, and I calculated the number of bars to display from the % Disk Time value. I eventually discarded the design when I had some (relatively minor) problems with the icons not displaying correctly in the notification area, even though they would display correctly elsewhere, coupled with severe flicker problems. On my system the ZoneAlarm icon has the problem with not displaying correctly, but not the flicker problem.

Quote from: Mark Jones on March 26, 2006, 03:02:10 AM
Curious, would it be possible to log which applications or threads read or write in HDDMon?

This occurred to me too as potentially useful information, but I could see no way to do it without some very low-level code.

Title: Re: Another HDD Activity Monitor
Post by: Phoenix on March 26, 2006, 02:01:45 PM
Michael,

thank you for your feedback.

Quotethe function is returning the 8-character Unicode string "PhysDisk" in the StorageManagerName member

On my box the function is returning "Partmgr" in the StorageManagerName member, which is a 7-character Unicode string, causing the same problem. However, the four extra bytes seem to be always set to zero. Perhaps the structure member "WCHAR StorageManagerName[8]" is wrong in MSDN and should be "WCHAR StorageManagerName[10]" according to this:

From http://www.osronline.com/ddkx/storage/k306_950y.htm

QuoteStorageManagerName
Contains an 8-character string that indicates which device driver provided the performance statistics. In Windows® 2000, this can be either "LogiDisk" for the driver logidisk.sys or "PhysDisk" for the driver physdisk.sys. These drivers collect performance statistics for devices and physical disks respectively. In Windows XP and later operating systems, this can be any of the following three strings: "FTDISK" for the driver ftdisk.sys, "DMIO" for the driver dmio.sys, or PARTMGR" for the driver partmgr.sys. These three drivers collect performance statistics for basic disk volumes, dynamic disk volumes, and physical disks respectively. Note that these strings are 8-character case-sensitive strings with blank fill. For example, in the case of the string "FTDISK", the StorageManagerName character array should contain two trailing blanks ("FTDISK<b><b>"), and in the case of the string "DMIO", the array should contain four trailing blanks ("DMIO<b><b><b><b>").

So, at least one WCHAR for the terminating 00 is missing in the structure, but two WCHARs are needed...(Size=88 bytes => DWORD alignment?)

Quoteboth versions show, as nearly as I can tell, the same level of disk activity.

DeviceIoControl / IOCTL_DISK_PERFORMANCE seem to collect the data for the PhysicalDisk performance object (pdh.dll), your results may comfirm this.

QuoteCurious, would it be possible to log which applications or threads read or write in HDDMon?
This occurred to me too as potentially useful information, but I could see no way to do it without some very low-level code

There is an interesting topic on MSDN about tracing disk I/0 events using StartTrace function from Advapi32.dll:
http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/etw/etw/i_o_events.asp

QuoteYou can use the ThreadId members of EVENT_TRACE_HEADER to identify the thread that requested the IO operation. If you also collect process and thread events, you can trace disk IO operations to a process.

QuoteUnder Windows 2000 the icons work OK, but on my system they are sized for young eyeballs.

Well, the design of these icons took more time than the coding itself... i have done at least five different sets but none of them is really satisfying. I think using something like the ZoneAlarm icon is a very good idea, but unfortunately i'm really no good designer... perhaps somebody has some good icons for this purpose?
Title: Re: Another HDD Activity Monitor
Post by: MichaelW on March 26, 2006, 08:03:07 PM
After building a test app with the Microsoft Visual C++ Toolkit 2003 it looks like the compiler is adding a 4-byte pad to the end of the structure. I'm guessing that this has nothing to do with alignment, it's just Microsoft silently hiding a mistake :toothy



[attachment deleted by admin]
Title: Re: Another HDD Activity Monitor
Post by: PBrennick on March 26, 2006, 08:19:16 PM
On my machine I have been watching the HDD LED and your red light and the two seem to be perfectly in sync.

Paul
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on March 29, 2006, 08:38:53 PM
Michael,

... a very strage strategy to hide an error, but Microsoft is always good for a surprise  :bdg

Well, i have tested HddMon on my office W2K box, and i needed a magnifying glass to see the icons... The attached file is HddMon with another set of icons (handmade, tested with W2K and XP) and some minor modifications in the Timer proc.

Phoenix

[attachment deleted by admin]
Title: Re: Another HDD Activity Monitor
Post by: MichaelW on March 29, 2006, 09:54:16 PM
Thanks Phoenix,

Under Windows 2000 the new icons look great in Explorer, but in the notification area the diagonal edges are visibly jagged, and irregular.

BTW, the code to restore the foreground window does not work (this should have been obvious to me), and making it work would involve too much monkey motion, so I just eliminated it from my version.

Title: Re: Another HDD Activity Monitor
Post by: Mark Jones on March 29, 2006, 09:56:17 PM
Great work. Here's a RadASM project file and some alternate icons. Not as pretty but can't miss 'em.

[attachment deleted by admin]
Title: Re: Another HDD Activity Monitor
Post by: Emperor on March 30, 2006, 12:13:19 PM
Works great on my computer :bg

Just love the icons!
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on March 30, 2006, 09:45:50 PM
MichaelW,

Thanks! Only the rw.ico has a 32X32 and a 16x16 icon, the others are 16x16 only... so they look jagged, i should add 32x32 icons to the others too. BTW, what exactly does not work? I can see nothing wrong with restoring the foreground window code....

Mark,

Thank you for your icons! I'm just working on a similar set based on these icons.

Emperor,

thank you for your feedback. Works on XP or W2K?
Title: Re: Another HDD Activity Monitor
Post by: MichaelW on March 30, 2006, 10:27:19 PM
As I stated, the icons look great everywhere but the notification area, and I think you made good choices on the design. Now that I look at the na icon in an icon editor, I see that the colors are irregular, and this might contribute to what I am seeing, but I think the real problem is something in the way Windows 2000 handles the notification area.

On my Windows 2000 system, the first SetForegroundWindow works, so the menu closes properly when you open it and then click somewhere else, but the second SetForegroundWindow fails when you do this.

And I think this behavior should be the same on Windows XP:

MSDN: SetForegroundWindow (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setforegroundwindow.asp)


          Invoke GetForegroundWindow
          push   eax
          Invoke SetForegroundWindow, hWin

          Invoke GetCursorPos,addr pt
          Invoke TrackPopupMenu, hPopupMenu, TPM_RIGHTALIGN,
            pt.x, pt.y, NULL, hWin, NULL

          pop    eax
          Invoke SetForegroundWindow, eax
          .IF eax == 0
            MsgBox 0,"SetForegroundWindow failed",0,0
          .ENDIF

Title: Re: Another HDD Activity Monitor
Post by: PBrennick on March 30, 2006, 11:30:13 PM
Phoenix,
Looks great on my XP box!

Michael,
What means 'notification area?'

Paul
Title: Re: Another HDD Activity Monitor
Post by: MichaelW on March 31, 2006, 01:38:16 AM
Hi Paul,

taskbar notification area, AKA system tray

Title: Re: Another HDD Activity Monitor
Post by: PBrennick on April 01, 2006, 05:47:40 AM
Thanx Michael, I guess I should feel stupid about that question.  Just wasn't thinking.  BTW:  I like these HDD monitors a lot, easier than looking on the floor at the tower, or trying too!

Paul
Title: Re: Another HDD Activity Monitor
Post by: Mark Jones on April 03, 2006, 09:44:15 PM
I agree! HDDMon had alerted me to the fact that something is writing to my disk at least twice a second, still unsure exactly what's doing it but I never would have seen it without HDDMon! :bg

Back in the days of Windows 3.1, there was a great utility that loaded as a DOS TSR and displayed a text overlay in the top-right corner of the screen. It used black text on red and green colored text backgounds and looked something like this: 00: 01:, indicating which physical disk was being accessed and wether it was being written to or read from. Slick! I loved that thing. :toothy

Any chance HDDMon could see a GUI overlay option like this? That would be really nice. Might be able to utilize faster refresh rates too.
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on April 04, 2006, 06:18:12 PM
Thank you all for your help and feedback. In fact, i am looking for different ways to show extended information about disk access in the taskbar notification area by another iconwidth for example (this led me to privilege management which should probably not be posted) or something on the desktop that does not take too much place. And yes, customizing of timersettings or similar should be done (and allow to choose one of the seven iconsets i'm testing right now on W2K and XP  :lol )

Regads Phoenix
Title: Re: Another HDD Activity Monitor
Post by: Ghirai on April 04, 2006, 10:37:22 PM
Very weird, after i left it running for some time, it stopped working (showing NO activity at all), while i was searching for files, arhiving, etc.
The Motherboard LED was showing activity.

Restarting the app didn't help...

Any ideas?

I'm running XP Pro SP2, AMD Athlon 64 3000+, 2 GB RAM, and a 300 GB Maxtor.
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on April 04, 2006, 11:30:39 PM
Ghirai,

i have no idea. Did the tooltip show information about the number of drives detected? It should report at least "1 drive detected" for your Maxtor.
Title: Re: Another HDD Activity Monitor
Post by: Ghirai on April 05, 2006, 10:09:59 AM
Yes it did.

Even after restarting the box it wouldn't want to work.

I remember downloading your app some time ago, tested, and it didn't work.
I forgot about it, and downloaded again 2-3 days after that, when it seemend to work fine.
Title: Re: Another HDD Activity Monitor
Post by: Mark Jones on April 05, 2006, 06:20:21 PM
Is the drive an external, USB, firewire, removable or something? Does it standby/powerdown from a BIOS inactivity timer? Maybe PDH.DLL crashed and burned? :dazzled: (no that couldn't be...)
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on April 05, 2006, 06:35:54 PM
Ghirai,

i have still no idea what happens...

Mark,

HddMon should work perfect with at least USB-Devices, i have tested it over and over again (on W2K SP4 and XP pro SP2). Unfortunately there is no chance for me to test it with firewire storage devices. BTW, HddMon does not use pdh.dll but DeviceIoControl from kernel32.dll.

If the device-number shown in the tooltip is > 0, and there is no activity shown... possibly a problem with displaying the icon.. i can't find anything going wrong. I did an 1.8-gig backup with 7z and resulting heavy disk activity today at office, no problem.

Anybody else with a similar problem?

Regard, Phoenix.
Title: Re: Another HDD Activity Monitor
Post by: Ghirai on April 05, 2006, 06:44:49 PM
Forgot to say, the HD is a standard IDE HD, nothing special.

It still doesn't work, and it doesn't work an my laptop anymore, but it does work at the computers at work (also an IDE HD).

It's a shame, couse i really like the app, and i added it to startup, but nothing... :(
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on April 05, 2006, 10:18:13 PM
The attached file contains HddMon with an error report via Console for Shell_NotifyIcon call and DeviceIoControl call. You can easily add error tracing for other functions, but i guess the most probable reason is DeviceIoControl.

This teached me, that USB-Devices are detected, but their drivers do NOT support IOCTL_DISK_PERFORMANCE requests.... Error number 50: Request not supported  :red



[attachment deleted by admin]
Title: Re: Another HDD Activity Monitor
Post by: PBrennick on April 06, 2006, 04:50:38 AM
On my machine (XP), neither of the monitors that can be found here report any of my USB drives (2 sticks and 1 platter type.  Whatever, I don't know how to decribe them.)  The platter type is on the floor under my table and the cat loves to sleep on top of it and really gets miffed if I shut the system down.

The USB drives  not being reported is no big deal AFAIAC.
Paul
Title: Re: Another HDD Activity Monitor
Post by: Ghirai on April 06, 2006, 11:32:56 AM
Strange, when i started up by pc thismorning, it worked fine, and it still does :eek
Title: Re: Another HDD Activity Monitor
Post by: John on April 18, 2006, 02:45:27 PM
Phoenix,
This is exactly what I had in mind when I posted a question about it a few weeks ago (http://www.masmforum.com/simple/index.php?topic=4108.0). I never could get the pdh.dll version working but this works perfectly.

Nice work!  :U
Title: Re: Another HDD Activity Monitor
Post by: John on April 19, 2006, 01:57:32 PM
I'm having problems on my home computer. It is an eMachines T6520 XP Pro with SP2, 2 Physical drives with one partioned into two logical drives, 4 removeable drives (none with disks inserted), one USB CF card reader (no disk inserted), and two CD drives. 1 gig of ram and a 2.4 ghz AMD processor (3400+). The errors reported when I run the one with errors reported are 1: Incorrect Function and 50: The request is not supported. The icon doesn't change at all.

It works great on my work computer though.
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on April 19, 2006, 07:44:45 PM
QuoteI'm having problems on my home computer.

Very strange. I have no clue. "The request is not supported" error is at least caused by the USB CF reader and the CD Drives. However, the physical drives should be reported anyway, if they are IDE/ATAPI/SATA. (BTW, nice Box! do you use the standard windows XP drivers?)  Can you tell me where the "Incorrect Function" error comes from? Possibly from Shell_NotifyIcon?

I am just testing another version of HddMon, this one checks disk activity by volumes and shows info per volume in a small dialog. As soon i get this one working, i will post it - it should be easier to track errors because of different ways of drawing.

Regards, Phoenix
Title: Re: Another HDD Activity Monitor
Post by: John on April 19, 2006, 07:54:39 PM
Hi Phoenix,
I was actually having an unrelated problem, so as a last ditch effort, before I have to breakdown and reformat/start from scratch, I reinstalled Windows. HDDMon is working now so I can't tell you where that Incorrect Function error was coming from. I do use the standard XP drivers AFAIK.
Title: Re: Another HDD Activity Monitor
Post by: Phoenix on April 19, 2006, 10:15:58 PM
Hi John,

I'm sorry about your problems, but it good to hear that HddMon is now working on your box!  :dance: