home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / dbiprof.bat < prev    next >
Encoding:
DOS Batch File  |  2004-07-06  |  5.0 KB  |  221 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl
  14. #line 15
  15.  
  16. use strict;
  17.  
  18. my $VERSION = "1.0";
  19.  
  20. use DBI::ProfileData;
  21. use Getopt::Long;
  22.  
  23. # default options
  24. my $number         = 10;
  25. my $sort           = 'total';
  26. my $filename       = 'dbi.prof';
  27. my $reverse        = 0;
  28. my $case_sensitive = 0;
  29. my (%match, %exclude);
  30.  
  31. # get options from command line
  32. GetOptions(
  33.            'version'        => sub { die "dbiprof $VERSION\n"; },
  34.            'number=i'       => \$number,
  35.            'sort=s'         => \$sort,
  36.            'reverse'        => \$reverse,
  37.            'match=s'        => \%match,
  38.            'exclude=s'      => \%exclude,
  39.            'case-sensitive' => \$case_sensitive,
  40.           );
  41.  
  42. # list of files defaults to dbi.prof
  43. my @files = @ARGV ? @ARGV : ('dbi.prof');
  44.  
  45.  
  46. # instantiate ProfileData object
  47. my $prof;
  48. eval { $prof = DBI::ProfileData->new(Files => \@files) };
  49. die "Unable to load profile data: $@\n" if $@;
  50.  
  51. # handle matches
  52. while (my ($key, $val) = each %match) {
  53.     if ($val =~ m!^/(.+)/$!) {
  54.         $val = $case_sensitive ? qr/$1/ : qr/$1/i;
  55.     } 
  56.     $prof->match($key, $val, case_sensitive => $case_sensitive);
  57. }
  58.  
  59. # handle excludes
  60. while (my ($key, $val) = each %exclude) {
  61.     if ($val =~ m!^/(.+)/$!) {
  62.         $val = $case_sensitive ? qr/$1/ : qr/$1/i;
  63.     } 
  64.     $prof->exclude($key, $val, case_sensitive => $case_sensitive);
  65. }
  66.  
  67. # sort the data
  68. $prof->sort(field => $sort, reverse => $reverse);
  69.  
  70. # all done, print it out
  71. print $prof->report(number => $number);
  72. exit 0;
  73.  
  74. __END__
  75.  
  76. =head1 NAME
  77.  
  78. dbiprof - command-line client for DBI::ProfileData
  79.  
  80. =head1 SYNOPSIS
  81.  
  82. See a report of the ten queries with the longest total runtime in the
  83. profile dump file F<prof1.out>:
  84.  
  85.  dbiprof prof1.out
  86.  
  87. See the top 10 most frequently run queries in the profile file
  88. F<dbi.prof> (the default):
  89.  
  90.   dbiprof --sort count
  91.  
  92. See the same report with 15 entries:
  93.  
  94.   dbiprof --sort count --number 15
  95.  
  96. =head1 DESCRIPTION
  97.  
  98. This tool is a command-line client for the DBI::ProfileData.  It
  99. allows you to analyze the profile data file produced by
  100. DBI::ProfileDumper and produce various useful reports.
  101.  
  102. =head1 OPTIONS
  103.  
  104. This program accepts the following options:
  105.  
  106. =over 4
  107.  
  108. =item --number N
  109.  
  110. Produce this many items in the report.  Defaults to 10.  If set to
  111. "all" then all results are shown.
  112.  
  113. =item --sort field
  114.  
  115. Sort results by the given field.  The available sort fields are:
  116.  
  117. =over 4
  118.  
  119. =item total
  120.  
  121. Sorts by total time run time across all runs.  This is the default
  122. sort.
  123.  
  124. =item longest
  125.  
  126. Sorts by the longest single run.
  127.  
  128. =item count
  129.  
  130. Sorts by total number of runs.
  131.  
  132. =item first
  133.  
  134. Sorts by the time taken in the first run.
  135.  
  136. =item shortest
  137.  
  138. Sorts by the shortest single run.
  139.  
  140. =back
  141.  
  142. =item --reverse
  143.  
  144. Reverses the selected sort.  For example, to see a report of the
  145. shortest overall time:
  146.  
  147.   dbiprof --sort total --reverse
  148.  
  149. =item --match keyN=value
  150.  
  151. Consider only items where the specified key matches the given value.
  152. Keys are numbered from 1.  For example, let's say you used a
  153. DBI::Profile Path of:
  154.  
  155.   [ DBIprofile_Statement, DBIprofile_Methodname ]
  156.  
  157. And called dbiprof as in:
  158.  
  159.   dbiprof --match key2=execute
  160.  
  161. Your report would only show execute queries, leaving out prepares,
  162. fetches, etc.
  163.  
  164. If the value given starts and ends with slashes (C</>) then it will be
  165. treated as a regular expression.  For example, to only include SELECT
  166. queries where key1 is the statement:
  167.  
  168.   dbiprof --match key1=/^SELECT/
  169.  
  170. By default the match expression is matched case-insensitively, but
  171. this can be changed with the --case-sensitive option.
  172.  
  173. =item --exclude keyN=value
  174.  
  175. Remove items for where the specified key matches the given value.  For
  176. example, to exclude all prepare entries where key2 is the method name:
  177.  
  178.   dbiprof --exclude key2=prepare
  179.  
  180. Like C<--match>, If the value given starts and ends with slashes
  181. (C</>) then it will be treated as a regular expression.  For example,
  182. to exclude UPDATE queries where key1 is the statement:
  183.  
  184.   dbiprof --match key1=/^UPDATE/
  185.  
  186. By default the exclude expression is matched case-insensitively, but
  187. this can be changed with the --case-sensitive option.
  188.  
  189. =item --case-sensitive
  190.  
  191. Using this option causes --match and --exclude to work
  192. case-sensitively.  Defaults to off.
  193.  
  194. =item --version
  195.  
  196. Print the dbiprof version number and exit.
  197.  
  198. =back
  199.  
  200. =head1 AUTHOR
  201.  
  202. Sam Tregar <sam@tregar.com>
  203.  
  204. =head1 COPYRIGHT AND LICENSE
  205.  
  206. Copyright (C) 2002 Sam Tregar
  207.  
  208. This program is free software; you can redistribute it and/or modify
  209. it under the same terms as Perl 5 itself.
  210.  
  211. =head1 SEE ALSO
  212.  
  213. L<DBI::ProfileDumper|DBI::ProfileDumper>,
  214. L<DBI::Profile|DBI::Profile>, L<DBI|DBI>.
  215.  
  216. =cut
  217.  
  218.  
  219. __END__
  220. :endofperl
  221.