Whilst going through my blog roll on Feedly this weekend, I spotted Kevin Marquette’s blog post announcing his new Chronometer module.
At a high level it generates a script profiler timeline as you run through a script. Showing you how long each line takes to run, which lines weren’t run and how many times that line has been called.
I’ve just finished writing a number of functions for the dbatools module to implement some new restore functionality, this seemed like a great way to peer into my functions and see what was going on inside, and spot where I was spending most of the time. This should make it easier to work out where I needed to focus attention to improve performance.
At it’s simplest form it can be called like this:
$start = Get-Date $Chronometer = @{ Path = 'c:\dbatools\module\functions\Restore-DbaDatabase.ps1' Script = {Restore-DbaDatabase -SqlServer localhost\sqlexpress2016 -Path C:\dbatools\backups -WithReplace -OutputScriptOnly} } $results = Get-Chronometer @Chronometer -Verbose (New-TimeSpan -Start $start -End (Get-Date)).TotalSeconds
This took about 10 seconds to run on my test box and dumped out all the coverage for the Restore-DbaDatabase function.