[Bio] / FigKernelScripts / trace.pl Repository:
ViewVC logotype

View of /FigKernelScripts/trace.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.3 - (download) (as text) (annotate)
Tue Apr 29 07:37:00 2008 UTC (11 years, 11 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.2: +2 -0 lines
Fixed so that the destination is not case-sensitive.

#!/usr/bin/perl -w

=head1 Command-line Tracing Setup

This is a simple tool that sets up Emergency Tracing for the current user.
It accepts an array of positional parameters, starting with the tracing level
(0, 1, 2, 3) and followed by a list of the tracing modules to turn on.

Prior to using any tracing, you must set the C<TRACING> environment variable,

    export TRACING=Bruce

This tells the tracing facility where to find your tracing parameters
and what to name your trace file. (The trace file is always named
C<trace>I<user>C<.log> in the FIG temporary directory.)

To turn on tracing for command-line tools, your script must use the B<Tracer>
module and call B<ETracing> early in the process.

    use Tracer

The trace levels are as follows:

=over 4

=item 0

Only error messages are traced.

=item 1

Error and warning messages are traced.

=item 2

Error, warning, and status information is traced. This is the default setting
for many scripts.

=item 3

Periodic information is traced. Generally, trace messages will be issued
once per genome, or possibly once per SQL statement. This is the normal setting
used for debugging.

=item 4

Everything is traced. This generates a great deal of information and is only
used in dire situations.


The trace level is the first positional parameter. The remaining parameters are
the trace module names. In general, the trace module name is the same as the
name of the C<pm> file in which the C<Trace> statement is coded. So, if
the following line of code were in the file C<DBKernel.pm>

    Trace("Prepare to issue command $command.") if T(3);

Then the command

    trace 3 DBKernel

would cause it to appear.

There are a few special trace modules, most of which are only useful to web
applications. The one exception is C<SQL>. Coding

    trace 3 SQL

will cause all SQL statements to be traced. Coding

    trace 4 SQL

will cause all SQL statements and row fetches to be traced. Note that SQL
can be combined with other trace modules.

    trace 3 SQL Subsystem BasicLocation

will trace the SQL statements and any level 3 trace messages from the
C<Subsystem.pm> and C<BasicLocation.pm> modules.

To turn on ALL modules, use an asterisk.

    trace 3 "*"

The currently-supported command-line options are as follows.

=over 4

=item duration

Number of hours to keep tracing turned on. The default is C<4>.

=item dest

Destination for the trace output. C<DUAL> sends it to both the trace log in the
FIG temporary directory and the standard output. C<FILE> sends it only to the
trace log in the FIG temporary directory. C<WARN> sends it to the error
output. C<TEXT> sends it only to the standard output. The default is C<DUAL>.

=item background

Save the standard and error output to files. The files will be created
in the FIG temporary directory and will be named C<err>I<User>C<.log> and
C<out>I<User>C<.log>, respectively, where I<User> is the value of the
B<user> option above.

=item h

Display this command's parameters and options.

=item phone

Phone number to message when the script is complete.



use strict;
use Tracer;
use Cwd;
use File::Copy;
use File::Path;
use FIG;

# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw() ],
                                              trace => [0, "tracing level for THIS SCRIPT (as opposed to the level being set)"],
                                              phone => ["", "phone number (international format) to call when load finishes"],
                                              dest => ["DUAL", "DUAL to send tracing messages to the trace file and the standard output, FILE to send to the trace file only, WARN to send to the error output only, and TEXT to send to the standard output only"],
                                              duration => ["4", "number of hours for tracing to be active"],
                                           "<level> <packages>",
# Set a variable to contain return type information.
my $rtype;
# Insure we catch errors.
eval {
    # Get the trace level and the module names.
    my ($level, @modules) = @parameters;
    # Do some validation.
    if ($level !~ /[01234]/) {
        # The trace level has to be a single digit from the approved list.
        Confess("Invalid trace level $level specified.");
    } elsif ($options->{user} =~ /^\d+$/) {
        # Here the user did not set the trace key.
        Confess("Please use \"export TRACING=<yourname>\" to set the trace key.");
    } else {
        # Fix the case on the destination option, in case the user didn't use upper case.
        my $dest = uc $options->{dest};
        # Okay, here we are in good shape. Set up the emergency tracing file.
        Emergency($options->{user}, $options->{duration}, $options->{dest}, $level, @modules);
if ($@) {
    Trace("Script failed with error: $@") if T(0);
    $rtype = "error";
} else {
    Trace("Script complete.") if T(2);
    $rtype = "no error";
if ($options->{phone}) {
    my $msgID = Tracer::SendSMS($options->{phone}, "Command-line Tracing Setup terminated with $rtype.");
    if ($msgID) {
        Trace("Phone message sent with ID $msgID.") if T(2);
    } else {
        Trace("Phone message not sent.") if T(2);


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3