On Sun, Oct 06, 2002 at 12:51:30AM -0400, Sam Tregar wrote:
> Here is my proposed interface for DBI::ProfileDumper.  Any and all
> comments welcome.  I would like to begin implementation on Monday, if
> possible.

[Just a quick skim - short on time]

> =head1 USAGE
> 
> The normal way to use this module is just to enable it in your C<$dbh>:
> 
>   $dbh->{Profile} = "DBI::ProfileDumper";

I'd suggest you suggest that people use the DBI_PROFILE env var.

> 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.

I'd suggest that the method be
called flush_to_disk() (and passed an optional filehandle).
flush_to_disk() could just call dump_to_disk() then discard_data().

> =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

I'd add a general name=value section here (matching /^(\w+)=(.*)$/) that can be used
to store information like the Path being used, $0, @ARGV, etc.

>   + 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.

I'd add an extra record-type field at the front of each row
(or at least the profile data records). Perhaps something like:

        @ + SELECT name FROM users WHERE id = ?
        @ ++ prepare
        = 1 0.0312958955764771 0.000490069389343262 0.00....

because it'll make it slightly faster to read and also more easily
extensible if the need arises.

> 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.

Might be wise to also escape \r.

Tim.

Reply via email to