怎么监视跟踪一个进程(Process)中的dll的详细性能(performance)【asp.net C#】
This tutorial will show how to instrument a unit test DLL for performance profiling. Visual Studio will allow you to do performance profiling on individual tests (i.e. functions) in a test suite. This can be done in the user interface (i.e. UI or IDE). However if you have a unit test DLL that contains lots of unit tests or test methods, it’s apparently not possible to do performance profiling in the IDE.
Here was my original question:
Question on MSDN forums
I have a MS Unit Test DLL written in C# that targets a C++/CLI managed assembly. I have roughly 60 unit tests in that unit test dll. What I would like to do is run all the unit tests under the performance profiler, in the IDE. That is using the performance explorer to run a performance session for all the unit tests in my test DLL. I know how to do this from the command line, but I feel that is a last resort. I’d like to do this in the IDE if possible. It is possible to create a performance session for one unit test in the unit test DLL. The steps are listed here: ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vsetlt01/html/4cc514d2-47bd-4f1c-a039-5ffae7c68bf1.htm i.e. Right click over a test result, and select "Create Performance Session". Whereupon the Performance Explorer will show a new session based off of one unit test. That’s great, but I’ve got 60 unit tests in my DLL. I don’t want to have to create 60 performance sessions.
PreparationBuild the code that you will be testing. In my case it was the following DLL’s (Assuming a common root folder)
DLL name
Description
..\ManagedAPI\Win32\Debug\UnderstandWrapper.ManagedAPI.dl The DLL with the code I wanted to test
..\UnitTest\bin\x86\Debug\UnitTest.dll This DLL contains my unit tests
Then just to play it safe, run all the unit tests (This can be done in the IDE) in UnitTest.dll. It pays to be paranoid like this since if you want to detect bugs early and swiftly.
Now the strategy for profiling an entire DLL is to:
Instrument the DLL. This means to inject performance related commands into the code. Don’t worry it’s perfectly safe.
Turn on performance profiling via a global command.
Run your unit tests. Here is where the real work gets done.
Turn off performance profiling via a global command. (A results file gets saved somewhere).
Un-Instrument the DLL. This means restoring it to it’s original state. (i.e. Don’t ship a DLL with performance profiling enabled).
Instrument the BinariesI instrument my DLL’s using the following batch script called: Instrument_ON.bat
@echo off
@echo Instrumenting Binary
set VS90TEAMTOOLS="%VS90COMNTOOLS%..\..\Team Tools\Performance Tools\"
%VS90TEAMTOOLS%\VSInstr.exe ..\ManagedAPI\Win32\Debug\UnderstandWrapper.ManagedAPI.dll
%VS90TEAMTOOLS%\VSInstr.exe ..\UnitTest\bin\x86\Debug\UnitTest.dll
pause
@echo on
The results of instrumenting it looks like this:
Instrumenting Binary Microsoft (R) VSInstr Post-Link Instrumentation 9.0.30729 x86 Copyright (C) Microsoft Corp. All rights reserved.
File to Process: F:\CodePlex\UnderstandAPI\Managed\ManagedAPI\Win32\Debug\UnderstandWrapper.ManagedAPI.dll –> F:\CodePlex\UnderstandAPI\Managed\ManagedAPI\Win32\De bug\UnderstandWrapper.ManagedAPI.dll Original file backed up to F:\CodePlex\UnderstandAPI\Managed\ManagedAPI\Win32\Debug\UnderstandWrapper.ManagedAPI.dll.orig
Successfully instrumented file F:\CodePlex\UnderstandAPI\Managed\ManagedAPI\Win32\Debug\UnderstandWrapper.ManagedAPI.dll. Warning VSP2013 : Instrumenting this image requires it to run as a 32-bit process. The CLR header flags have been updated to reflect this. Microsoft (R) VSInstr Post-Link Instrumentation 9.0.30729 x86 Copyright (C) Microsoft Corp. All rights reserved.
File to Process: F:\CodePlex\UnderstandAPI\Managed\UnitTest\bin\x86\Debug\UnitTest.dll –> F:\CodePlex\UnderstandAPI\Managed\UnitTest\bin\x86\Debug\UnitTest.dll Original file backed up to F:\CodePlex\UnderstandAPI\Managed\UnitTest\bin\x86\Debug\UnitTest.dll.orig
Successfully instrumented file F:\CodePlex\UnderstandAPI\Managed\UnitTest\bin\x86\Debug\UnitTest.dll. Press any key to continue . . .
Turn on MonitorI then turn on performance profiling using the following batch script called: Performance_ON.bat
@echo off
@echo Turning ON performance coverage session recorder
set VS90TEAMTOOLS="%VS90COMNTOOLS%..\..\Team Tools\Performance Tools"
%VS90TEAMTOOLS%\VsPerfCmd /start:trace /output:ManagedAPI.vsp
pause
@echo on
The results of this batch scripts looks like this:
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67200.html
- 上一篇:c#正则表达式用法大全
- 下一篇:windows 8.1 下蓝屏报错:SYSTEM