PerlSetEnv DBI_PROFILE 2/DBI::ProfileDumper::Apache
(If you're using mod_perl2, see ``When using mod_perl2'' for some additional notes.)
Then restart your server. Access the code you wish to test using a web browser, then shutdown your server. This will create a set of dbi.prof.* files in your Apache log directory.
Get a profiling report with dbiprof:
dbiprof /path/to/your/apache/logs/dbi.prof.*
When you're ready to perform another profiling run, delete the old files and start again.
PerlSetEnv DBI_PROFILE 2/DBI::ProfileDumper::Apache
The DBI will look after loading and using the module when the first DBI handle is created.
It's also possible to use this module by setting the Profile attribute of any DBI handle:
$dbh->{Profile} = "2/DBI::ProfileDumper::Apache";
See DBI::ProfileDumper for more possibilities, and DBI::Profile for full details of the DBI's profiling mechanism.
The user that the httpd processes run as will need write access to the directory. So, for example, if you're running the child httpds as user 'nobody' and using chronolog to write to the logs directory, then you'll need to change the default.
You can change the destination directory either by specifying a "Dir" value when creating the profile (like "File" in the DBI::ProfileDumper docs), or you can use the "DBI_PROFILE_APACHE_LOG_DIR" env var to change that. For example:
PerlSetEnv DBI_PROFILE_APACHE_LOG_DIR /server_root/logs
When using mod_perl2
Under mod_perl2 you'll need to either set the "DBI_PROFILE_APACHE_LOG_DIR" env var, or enable the mod_perl2 "GlobalRequest" option, like this:
PerlOptions +GlobalRequest
to the global config section you're about test with DBI::ProfileDumper::Apache. If you don't do one of those then you'll see messages in your error_log similar to:
DBI::ProfileDumper::Apache on_destroy failed: Global $r object is not available. Set: PerlOptions +GlobalRequest in httpd.conf at ..../DBI/ProfileDumper/Apache.pm line 144
Naming the files
The default file name is inherited from DBI::ProfileDumper via the filename() method, but DBI::ProfileDumper::Apache appends the parent pid and the current pid, separated by dots, to that name.
Silencing the log
By default a message is written to STDERR (i.e., the apache error_log file) when flush_to_disk() is called (either explicitly, or implicitly via DESTROY).
That's usually very useful. If you don't want the log message you can silence it by setting the "Quiet" attribute true.
PerlSetEnv DBI_PROFILE 2/DBI::ProfileDumper::Apache/Quiet:1 $dbh->{Profile} = "!Statement/DBI::ProfileDumper/Quiet:1"; $dbh->{Profile} = DBI::ProfileDumper->new( Path => [ '!Statement' ] Quiet => 1 );
DBI::ProfileDumper::Apache writing to /usr/local/apache/logs/dbi.prof.2604.2619
Now you can use dbiprof to examine the data:
dbiprof /usr/local/apache/logs/dbi.prof.2604.*
By passing dbiprof a list of all generated files, dbiprof will automatically merge them into one result set. You can also pass dbiprof sorting and querying options, see dbiprof for details.
rm /usr/local/apache/logs/dbi.prof.*
Then restart your server and get back to work.
$dbh->{Profile}->flush_to_disk() if $dbh->{Profile};
or, rather than flush every time, you could flush less often:
$dbh->{Profile}->flush_to_disk() if $dbh->{Profile} and ++$i % 100;
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.