Brent Arias
Brent Arias

Reputation: 30165

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?

Upvotes: 11

Views: 3462

Answers (1)

Colin Thomsen
Colin Thomsen

Reputation: 1806

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...

Upvotes: 11

Related Questions