# perldoc > DBI::ProfileData

---
type: CommandReference
command: DBI::ProfileData
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference

- `dbiprof --number 15 --sort count` — run profile analysis with top 15 by count
- `$prof = DBI::ProfileData->new(File => "dbi.prof")` — load profile data from file
- `$prof->sort(field => "longest")` — sort records by longest duration (descending)
- `$prof->exclude(key2 => 'disconnect')` — remove records where key2 equals 'disconnect'
- `$prof->match(key1 => qr/^SELECT/i)` — keep only records where key1 matches SELECT
- `$prof->report(number => 10)` — generate a formatted report with top 10 items
- `$prof->clone()` — create a duplicate of the profile data set
- `$prof->format($nodes->[0])` — format a single node as readable text

## Name

DBI::ProfileData - manipulate DBI::ProfileDumper data dumps

## Synopsis

perl
# Via dbiprof frontend:
dbiprof --number 15 --sort count

# Direct use:
use DBI::ProfileData;
$prof = DBI::ProfileData->new(File => "dbi.prof");
$prof->sort(field => "longest");
$prof->exclude(key2 => 'disconnect');
$prof->match(key1 => qr/^SELECT/i);
$report = $prof->report(number => 10);
## Methods

### Creation and Loading

- `DBI::ProfileData->new(File => "dbi.prof")` — create object from a single file
- `DBI::ProfileData->new(Files => [ "dbi.prof.1", "dbi.prof.2" ])` — create from multiple files; header from first file
- `DBI::ProfileData->new(File => "dbi.prof", DeleteFiles => 1)` — delete source files after reading (renamed with "deleteme" suffix, locked, then deleted)
- `DBI::ProfileData->new(File => "dbi.prof", Filter => sub { ... })` — apply a filter code reference during loading to normalize paths (e.g., SQL statements)

### Data Access

- `$prof->header()` — returns reference to hash of header values (e.g., `Path`, `Program`). Modifying the hash modifies the object's header.
- `$prof->nodes()` — returns reference to sorted array of node records. Each node is an arrayref: `[count, total_duration, first_duration, shortest_duration, longest_duration, time_first, time_last, key1, key2, ...]`. Modifying the array modifies the object's data.
- `$prof->Data()` — returns the raw Data hash structure (unsorted) as used by DBI::Profile
- `$prof->count()` — returns the number of records (unique paths) in the data set

### Data Manipulation

- `$prof->sort(field => "field")` — sort by field: `longest`, `total`, `count`, `shortest`. Default descending (opposite of Perl's normal sort).
- `$prof->sort(field => "field", reverse => 1)` — sort ascending
- `$prof->exclude(key2 => "disconnect")` — remove records matching a string or regex. Returns count of remaining nodes.
- `$prof->exclude(key2 => "disconnect", case_sensitive => 1)` — case-sensitive matching
- `$prof->match(key1 => qr/^SELECT/i)` — remove records that do NOT match the string or regex. Returns count of remaining nodes.
- `$prof->match(key1 => "SELECT", case_sensitive => 1)` — case-sensitive matching
- `$prof->clone()` — create a deep copy of the profile data set

### Reporting

- `$prof->report(number => 10)` — produce a formatted report with the given number of items
- `$prof->format($nodes->[0])` — format a single node into a human-readable block of text

## Examples

### Filtering SQL during loading

perl
$prof = DBI::ProfileData->new(
    File   => "dbi.prof",
    Filter => sub {
        my ($path_ref, $data_ref) = @_;
        local $_ = $path_ref->[0];
        s/\b\d+\b/N/g;             # 42 -> N
        s/\b0x[0-9A-Fa-f]+\b/N/g;  # 0xFE -> N
        s/'.*?'/'S'/g;             # single quoted strings
        s/".*?"/"S"/g;             # double quoted strings
        s/([a-z_]+)(\d{2,})/$1.('N' x length($2))/ieg;  # normalize names with digits
        s!(([NS],){100,})!sprintf("$2,{repeated %d times}",length($1)/2)!eg;  # shorten long IN clauses
    }
);
### Excluding and matching

perl
$prof->exclude(key2 => 'disconnect');
$prof->match(key1 => qr/^SELECT/i);
### Cloning and sorting

perl
$clone = $prof->clone();
$clone->sort(field => "longest");
## See Also

- [DBI::ProfileDumper](https://metacpan.org/pod/DBI::ProfileDumper)
- [DBI::Profile](https://metacpan.org/pod/DBI::Profile)
- [dbiprof](https://metacpan.org/pod/dbiprof)

## Exit Codes

Not documented.