DBI::ProfileData(3)

🌸 DBI::ProfileData 🌸

okay bestie, so this page lives in the User Contributed Perl Documentation section (that's the (3) vibe, iykyk) and it's literally called DBI::ProfileData. it's the whole entire manual. let's go πŸ’…


✨ NAME ✨

DBI::ProfileData β€” manipulate DBI::ProfileDumper data dumps πŸŽ€


✨ SYNOPSIS ✨

okay so the easiest way to use this module is through the dbiprof frontend (peep dbiprof for the details, bestie):

  dbiprof --number 15 --sort count

but you can also absolutely roll your own profile analysis, and honestly? iconic behavior:

  local $DBI::ProfileData::MAX_PATH_DEPTH = 256; # override the maximum path depth of files

  # load data from dbi.prof
  $prof = DBI::ProfileData->new(File => "dbi.prof");

  # get a count of the records (unique paths) in the data set
  $count = $prof->count();

  # sort by longest overall time
  $prof->sort(field => "longest");

  # sort by longest overall time, least to greatest
  $prof->sort(field => "longest", reverse => 1);

  # exclude records with key2 eq 'disconnect'
  $prof->exclude(key2 => 'disconnect');

  # exclude records with key1 matching /^UPDATE/i
  $prof->exclude(key1 => qr/^UPDATE/i);

  # remove all records except those where key1 matches /^SELECT/i
  $prof->match(key1 => qr/^SELECT/i);

  # produce a formatted report with the given number of items
  $report = $prof->report(number => 10);

  # clone the profile data set
  $clone = $prof->clone();

  # get access to hash of header values
  $header = $prof->header();

  # get access to sorted array of nodes
  $nodes = $prof->nodes();

  # format a single node in the same style as report()
  $text = $prof->format($nodes->[0]);

  # get access to Data hash in DBI::Profile format
  $Data = $prof->Data();

πŸ’– DESCRIPTION πŸ’–

this module hands you the ability to read, manipulate and format DBI::ProfileDumper profile data. no big deal. πŸ¦‹

so conceptually? a profile is a whole series of records, aka nodes, and each of each one has a set of statistics plus a set of keys. every record has to have a unique set of keys β€” but there is no requirement that every record have the same number of keys. periodt. πŸ’€


🫢 METHODS 🫢

these are the methods that DBI::ProfileData objects support, bestie. buckle in.

$prof = DBI::ProfileData->new(File => "dbi.prof")

$prof = DBI::ProfileData->new(File => "dbi.prof", Filter => sub { ... })

$prof = DBI::ProfileData->new(Files => [ "dbi.prof.1", "dbi.prof.2" ])

creates a brand new DBI::ProfileData object πŸŽ€ takes either a single file via the File option or a list of Files in an array ref. if you specify multiple files, then the header data from the first file is the one that gets used. first come, first served fr fr.

  • Files

reference to an array of file names to read. πŸ“‚

  • File

name of file to read. takes precedence over "Files". πŸ‘‘

  • DeleteFiles

if true, the files are deleted after being read.

actually β€” plot twist β€” the files are renamed with a "deleteme" suffix before being read, and then, after reading all the files, they're all deleted together. the way that works is so unhinged but it makes sense, trust.

the files are locked while being read which, combined with the rename, makes it safe to 'consume' files that are still being generated by DBI::ProfileDumper. no cap, that's the whole point. πŸ”₯

  • Filter

the "Filter" parameter can be used to supply a code reference that can manipulate the profile data as it is being read. this is most useful for editing SQL statements so that slightly different statements in the raw data will be merged and aggregated in the loaded data. like, for example:

  Filter => sub {
      my ($path_ref, $data_ref) = @_;
      s/foo = '.*?'/foo = '...'/ for @$path_ref;
  }

and here's an example that performs some normalization on the SQL. it converts all numbers to "N" and all quoted strings to "S". it can also convert digits to N within names. finally, it summarizes long "IN (...)" clauses. 🧚

it's aggressive and simplistic, but it's often sufficient, and serves as an example that you can tailor to suit your own needs:

  Filter => sub {
      my ($path_ref, $data_ref) = @_;
      local $_ = $path_ref->[0]; # whichever element contains the SQL Statement
      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 (doesn't handle escapes)
      s/".*?"/"S"/g;             # double quoted strings (doesn't handle escapes)
      # convert names like log_20001231 into log_NNNNNNNN, controlled by $opt{n}
      s/([a-z_]+)(\d{$opt{n},})/$1.('N' x length($2))/ieg if $opt{n};
      # abbreviate massive "in (...)" statements and similar
      s!(([NS],){100,})!sprintf("$2,{repeated %d times}",length($1)/2)!eg;
  }

and honestly? it's often better to perform this kinds of normalization in the DBI while the data is being collected, to avoid too much memory being used by storing profile data for many different SQL statement. peep DBI::Profile. πŸ’‘

$copy = $prof->clone();

clone a profile data set creating a new object. it's giving photocopy main character energy 🫢

$header = $prof->header();

returns a reference to a hash of header values. these are the key value pairs included in the header section of the DBI::ProfileDumper data format. for example:

  $header = {
    Path    => [ '!Statement', '!MethodName' ],
    Program => 't/42profile_data.t',
  };
heads up bestie β€” modifying this hash will modify the header data stored inside the profile object. so like, be careful, it's not a copy πŸ’€

$nodes = $prof->nodes()

returns a reference the sorted nodes array. each element in the array is a single record in the data set. the first seven elements are the same as the elements provided by DBI::Profile. after that each key is in a separate element. for example:

 $nodes = [
            [
              2,                      # 0, count
              0.0312958955764771,     # 1, total duration
              0.000490069389343262,   # 2, first duration
              0.000176072120666504,   # 3, shortest duration
              0.00140702724456787,    # 4, longest duration
              1023115819.83019,       # 5, time of first event
              1023115819.86576,       # 6, time of last event
              'SELECT foo FROM bar'   # 7, key1
              'execute'               # 8, key2
                                      # 6+N, keyN
            ],
                                      # ...
          ];
same warning, different array: modifying this array will modify the node data stored inside the profile object. 🚨

$count = $prof->count()

returns the number of items in the profile data set. it's literally just a count. slay. ✨

$prof->sort(field => "field")

$prof->sort(field => "field", reverse => 1)

sorts data by the given field. the available fields are:

  longest
  total
  count
  shortest

the default sort is greatest to smallest, which is the opposite of the normal Perl meaning. this, however, matches the expected behavior of the dbiprof frontend. so it's weird but it's correct, iykyk. 🌈

$count = $prof->exclude(key2 => "disconnect")

$count = $prof->exclude(key2 => "disconnect", case_sensitive => 1)

$count = $prof->exclude(key1 => qr/^SELECT/i)

removes records from the data set that match the given string or regular expression. 😭

this method modifies the data in a permanent fashion β€” use clone() first to maintain the original data after exclude(). no takebacks, bestie.

returns the number of nodes left in the profile data set.

$count = $prof->match(key2 => "disconnect")

$count = $prof->match(key2 => "disconnect", case_sensitive => 1)

$count = $prof->match(key1 => qr/^SELECT/i)

removes records from the data set that do not match the given string or regular expression. πŸ™ˆ

same deal β€” this method modifies the data in a permanent fashion, so use clone() first to maintain the original data after match().

returns the number of nodes left in the profile data set.

$Data = $prof->Data()

returns the same Data hash structure as seen in DBI::Profile. this structure is not sorted. the nodes() structure probably makes more sense for most analysis. just saying. πŸ‘‘

$text = $prof->format($nodes->[0])

formats a single node into a human-readable block of text. one node, one glow-up 🌸

$text = $prof->report(number => 10)

produces a report with the given number of items. πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Sam Tregar <sam@tregar.com>


Copyright (C) 2002 Sam Tregar

this program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. 🫢


aaaand that's the whole page babes πŸŽ€ this was perl v5.42.3, dated 2026-10-19, living it up as DBI::ProfileData(3). go forth and profile, bestie πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from