Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Inserting Profiling Marks

I'm using the Profiler of Visual Studio 2008 Development Edition. To perform "targeted profiling," I can manually set profiler filters through "marks" anytime I am attached to my currently-running test code. But I would like to insert the marks programmatically instead. I would like to add a call, instruction, or directive to my test code that, when executed, tells the profiler "this is a 'mark' called 'BeginWork'" and "this is a 'mark' called 'EndWork'".

Is there a way to do that? If not, does Visual Studio 2010 have that ability?

like image 737
Brent Arias Avatar asked Nov 29 '10 23:11

Brent Arias


1 Answers

You can use the Profiler API to insert marks programmatically. See the DataCollection.CommentMarkProfile method documentation on MSDN.

You just need to add a reference to Microsoft.VisualStudio.Profiler.dll from 'Program Files[ x86]\Microsoft Visual Studio 9.0\Team Tools\Performance Tools' to use the managed API.

Your test code could look something like:

MarkOperationResult result;
result = DataCollection.CommentMarkProfile(markID1, "BeginWork");
// Validate result...

SomeOperation();

result = DataCollection.CommentMarkProfile(markID2, "EndWork");
// Validate result...
like image 141
Colin Thomsen Avatar answered Nov 03 '22 18:11

Colin Thomsen