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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With