Automating DevHealth runs
Hope everyone had a good New Year. I was doing some Hopper runs on a partner device and gathering DevHealth logs to see memory usage over time. It was rather painful to manually collect the DevHealth logs since Hopper was interrupting me (did not have KITL so could not launch DevHealth from the Target Control Window) and I also wanted to run DevHealth at specific intervals, say every 60 minutes.
I decided to write a quick application to help me do this and now am sharing my experiences with you. The application I created as a no-frills command-line app. The pseudo-code for the application follows:
FOR i = 1 TO X
Create DevHeath Process
Wait until DevHealth Process has finished
IF I == X -1 THEN
Exit loop
Sleep for Y seconds
END FOR
Where X is the number of times you want to launch DevHealth to collect samples (for me this value was set to 25) and Y is the time between collecting the DevHealth logs (I set this at 3600 seconds). Some implementation notes is that you can use CreateProcess to create the DevHealth process and do a WaitForSingleObject on the process handle (returned via struct from CreateProcess) to wait until the process is finished.
Some improvements:
- Ensure only 1 instance of this application is running (i.e. make sure if Hopper tries to start another processing using this executable, don’t allow it). I’d probably use the Toolhelp API to enumerate the active processes and perform the check based on process name.
- Enable basic data logging. Creation of a small log file to mark the when DevHealth started collecting data, and when it stopped collecting data.
Hope this will give you guys some ideas and save you time on collecting those DevHealth logs.