# info > DBI::ProfileDumper

---
type: CommandReference
command: DBI::ProfileDumper
mode: perldoc
section: '3pm'
source: perldoc
---

## Quick Reference

- `DBI_PROFILE=2/DBI::ProfileDumper program.pl` -- profile program via environment variable
- `$dbh->{Profile} = "!Statement/DBI::ProfileDumper"` -- enable with default path and file
- `$dbh->{Profile} = DBI::ProfileDumper->new( Path => [ '!Statement' ], File => 'dbi.prof' )` -- explicit configuration
- `$profile->flush_to_disk()` -- flush data to disk and clear Data hash
- `$profile->empty()` -- clear Data hash without writing
- `$profile->filename()` -- get or set output filename (accepts CODE ref)

## Name

profile DBI usage and output data to a file

## Synopsis

perl
# Via environment variable (bash):
# DBI_PROFILE=2/DBI::ProfileDumper program.pl

# Enable in code:
use DBI;
$dbh->{Profile} = "!Statement/DBI::ProfileDumper";

# Same with explicit object:
use DBI::ProfileDumper;
$dbh->{Profile} = DBI::ProfileDumper->new(
    Path => [ '!Statement' ],
    File => 'dbi.prof'
);

# Custom path:
$dbh->{Profile} = DBI::ProfileDumper->new(
    Path => [ "foo", "bar" ],
    File => 'dbi.prof',
);
## Description

`DBI::ProfileDumper` is a subclass of `DBI::Profile` that dumps profile data to a file instead of printing a summary. The generated file (default `dbi.prof`) can be analyzed with `dbiprof` or custom scripts using `DBI::ProfileData`.

Activate by setting the `DBI_PROFILE` environment variable, enabling in a `$dbh`, or constructing a `DBI::ProfileDumper` object and assigning it to `$dbh->{Profile}`. All DBI handles can share the same profile object when using `DBI_PROFILE`.

For Apache/mod_perl applications, use `DBI::ProfileDumper::Apache`.

## Options

### Constructor parameters

- `Path` -- arrayref of path components (same as in `DBI::Profile`). Default: `['!Statement']`.
- `File` -- filename for output (default: `dbi.prof`). May be a CODE reference that returns the filename when called with the profile object as first argument.

### Methods

- `flush_to_disk()` -- write all collected data to disk and empty the `Data` hash. Returns the filename written, or `undef` if no data. File is locked during write. May be called multiple times.
- `empty()` -- clear the `Data` hash without writing to disk.
- `filename()` -- get or set the filename. If setting, accepts a string or CODE reference.

## Data Format

The output file starts with a header line containing the module version, followed by variable declarations and two newlines, then the profile data. Example:

DBI::ProfileDumper 2.003762
Path = [ '!Statement', '!MethodName' ]
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
...
- Lines beginning with `+` are keys, with nesting level indicated by the number.
- Lines beginning with `=` are profile data (same order as in `DBI::Profile`).
- Same path may appear multiple times; `DBI::ProfileData` merges duplicates.
- Key strings have backslashes doubled, newlines and carriage returns escaped to `\n` and `\r`, and NULL bytes removed.

## See Also

- [DBI::Profile](perldoc/DBI::Profile)
- [DBI::ProfileData](perldoc/DBI::ProfileData)
- [DBI::ProfileDumper::Apache](perldoc/DBI::ProfileDumper::Apache)