Bug 971 – [profile] No profiling output is generated if the application terminates with exit
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-02-16T15:36:27Z
Last change time
2019-05-23T08:13:59Z
Assigned to
Walter Bright
Creator
David Ferenczi
Comments
Comment #0 by david — 2007-02-16T15:36:27Z
test1.d :
--------------8<-----------------------------------
int main(char[][] args)
{
return 0;
}
--------------8<-----------------------------------
test2.d:
--------------8<-----------------------------------
static private import std.c.stdlib: exit;
int main(char[][] args)
{
exit(0);
return 0;
}
--------------8<-----------------------------------
dmd test1.d -profile
./test1
--> trace.def and trace.log are generated
dmd test1.d -profile
./test2
--> no output generated
Comment #1 by david — 2007-02-16T15:40:53Z
In the 2nd case test2.d will be compiled, of course.
dmd test2.d -profile
./test2
> dmd test1.d -profile
> ./test2
>
> --> no output generated
>
Comment #2 by sean — 2007-02-16T15:55:27Z
No output will be generated if the application terminates from an
unhandled exception either. But I think this is correct behavior. If
the application is terminated abruptly then it should be expected that
unwinding code will not be executed.
Comment #3 by david — 2007-02-16T16:31:05Z
It may have been just a bad practice of mine to use the exit function also for normal terminating. The question is, if it's really a misuse, or e.g. exit(EXIT_SUCCESS) should be treated as normal termination.
(Nevertheless I cahnged my code, so it doesn't contain any exit calls.)
Comment #4 by sean — 2007-02-16T17:55:33Z
[email protected] wrote:
>
> ------- Comment #3 from [email protected] 2007-02-16 16:31 -------
> It may have been just a bad practice of mine to use the exit function also for
> normal terminating. The question is, if it's really a misuse, or e.g.
> exit(EXIT_SUCCESS) should be treated as normal termination.
That's a good question. A normal termination in C terms is not a normal
termination in D terms, but one could argue that the D runtime should
handle this case anyway. I think it would be easy enough to do with
atexit() however.
Comment #5 by wbaxter — 2007-08-09T21:43:33Z
Ok, so how *does* one exit from deep within a program in a manner that will still generate profile info?
The only thing I could think of was to put an exception handler around the main loop, and then throw an exception when I want to stop execution.
Is that the best option?
Comment #6 by sean — 2007-08-10T10:58:30Z
That's the most straightforward approach. Unfortunately, it only works when done in the main program thread. An alternate, evil approach would be to suspend all threads, manually call the runtime cleanup routines, and then call C exit(). The safest would probably be for the runtime to register its cleanup routines using _atexit() or the equivalent so C exit() can be called.
Comment #7 by bugzilla — 2007-08-13T00:00:07Z
You can call trace_term() in internal/trace.d to send out the output. I'll make it extern(C) in the next update to make this easier.
The profiler won't work with multithreaded code anyway.
Comment #8 by Justin.SpahrSummers — 2009-10-29T13:12:09Z
I don't know if this issue ever got resolved, but now it's cropping up with a "void main" too, even through a clean return. "int main" does not share the problem.
Comment #9 by razvan.nitu1305 — 2019-05-23T08:13:59Z
Tested on git HEAD master and trace.def/trace.log are both generated for both files in the original bug report. Closing as WORKSFORME, please reopen if the bug still manifests.