develooper Front page | perl.dbi.dev | Postings from October 2002

POD for proposed DBI::ProfileDumper

Thread Next
From:
Sam Tregar
Date:
October 5, 2002 21:55
Subject:
POD for proposed DBI::ProfileDumper
Message ID:
Pine.LNX.4.44.0210060044520.31209-100000@airtrout.tregar.com
Here is my proposed interface for DBI::ProfileDumper.  Any and all
comments welcome.  I would like to begin implementation on Monday, if
possible.

-sam


=head1 NAME

DBI::ProfileDumper - profile DBI usage and output data to a file

=head1 SYNOPSIS

  use DBI;

  # profile with default path (2) and output file (dbi.prof)
  $dbh->{Profile} = "DBI::ProfileDumper";

  # same thing, spelled out
  $dbh->{Profile} = "2/DBI::ProfileDumper/File/dbi.prof";

  # another way to say it
  use DBI::Profile;
  $dbh->{Profile} = DBI::ProfileDumper->new(
                      { Path => [ DBIprofile_Statement ]
                        File => 'dbi.prof' });

  # using a custom path
  $dbh->{Profile} = DBI::ProfileDumper->new({ Path => [ "foo", "bar" ],
                                              File => 'dbi.prof' });


=head1 DESCRIPTION

DBI::ProfileDumper is a subclass of L<DBI::Profile|DBI::Profile> that
dumps profile data to disk instead of printing a summary to your
screen.  You can then use dbi_prof to analyze the data in a number of
interesting ways, or you can roll your own analysis using
L<DBI::ProfileData|DBI::ProfileData>.

=head1 USAGE

The normal way to use this module is just to enable it in your C<$dbh>:

  $dbh->{Profile} = "DBI::ProfileDumper";

This will write out profile data by statement into a file called
dbi.prof.  If you want to modify either of these properties, you can
construct the DBI::ProfileDumper object yourself:

  use DBI::Profile qw(DBIprofile_Statement);
  $dbh->{Profile} = DBI::ProfileDumper->new(
                      { Path => [ DBIprofile_Statement ]
                        File => 'dbi.prof' });

The C<Path> option takes the same values as in
L<DBI::Profile|DBI:Profile>.  The C<File> option gives the name of the
file where results will be collected.  If it already exists it will be
overwritten.

To collect data before the process ends, you can call the C<format()>
method:

  $dbh->{Profile}->format();

Calling this methods will empty the currently held profile data and
flush it to disk.

=head1 DATA FORMAT

The data format written by DBI::ProfileDumper starts with a header
containing the version number of the module used to generate it. After two
newlines, the profile data forms the body of the file.  For example:

  DBI::ProfileDumper 1.0

  + SELECT name FROM users WHERE id = ?
  ++ prepare
  1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
  ++ execute
  1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
  ++ fetchrow_hashref
  1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
  + UPDATE users SET name = ? WHERE id = ?
  ++ prepare
  1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
  ++ execute
  1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576

The lines beginning with C<+> signs signify keys.  The number of C<+>
signs shows the nesting level of the key.  Lines of numbers are the actual
profile data, in the same order as in DBI::Profile.

Note that the same path may be present multiple times in the data file
since C<format()> may be called more than once.  When read by
DBI::ProfileData the data points will be merged to produce a single
set for each distinct set of keys.

The key strings are transformed in two ways.  First, all backslashes
are doubled.  Then all newlines are transformed into C<\n>.  When
DBI::ProfileData reads the file these transformations will be
reversed.

=cut


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About