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} = "2/DBI::ProfileDumper";
25
26         # same thing, spelled out
27         $dbh->{Profile} = "2/DBI::ProfileDumper/File:dbi.prof";
28
29         # another way to say it
30         use DBI::Profile;
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( Path => [ "foo", "bar" ],
37                                                    File => 'dbi.prof' );
38

DESCRIPTION

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

USAGE

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

METHODS

73       The following methods are available to be called using the profile
74       object.  You can get access to the profile object from the Profile key
75       in any DBI handle:
76
77         my $profile = $dbh->{Profile};
78
79       $profile->flush_to_disk()
80           Flushes all collected profile data to disk and empties the Data
81           hash.  This method may be called multiple times during a program
82           run.
83
84       $profile->empty()
85           Clears the Data hash without writing to disk.
86

DATA FORMAT

88       The data format written by DBI::ProfileDumper starts with a header con‐
89       taining the version number of the module used to generate it.  Then a
90       block of variable declarations describes the profile.  After two new‐
91       lines, the profile data forms the body of the file.  For example:
92
93         DBI::ProfileDumper 1.0
94         Path = [ '!Statement', '!MethodName' ]
95         Program = t/42profile_data.t
96
97         + 1 SELECT name FROM users WHERE id = ?
98         + 2 prepare
99         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
100         + 2 execute
101         1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
102         + 2 fetchrow_hashref
103         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
104         + 1 UPDATE users SET name = ? WHERE id = ?
105         + 2 prepare
106         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
107         + 2 execute
108         = 1 0.0312958955764771 0.000490069389343262 0.000176072120666504 0.00140702724456787 1023115819.83019 1023115819.86576
109
110       The lines beginning with "+" signs signify keys.  The number after the
111       "+" sign shows the nesting level of the key.  Lines beginning with "="
112       are the actual profile data, in the same order as in DBI::Profile.
113
114       Note that the same path may be present multiple times in the data file
115       since "format()" may be called more than once.  When read by DBI::Pro‐
116       fileData the data points will be merged to produce a single data set
117       for each distinct path.
118
119       The key strings are transformed in three ways.  First, all backslashes
120       are doubled.  Then all newlines and carriage-returns are transformed
121       into "\n" and "\r" respectively.  Finally, any NULL bytes ("\0") are
122       entirely removed.  When DBI::ProfileData reads the file the first two
123       transformations will be reversed, but NULL bytes will not be restored.
124

AUTHOR

126       Sam Tregar <sam@tregar.com>
127
129       Copyright (C) 2002 Sam Tregar
130
131       This program is free software; you can redistribute it and/or modify it
132       under the same terms as Perl 5 itself.
133
134
135
136perl v5.8.8                       2006-02-07             DBI::ProfileDumper(3)
Impressum