Profiling after exit()

Eugene Wissner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 27 07:30:33 PDT 2017


I have a multi-threaded application, whose threads normally run 
forever. But I need to profile this program, so I compile the 
code with -profile, send a SIGTERM and call exit(0) from my 
signal handler to exit the program. The problem is that I get the 
profiling information only from the main thread, but not from the 
other ones.

Is there a way to get the profiling information from all threads 
before terminating the program? Maybe some way to finish the 
threads gracefully? or manully call "write trace.log"-function 
for a thread?

Here is a small example that demonstrates the problem:

import core.thread;
import core.stdc.stdlib;

shared bool done = false;

void run()
{
     while (!done)
     {
         foo;
     }
}

void foo()
{
     new Object;
}

void main()
{
     auto thread = new Thread(&run);
     thread.start;
     Thread.sleep(3.seconds);

     exit(0); // Replace with "done = true;" to get the expected 
behaviour.
}

There is already an issue: 
https://issues.dlang.org/show_bug.cgi?id=971
The hack was to call trace_term() in internal/trace. call_term() 
doesn't exist anymore, I tried to export the static destructor 
from druntime/src/rt/trace.d with:

extern (C) void _staticDtor449() @nogc nothrow;

(on my system) and call it manually. I get some more information 
this way, but the numbers in the profiling report are still wrong.


More information about the Digitalmars-d-learn mailing list