.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "DBI::ProfileData 3" .TH DBI::ProfileData 3 2024-09-13 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME DBI::ProfileData \- manipulate DBI::ProfileDumper data dumps .SH SYNOPSIS .IX Header "SYNOPSIS" The easiest way to use this module is through the dbiprof frontend (see dbiprof for details): .PP .Vb 1 \& dbiprof \-\-number 15 \-\-sort count .Ve .PP This module can also be used to roll your own profile analysis: .PP .Vb 2 \& # 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 \*(Aqdisconnect\*(Aq \& $prof\->exclude(key2 => \*(Aqdisconnect\*(Aq); \& \& # 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(); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module offers the ability to read, manipulate and format DBI::ProfileDumper profile data. .PP Conceptually, a profile consists of a series of records, or nodes, each of each has a set of statistics and set of keys. Each record must have a unique set of keys, but there is no requirement that every record have the same number of keys. .SH METHODS .IX Header "METHODS" The following methods are supported by DBI::ProfileData objects. .ie n .SS "$prof = DBI::ProfileData\->new(File => ""dbi.prof"")" .el .SS "\f(CW$prof\fP = DBI::ProfileData\->new(File => ""dbi.prof"")" .IX Subsection "$prof = DBI::ProfileData->new(File => ""dbi.prof"")" .ie n .SS "$prof = DBI::ProfileData\->new(File => ""dbi.prof"", Filter => sub { ... })" .el .SS "\f(CW$prof\fP = DBI::ProfileData\->new(File => ""dbi.prof"", Filter => sub { ... })" .IX Subsection "$prof = DBI::ProfileData->new(File => ""dbi.prof"", Filter => sub { ... })" .ie n .SS "$prof = DBI::ProfileData\->new(Files => [ ""dbi.prof.1"", ""dbi.prof.2"" ])" .el .SS "\f(CW$prof\fP = DBI::ProfileData\->new(Files => [ ""dbi.prof.1"", ""dbi.prof.2"" ])" .IX Subsection "$prof = DBI::ProfileData->new(Files => [ ""dbi.prof.1"", ""dbi.prof.2"" ])" Creates a new DBI::ProfileData object. Takes either a single file through the File option or a list of Files in an array ref. If multiple files are specified then the header data from the first file is used. .PP \fIFiles\fR .IX Subsection "Files" .PP Reference to an array of file names to read. .PP \fIFile\fR .IX Subsection "File" .PP Name of file to read. Takes precedence over \f(CW\*(C`Files\*(C'\fR. .PP \fIDeleteFiles\fR .IX Subsection "DeleteFiles" .PP If true, the files are deleted after being read. .PP Actually the files are renamed with a \f(CW\*(C`deleteme\*(C'\fR suffix before being read, and then, after reading all the files, they're all deleted together. .PP 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. .PP \fIFilter\fR .IX Subsection "Filter" .PP The \f(CW\*(C`Filter\*(C'\fR 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. For example: .PP .Vb 4 \& Filter => sub { \& my ($path_ref, $data_ref) = @_; \& s/foo = \*(Aq.*?\*(Aq/foo = \*(Aq...\*(Aq/ for @$path_ref; \& } .Ve .PP Here's an example that performs some normalization on the SQL. It converts all numbers to \f(CW\*(C`N\*(C'\fR and all quoted strings to \f(CW\*(C`S\*(C'\fR. It can also convert digits to N within names. Finally, it summarizes long "IN (...)" clauses. .PP It's aggressive and simplistic, but it's often sufficient, and serves as an example that you can tailor to suit your own needs: .PP .Vb 12 \& Filter => sub { \& my ($path_ref, $data_ref) = @_; \& local $_ = $path_ref\->[0]; # whichever element contains the SQL Statement \& s/\eb\ed+\eb/N/g; # 42 \-> N \& s/\eb0x[0\-9A\-Fa\-f]+\eb/N/g; # 0xFE \-> N \& s/\*(Aq.*?\*(Aq/\*(AqS\*(Aq/g; # single quoted strings (doesn\*(Aqt handle escapes) \& s/".*?"/"S"/g; # double quoted strings (doesn\*(Aqt handle escapes) \& # convert names like log_20001231 into log_NNNNNNNN, controlled by $opt{n} \& s/([a\-z_]+)(\ed{$opt{n},})/$1.(\*(AqN\*(Aq 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; \& } .Ve .PP 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. See DBI::Profile. .ie n .SS "$copy = $prof\->\fBclone()\fP;" .el .SS "\f(CW$copy\fP = \f(CW$prof\fP\->\fBclone()\fP;" .IX Subsection "$copy = $prof->clone();" Clone a profile data set creating a new object. .ie n .SS "$header = $prof\->\fBheader()\fP;" .el .SS "\f(CW$header\fP = \f(CW$prof\fP\->\fBheader()\fP;" .IX Subsection "$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: .PP .Vb 4 \& $header = { \& Path => [ \*(Aq!Statement\*(Aq, \*(Aq!MethodName\*(Aq ], \& Program => \*(Aqt/42profile_data.t\*(Aq, \& }; .Ve .PP Note that modifying this hash will modify the header data stored inside the profile object. .ie n .SS "$nodes = $prof\->\fBnodes()\fP" .el .SS "\f(CW$nodes\fP = \f(CW$prof\fP\->\fBnodes()\fP" .IX Subsection "$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: .PP .Vb 10 \& $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 \& \*(AqSELECT foo FROM bar\*(Aq # 7, key1 \& \*(Aqexecute\*(Aq # 8, key2 \& # 6+N, keyN \& ], \& # ... \& ]; .Ve .PP Note that modifying this array will modify the node data stored inside the profile object. .ie n .SS "$count = $prof\->\fBcount()\fP" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->\fBcount()\fP" .IX Subsection "$count = $prof->count()" Returns the number of items in the profile data set. .ie n .SS "$prof\->sort(field => ""field"")" .el .SS "\f(CW$prof\fP\->sort(field => ""field"")" .IX Subsection "$prof->sort(field => ""field"")" .ie n .SS "$prof\->sort(field => ""field"", reverse => 1)" .el .SS "\f(CW$prof\fP\->sort(field => ""field"", reverse => 1)" .IX Subsection "$prof->sort(field => ""field"", reverse => 1)" Sorts data by the given field. Available fields are: .PP .Vb 4 \& longest \& total \& count \& shortest .Ve .PP 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. .ie n .SS "$count = $prof\->exclude(key2 => ""disconnect"")" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->exclude(key2 => ""disconnect"")" .IX Subsection "$count = $prof->exclude(key2 => ""disconnect"")" .ie n .SS "$count = $prof\->exclude(key2 => ""disconnect"", case_sensitive => 1)" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->exclude(key2 => ""disconnect"", case_sensitive => 1)" .IX Subsection "$count = $prof->exclude(key2 => ""disconnect"", case_sensitive => 1)" .ie n .SS "$count = $prof\->exclude(key1 => qr/^SELECT/i)" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->exclude(key1 => qr/^SELECT/i)" .IX Subsection "$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 \fBclone()\fR first to maintain the original data after \&\fBexclude()\fR. Returns the number of nodes left in the profile data set. .ie n .SS "$count = $prof\->match(key2 => ""disconnect"")" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->match(key2 => ""disconnect"")" .IX Subsection "$count = $prof->match(key2 => ""disconnect"")" .ie n .SS "$count = $prof\->match(key2 => ""disconnect"", case_sensitive => 1)" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->match(key2 => ""disconnect"", case_sensitive => 1)" .IX Subsection "$count = $prof->match(key2 => ""disconnect"", case_sensitive => 1)" .ie n .SS "$count = $prof\->match(key1 => qr/^SELECT/i)" .el .SS "\f(CW$count\fP = \f(CW$prof\fP\->match(key1 => qr/^SELECT/i)" .IX Subsection "$count = $prof->match(key1 => qr/^SELECT/i)" Removes records from the data set that do not match the given string or regular expression. This method modifies the data in a permanent fashion \- use \fBclone()\fR first to maintain the original data after \&\fBmatch()\fR. Returns the number of nodes left in the profile data set. .ie n .SS "$Data = $prof\->\fBData()\fP" .el .SS "\f(CW$Data\fP = \f(CW$prof\fP\->\fBData()\fP" .IX Subsection "$Data = $prof->Data()" Returns the same Data hash structure as seen in DBI::Profile. This structure is not sorted. The \fBnodes()\fR structure probably makes more sense for most analysis. .ie n .SS "$text = $prof\->format($nodes\->[0])" .el .SS "\f(CW$text\fP = \f(CW$prof\fP\->format($nodes\->[0])" .IX Subsection "$text = $prof->format($nodes->[0])" Formats a single node into a human-readable block of text. .ie n .SS "$text = $prof\->report(number => 10)" .el .SS "\f(CW$text\fP = \f(CW$prof\fP\->report(number => 10)" .IX Subsection "$text = $prof->report(number => 10)" Produces a report with the given number of items. .SH AUTHOR .IX Header "AUTHOR" Sam Tregar .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2002 Sam Tregar .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.