Profiling after exit()

Eugene Wissner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 28 01:06:33 PDT 2017


On Friday, 28 July 2017 at 06:32:59 UTC, Jacob Carlborg wrote:
> On 2017-07-27 16:30, Eugene Wissner wrote:
>> 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?
>
> As others have mentioned, you should in general avoid calling 
> "exit" in a D program. There's a C function called "atexit" 
> that allows to register a callback that is called after calling 
> "exit". You could perhaps join the threads there. I don't know 
> if that helps with the profiling though.

Unfortunately I can't join threads, because the program wouldn't 
exit then, the threads run forever normally. I thought maybe 
there is some way to kill a thread gracefully in linux, so it can 
write its profiling information; or another way to get profiling.
Thanks anyway.


More information about the Digitalmars-d-learn mailing list