1DBI::ProfileDumper(3) User Contributed Perl DocumentationDBI::ProfileDumper(3)
2
3
4

NAME

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

SYNOPSIS

9       To profile an existing program using DBI::ProfileDumper, set the
10       DBI_PROFILE environment variable and run your program as usual.  For
11       example, using bash:
12
13         DBI_PROFILE=2/DBI::ProfileDumper program.pl
14
15       Then analyze the generated file (dbi.prof) with dbiprof:
16
17         dbiprof
18
19       You can also activate DBI::ProfileDumper from within your code:
20
21         use DBI;
22
23         # profile with default path (2) and output file (dbi.prof)
24         $dbh->{Profile} = "!Statement/DBI::ProfileDumper";
25
26         # same thing, spelled out
27         $dbh->{Profile} = "!Statement/DBI::ProfileDumper/File:dbi.prof";
28
29         # another way to say it
30         use DBI::ProfileDumper;
31         $dbh->{Profile} = DBI::ProfileDumper->new(
32                               Path => [ '!Statement' ],
33                               File => 'dbi.prof' );
34
35         # using a custom path
36         $dbh->{Profile} = DBI::ProfileDumper->new(
37             Path => [ "foo", "bar" ],
38             File => 'dbi.prof',
39         );
40

DESCRIPTION

42       DBI::ProfileDumper is a subclass of DBI::Profile which dumps profile
43       data to disk instead of printing a summary to your screen.  You can
44       then use dbiprof to analyze the data in a number of interesting ways,
45       or you can roll your own analysis using DBI::ProfileData.
46
47       NOTE: For Apache/mod_perl applications, use DBI::ProfileDumper::Apache.
48

USAGE

50       One way to use this module is just to enable it in your $dbh:
51
52         $dbh->{Profile} = "1/DBI::ProfileDumper";
53
54       This will write out profile data by statement into a file called
55       dbi.prof.  If you want to modify either of these properties, you can
56       construct the DBI::ProfileDumper object yourself:
57
58         use DBI::ProfileDumper;
59         $dbh->{Profile} = DBI::ProfileDumper->new(
60             Path => [ '!Statement' ],
61             File => 'dbi.prof'
62         );
63
64       The "Path" option takes the same values as in DBI::Profile.  The "File"
65       option gives the name of the file where results will be collected.  If
66       it already exists it will be overwritten.
67
68       You can also activate this module by setting the DBI_PROFILE
69       environment variable:
70
71         $ENV{DBI_PROFILE} = "!Statement/DBI::ProfileDumper";
72
73       This will cause all DBI handles to share the same profiling object.
74

METHODS

76       The following methods are available to be called using the profile
77       object.  You can get access to the profile object from the Profile key
78       in any DBI handle:
79
80         my $profile = $dbh->{Profile};
81
82   flush_to_disk
83         $profile->flush_to_disk()
84
85       Flushes all collected profile data to disk and empties the Data hash.
86       Returns the filename written to.  If no profile data has been collected
87       then the file is not written and flush_to_disk() returns undef.
88
89       The file is locked while it's being written. A process 'consuming' the
90       files while they're being written to, should rename the file first,
91       then lock it, then read it, then close and delete it. The "DeleteFiles"
92       option to DBI::ProfileData does the right thing.
93
94       This method may be called multiple times during a program run.
95
96   empty
97         $profile->empty()
98
99       Clears the Data hash without writing to disk.
100
101   filename
102         $filename = $profile->filename();
103
104       Get or set the filename.
105
106       The filename can be specified as a CODE reference, in which case the
107       referenced code should return the filename to be used. The code will be
108       called with the profile object as its first argument.
109

DATA FORMAT

111       The data format written by DBI::ProfileDumper starts with a header
112       containing the version number of the module used to generate it.  Then
113       a block of variable declarations describes the profile.  After two
114       newlines, the profile data forms the body of the file.  For example:
115
116         DBI::ProfileDumper 2.003762
117         Path = [ '!Statement', '!MethodName' ]
118         Program = t/42profile_data.t
119
120         + 1 SELECT name FROM users WHERE id = ?
121         + 2 prepare
122         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
123         + 2 execute
124         1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
125         + 2 fetchrow_hashref
126         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
127         + 1 UPDATE users SET name = ? WHERE id = ?
128         + 2 prepare
129         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
130         + 2 execute
131         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
132
133       The lines beginning with "+" signs signify keys.  The number after the
134       "+" sign shows the nesting level of the key.  Lines beginning with "="
135       are the actual profile data, in the same order as in DBI::Profile.
136
137       Note that the same path may be present multiple times in the data file
138       since "format()" may be called more than once.  When read by
139       DBI::ProfileData the data points will be merged to produce a single
140       data set for each distinct path.
141
142       The key strings are transformed in three ways.  First, all backslashes
143       are doubled.  Then all newlines and carriage-returns are transformed
144       into "\n" and "\r" respectively.  Finally, any NULL bytes ("\0") are
145       entirely removed.  When DBI::ProfileData reads the file the first two
146       transformations will be reversed, but NULL bytes will not be restored.
147

AUTHOR

149       Sam Tregar <sam@tregar.com>
150
152       Copyright (C) 2002 Sam Tregar
153
154       This program is free software; you can redistribute it and/or modify it
155       under the same terms as Perl 5 itself.
156
157
158
159perl v5.28.0                      2013-06-24             DBI::ProfileDumper(3)
Impressum