Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why dotmemory can't collect memory traffic and stack trace info when try to attached to a live process

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.

like image 661
gfan Avatar asked Dec 15 '14 12:12

gfan


People also ask

What is unmanaged memory in dotMemory?

114.47 MB total means that the application consumes 114.47 MB of memory in total. This size is equal to Windows Task Manager's Commit size: the amount of memory requested by a process. The total value consists of: Unmanaged memory: memory allocated outside of the managed heap and not managed by Garbage Collector.

What does memory traffic mean?

To identify and analyze such issues, you should examine the so-called memory traffic. Traffic information shows you how many objects (and memory) were allocated and released during a particular time interval.


1 Answers

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.

EDIT: Since the version 2021.3 dotMemory also supports gathering allocations data using Windows ETW, so it's possible to get it even in case of attaching the profiler to an already running process.

like image 63
Ed Pavlov Avatar answered Nov 26 '22 13:11

Ed Pavlov