Devel::Trace::Fork - Devel::Trace-like output for multi-process programs
0.11
perl -d:Trace::Fork program
Like Mark Jason Dominus's Devel::Trace module, but debugging output includes additional information like
a high-resolution timestamp for the time each statement was executed
the process id of the process that executes each statement
the current value of the $CHILD_ERROR variable ($?)
$?
This additional information can be helpful for debugging programs that make use of the fork system call to run. For example, the Trace::Fork output of this program:
Trace::Fork
if (fork() == 0) { print "This is the child.\n"; exit 0; } print "This is the parent.\n";
will be a file that looks something like:
/usr/bin/perl test 1268025451 1268025451.815 >> 0.816214:7996:0:test:1: if (fork() == 0) { >> 0.826566:7996:0:test:5: print "This is the parent.\n"; >> 0.826684:9572:0:test:2: print "This is the child.\n"; >> 0.826941:9572:0:test:3: exit 0;
Debug output is not to STDERR, but to a file that is either specified by $ENV{DTRACE_FILE} or set to the file name "DTFork.$$" in the current directory (where $$ is the process identifier of the parent process). To output debugging output to STDERR the way Devel::Trace does, see Devel::Trace::Fork::Stderr.
STDERR
$ENV{DTRACE_FILE}
"DTFork.$$"
$$
See Devel::Trace. Use the $Devel::Trace::TRACE variable or the Devel::Trace::trace function exactly the way you would use them with the pure Devel::Trace module. To import the Devel::Trace::trace function into your program's namespace, include the line:
$Devel::Trace::TRACE
Devel::Trace::trace
Devel::Trace
use Devel::Trace 'trace';
somewhere in your program.
None
Devel::Trace::Fork: failed to ...
An I/O error occurred with the trace output file. Check that you have permission to create or overwrite the file specified by the DTRACE_FILE environment variable, or if DTRACE_FILE is not specified, that you can create files in the current directory.
DTRACE_FILE
Name of trace output file. If not specified, uses the filename "DTFork.$$" in the current directory.
$ENV{DTFORK_ERASE_ON_GOOD_EXIT}
If this variable is non-zero, and the program is successful (that is, it is exiting with status 0), then the output trace file will be removed. This setting is helpful if you are trying to replicate an intermittent program failure and don't want your directory littered with the trace files of successful runs.
If there are child processes that exit later than the parent process, then the final output will not be sorted.
There is almost enough information in the trace output to use it for profiling. Almost.
Devel::Trace, Devel::Trace::More
Marty O'Brien, <mob@cpan.org>
Copyright (c) 2010, Marty O'Brien
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.
To install Devel::Trace::Fork, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::Trace::Fork
CPAN shell
perl -MCPAN -e shell install Devel::Trace::Fork
For more information on module installation, please visit the detailed CPAN module installation guide.