Profiling Report example
We are trying to get to a report that looks like this. This will show every code section you have chosen to profile along with the results and the context. This should help you identify which areas of code to focus on.
Profiling concept
A simple profiling session might have a structure like this
- cProcTimer – an instance of this class is created for every section
- cProcProfiler – an instance of this class is created for every profiler.
- ProcProfileWrapper – this module provides a few procedures to set up the data structures, and provides a ready made public instance of cProcProfiler for you to use. It also contains an example as below
- ptLevels – an enum allowing you to vary the depth of analysis without changing the profiling calls throughout your code
Example
Sub exampleProfile() Dim i As Long ' create defaultprofiler, and start Call procProfilerConstruct(, ptLevelAll) ' ' ... some code ' Call procProfiler.Start("Manager", "example Profile", ptLevelLow) ' ' ... some code ' ' pause timing to collect user input ' Call procProfiler.Pause("Manager") ' MsgBox ("restart timing") ' Call procProfiler.Start("Manager") ' ' some more code ' For i = 1 To 100 Call exampleprofilesub Next i ' ' some more code ' Call procProfiler.Finish("Manager") ' ' all over ' Call procProfiler.FinishProfiler ' ' report results ' Call procProfiler.Results(Range("ResultSheet!a1")) ' ' clean ' Call procProfilerDestroy ' End Sub Sub exampleprofilesub() ' ' some more code ' Dim i As Long, d As Double Call procProfiler.Start("Sub", "exampleprofilesub", ptLevelMedium) ' 'some more code For i = 1 To 1000 Call procProfiler.Start("Random loop", "exampleprofilesub", ptLevelHigh) d = Sqr(Rnd(i)) * Sqr(Rnd()) Call procProfiler.Finish("Random loop") Next i ' ' some more code ' Call procProfiler.Finish("Sub") End Sub
cProcProfiler Class
cProcTimer Class
ProcProfilerWrapper Module
ptLevels enum
You will see that both the cProcTimer class and the cProcProfiler class reference a level. The main use of this is enable you to filter which sections to profile without having to change any of your code, aside from the initial call to construct the profiler
For help and more information join our forum, follow the blog or follow me on Twitter