Memory profiling with Visual Studio 2010

谁说我不能喝 提交于 2019-12-11 05:48:16

问题


I have a solution with two applications. One is Windows Service project, another one is launcher (installs and starts the windows service). I want to attach memory profiler to the installed windows service to collect information about memory usage and object sizes to investigate the OutOfMemory exception.

Here is the approach I used.
First I ran the "VSPerfCLREnv.cmd /samplegclife". This should init the profiling environment variables to enable memory profiling.
Then I start my launcher, which launches the service.
Finally VS 2010 -> Analyze -> Profiler -> attach (to the windows service).

But when the profiling is stopped I cannot see any information about object sizes or memory usage.
Am I doing something wrong?


回答1:


Actually it meant that the memory of object has been corrupted while storing the data...To Exclude this you have to invoke garbage collector like GC.collect() and free's the unused memory by assigning null...For Example:string sTest="Tested";string sAssign=sTest;sTest=null; To View total memory of an object use GC.GetTotalMemory(false);




回答2:


I found out.
To attach the profiler to .net process to collect memory data you should follow these steps:

1. Initialize the profiling environment variables:
VSPerfClrEnv /globalsamplegc
Reboot PC.

2. Start profiling session:
VSPerfCmd /start:"sample" /output:"C:\log.vsp" /crosssession

3. Attach the profiler to the process:
VSPerfCmd /attach:[PID]

4.To stop profiling:
VSPerfCmd /detach
VSPerfCmd /shutdown

For more information refer to this.



来源:https://stackoverflow.com/questions/19906588/memory-profiling-with-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!