DESCRIPTION

This module offers the ability to read, manipulate and format DBI::ProfileDumper profile data.

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.

METHODS

The following methods are supported by DBI::ProfileData objects.

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

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.

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 the files are renamed with a C.deleteme> suffix before being read, and then, after reading all the files, they're all deleted together.

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.

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. For example:

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:

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.

$copy = $prof->clone();

Clone a profile data set creating a new object.

$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:

Note that modifying this hash will modify the header data stored inside the profile object.

$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:

Note that 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.

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

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

Sorts data by the given field. 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.

$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(). 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. This method modifies the data in a permanent fashion - 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.

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

Formats a single node into a human-readable block of text.

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

Produces a report with the given number of items.

AUTHOR

Sam Tregar <sam@tregar.com>

COPYRIGHT AND LICENSE

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.

Module Install Instructions

To install DBI::ProfileData, simply copy and paste either of the commands in to your terminal