hindikaynen / NetMemoryProfiler

Ascon.NetMemoryProfiler is a set of APIs for memory analysis of .NET processes
Apache License 2.0
7 stars 2 forks source link

Trying to test ConsoleApp. System.InvalidOperationException: 'Unable to force GC.Collect on remote process' #1

Open rpokrovskij opened 6 years ago

rpokrovskij commented 6 years ago

.NET Framework 4.7;

There are two console applications: one create "load", other tryies to get profiling information. The second one throws an exception:

System.InvalidOperationException: 'Unable to force GC.Collect on remote process'

at Ascon.NetMemoryProfiler.GarbageCollectorRunner.ForceGarbageCollectionInRemoteProcess(Int32 pid) at Ascon.NetMemoryProfiler.Profiler.AttachToProcess(Int32 pid, UInt32 timeout) at Ascon.NetMemoryProfiler.Profiler.AttachToProcess(String processName, UInt32 timeout) at ProfilerAutomation.Program.Main(String[] args) in D:\cot\DashboardCode\Routines\Tests\ProfilerAutomation\Program.cs:line 14

Code (exception thrown on the first line)

            using (var session = Profiler.AttachToProcess("DashboardCode.Routines.Storage.EfModelTest.EfCore.NETFramework.Sandbox"))
            {
                var objects = session.GetAliveObjects(x => x.Type == "Microsoft.Extensions.Logging.LoggingFactory");
                var retentions = session.FindRetentions(objects);
                System.Console.WriteLine(DumpRetentions(retentions));
            }
hindikaynen commented 6 years ago

Managed injector which is used to force garbage collection on remote process uses the MainWindow handle to identify thread to run external code in it. There is no MainWindow in console application, so this approach doesn't work. I understand that it is a severe limitation. I'll look at this and let you know.

rpokrovskij commented 6 years ago

It would be nice to have a solution for WinService and ASP either. It can be a client part (three different client parts that stop app three different ways for a profiling session).

For a console app it can be a requirement to run all code in tasks with specific TaskSchedule (there is genre of C# tooling "write custom async manager for console app" use them as source of inspiration).