The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Devel::Trace::Fork - Devel::Trace-like output for multi-process programs

VERSION

0.11

SYNOPSIS

    perl -d:Trace::Fork program

DESCRIPTION

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:

    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;

DETAILS

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.

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:

    use Devel::Trace 'trace';

somewhere in your program.

SUBROUTINES/METHODS

None

DIAGNOSTICS

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.

CONFIGURATION AND ENVIRONMENT

$ENV{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.

DEPENDENCIES

    Devel::Trace

BUGS AND LIMITATIONS

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.

SEE ALSO

Devel::Trace, Devel::Trace::More

AUTHOR

Marty O'Brien, <mob@cpan.org>

LICENSE AND COPYRIGHT

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.