Wednesday, February 8, 2012

How To Time Things

I’ve found myself in several situations lately where I have VMs being paused for various reasons. Since this means there will be some measure of downtime, people often ask how much downtime they can expect.

How do you figure that out?

I use a script that writes the current date / time once every second to a file. I start running this script just before pausing the VM, then take a look at the file once the VM is back online to see how big the time gap is.

Here is my script for Linux:

while true; do date >> datelist; sleep 1; done

And for Windows, I create a BATch file:

@echo off
:again
date /t >> datelist
time /t >> datelist
goto again

You could easily adapt these simple scripts to time a lot of different things by combining them with ping, checking the status of another file, starting / killing this script via another script to see how long something runs, or just running these scripts as-is to eyeball a timing on something.