.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "DBI::ProfileDumper 3" .TH DBI::ProfileDumper 3 2024-09-13 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME DBI::ProfileDumper \- profile DBI usage and output data to a file .SH SYNOPSIS .IX Header "SYNOPSIS" To profile an existing program using DBI::ProfileDumper, set the DBI_PROFILE environment variable and run your program as usual. For example, using bash: .PP .Vb 1 \& DBI_PROFILE=2/DBI::ProfileDumper program.pl .Ve .PP Then analyze the generated file (\fIdbi.prof\fR) with dbiprof: .PP .Vb 1 \& dbiprof .Ve .PP You can also activate DBI::ProfileDumper from within your code: .PP .Vb 1 \& use DBI; \& \& # profile with default path (2) and output file (dbi.prof) \& $dbh\->{Profile} = "!Statement/DBI::ProfileDumper"; \& \& # same thing, spelled out \& $dbh\->{Profile} = "!Statement/DBI::ProfileDumper/File:dbi.prof"; \& \& # another way to say it \& use DBI::ProfileDumper; \& $dbh\->{Profile} = DBI::ProfileDumper\->new( \& Path => [ \*(Aq!Statement\*(Aq ], \& File => \*(Aqdbi.prof\*(Aq ); \& \& # using a custom path \& $dbh\->{Profile} = DBI::ProfileDumper\->new( \& Path => [ "foo", "bar" ], \& File => \*(Aqdbi.prof\*(Aq, \& ); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" DBI::ProfileDumper is a subclass of DBI::Profile which dumps profile data to disk instead of printing a summary to your screen. You can then use dbiprof to analyze the data in a number of interesting ways, or you can roll your own analysis using DBI::ProfileData. .PP \&\fBNOTE:\fR For Apache/mod_perl applications, use DBI::ProfileDumper::Apache. .SH USAGE .IX Header "USAGE" One way to use this module is just to enable it in your \f(CW$dbh\fR: .PP .Vb 1 \& $dbh\->{Profile} = "1/DBI::ProfileDumper"; .Ve .PP This will write out profile data by statement into a file called \&\fIdbi.prof\fR. If you want to modify either of these properties, you can construct the DBI::ProfileDumper object yourself: .PP .Vb 5 \& use DBI::ProfileDumper; \& $dbh\->{Profile} = DBI::ProfileDumper\->new( \& Path => [ \*(Aq!Statement\*(Aq ], \& File => \*(Aqdbi.prof\*(Aq \& ); .Ve .PP The \f(CW\*(C`Path\*(C'\fR option takes the same values as in DBI::Profile. The \f(CW\*(C`File\*(C'\fR option gives the name of the file where results will be collected. If it already exists it will be overwritten. .PP You can also activate this module by setting the DBI_PROFILE environment variable: .PP .Vb 1 \& $ENV{DBI_PROFILE} = "!Statement/DBI::ProfileDumper"; .Ve .PP This will cause all DBI handles to share the same profiling object. .SH METHODS .IX Header "METHODS" The following methods are available to be called using the profile object. You can get access to the profile object from the Profile key in any DBI handle: .PP .Vb 1 \& my $profile = $dbh\->{Profile}; .Ve .SS flush_to_disk .IX Subsection "flush_to_disk" .Vb 1 \& $profile\->flush_to_disk() .Ve .PP Flushes all collected profile data to disk and empties the Data hash. Returns the filename written to. If no profile data has been collected then the file is not written and \fBflush_to_disk()\fR returns undef. .PP The file is locked while it's being written. A process 'consuming' the files while they're being written to, should rename the file first, then lock it, then read it, then close and delete it. The \f(CW\*(C`DeleteFiles\*(C'\fR option to DBI::ProfileData does the right thing. .PP This method may be called multiple times during a program run. .SS empty .IX Subsection "empty" .Vb 1 \& $profile\->empty() .Ve .PP Clears the Data hash without writing to disk. .SS filename .IX Subsection "filename" .Vb 1 \& $filename = $profile\->filename(); .Ve .PP Get or set the filename. .PP The filename can be specified as a CODE reference, in which case the referenced code should return the filename to be used. The code will be called with the profile object as its first argument. .SH "DATA FORMAT" .IX Header "DATA FORMAT" The data format written by DBI::ProfileDumper starts with a header containing the version number of the module used to generate it. Then a block of variable declarations describes the profile. After two newlines, the profile data forms the body of the file. For example: .PP .Vb 3 \& DBI::ProfileDumper 2.003762 \& Path = [ \*(Aq!Statement\*(Aq, \*(Aq!MethodName\*(Aq ] \& Program = t/42profile_data.t \& \& + 1 SELECT name FROM users WHERE id = ? \& + 2 prepare \& = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576 \& + 2 execute \& 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576 \& + 2 fetchrow_hashref \& = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576 \& + 1 UPDATE users SET name = ? WHERE id = ? \& + 2 prepare \& = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576 \& + 2 execute \& = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576 .Ve .PP The lines beginning with \f(CW\*(C`+\*(C'\fR signs signify keys. The number after the \f(CW\*(C`+\*(C'\fR sign shows the nesting level of the key. Lines beginning with \f(CW\*(C`=\*(C'\fR are the actual profile data, in the same order as in DBI::Profile. .PP Note that the same path may be present multiple times in the data file since \f(CWformat()\fR may be called more than once. When read by DBI::ProfileData the data points will be merged to produce a single data set for each distinct path. .PP The key strings are transformed in three ways. First, all backslashes are doubled. Then all newlines and carriage-returns are transformed into \f(CW\*(C`\en\*(C'\fR and \f(CW\*(C`\er\*(C'\fR respectively. Finally, any NULL bytes (\f(CW\*(C`\e0\*(C'\fR) are entirely removed. When DBI::ProfileData reads the file the first two transformations will be reversed, but NULL bytes will not be restored. .SH AUTHOR .IX Header "AUTHOR" Sam Tregar .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2002 Sam Tregar .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.