问题
I have an asp.net app, before the app can provide services, it needs to build a very large local cache. I want to profile a specific part of the code. My app is quite huge, I don’t want to profile it entirely. I just want to profile the code path that serves the request.
I start to use dotMemory to track my app memory usage. When I try to attach to a process,
the profiler options of two checkbox on the dialog: 1) collect every N-th object 2) collect memory traffic can't be checked.
Why dotMemory can't collect memory traffic and stack trace info when try to attached to a live process?
I also try to use the profiler API.
private void SomeMethod()
{
// Here goes your code
// ...
// Get a snapshot
if (MemoryProfiler.IsActive)
MemoryProfiler.Dump();
}
I can get a snapshot, but the app run first, then the profiler attatched after that. I can't get the memory traffic either.
回答1:
It is the restriction of Microsoft profiling api. The flag COR_PRF_ENABLE_OBJECT_ALLOCATED should be set before profiled process starts.
I would recommend you to try JetBrains dotTrace in "timeline" mode if you are not able to launch your application under dotMemory. It uses ETW providers to collect memory traffic statistics, and may help you in your problem.
p.s when you use profiling api do not forget to call MemoryProfiler.EnableAllocations if you want to collect stack traces.
来源:https://stackoverflow.com/questions/27483590/why-dotmemory-cant-collect-memory-traffic-and-stack-trace-info-when-try-to-atta