Analyzing DevHealth Runs Easily

This is documentation of a tool created in November 2008.

Our team became fairly dependent on analyzing DevHealth runs when debugging memory issues.  We would run DevHealth automatically every few minutes as our applications were used for a longer period of time.  Tracking memory usage for a handful of processes over an hour so became extremely tedious and time consuming.

I wrote a small application to parse through any number of successive DevHealth outputs and produce a csv file, a row for every executable and the memory usage in bytes as the columns.  It became so easy to deploy new code, use our software for an hour or so, and within minutes have a graph of memory usage for every process we cared about.  We tracked our apps in addition to gwes (graphics, windowing, and events subsystem) and our database engine.

I will post the source soon.  I originally wrote it as an in-house exec where we had to specify the apps to watch at design time.

Memory usage was calculated as the following: heap usage, code usage (non-ROM), r/o data, r/w data (page, stack, etc.) In DevHealth symbols with a 4096 byte page size:
(r/w(r, rw, E, D, H) + c + R + p + S) * 4096

Posted in Windows Mobile

Reloading device drivers in Windows Mobile

This is documentation of a fix found in late November 2008.

Our team was plagued by a GPS COTS product that would intermittently not clean up the GPS COM port when closing. An unrecoverable error would occur if our code tried to open the COTS product a second time after it failed to close the port. After going back and forth with the vendor and no solution, it came on us to work around it. I first tried to toggle the power to GPS chip using

SetDevicePower("COM5:", POWER_NAME, 4); //unpowered
SetDevicePower("COM5:", POWER_NAME, 0); //full power

which didn’t seem to do anything. After a lot of searching through MSDN I found these two native calls that saved our release to test. They completely reloaded the driver making the COM port usable again.

BOOL DeactivateDevice(HANDLE hDevice);
HANDLE ActivateDevice(LPCWSTR lpszDevKey, DWORD dwClientInfo);

The handle for the device can easily be found in the registry in HKLM\Drivers\Active. Look for your device as a subkey and provide that same name to ActivateDevice to reload the driver.

Posted in Windows Mobile