[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 #!/opt/perl/bin/perl 2 3 eval 'exec /opt/perl/bin/perl -S $0 $1+"$@"}' 4 if 0; # not running under some shell 5 6 use strict; 7 8 my $VERSION = sprintf("1.%06d", q$Revision: 9874 $ =~ /(\d+)/o); 9 10 use Data::Dumper; 11 use DBI::ProfileData; 12 use Getopt::Long; 13 14 # default options 15 my $number = 10; 16 my $sort = 'total'; 17 my $filename = 'dbi.prof'; 18 my $reverse = 0; 19 my $case_sensitive = 0; 20 my (%match, %exclude); 21 22 # get options from command line 23 GetOptions( 24 'version' => sub { die "dbiprof $VERSION\n" }, 25 'help' => sub { exit usage() }, 26 'number=i' => \$number, 27 'sort=s' => \$sort, 28 'dumpnodes!' => \my $dumpnodes, 29 'reverse' => \$reverse, 30 'match=s' => \%match, 31 'exclude=s' => \%exclude, 32 'case-sensitive' => \$case_sensitive, 33 'delete!' => \my $opt_delete, 34 ) or exit usage(); 35 36 sub usage { 37 print <<EOS; 38 dbiprof [options] [files] 39 40 Reads and merges DBI profile data from files and prints a summary. 41 42 files: defaults to $filename 43 44 options: 45 46 -number=N show top N, defaults to $number 47 -sort=S sort by S, defaults to $sort 48 -reverse reverse the sort 49 -match=K=V for filtering, see docs 50 -exclude=K=V for filtering, see docs 51 -case_sensitive for -match and -exclude 52 -delete rename files before reading then delete afterwards 53 -version print version number and exit 54 -help print this help 55 56 EOS 57 return 1; 58 } 59 60 # list of files defaults to dbi.prof 61 my @files = @ARGV ? @ARGV : ('dbi.prof'); 62 63 64 # instantiate ProfileData object 65 my $prof = eval { 66 DBI::ProfileData->new( 67 Files => \@files, 68 DeleteFiles => $opt_delete, 69 ); 70 }; 71 die "Unable to load profile data: $@\n" if $@; 72 73 if (%match) { # handle matches 74 while (my ($key, $val) = each %match) { 75 if ($val =~ m!^/(.+)/$!) { 76 $val = $case_sensitive ? qr/$1/ : qr/$1/i; 77 } 78 $prof->match($key, $val, case_sensitive => $case_sensitive); 79 } 80 } 81 82 if (%exclude) { # handle excludes 83 while (my ($key, $val) = each %exclude) { 84 if ($val =~ m!^/(.+)/$!) { 85 $val = $case_sensitive ? qr/$1/ : qr/$1/i; 86 } 87 $prof->exclude($key, $val, case_sensitive => $case_sensitive); 88 } 89 } 90 91 # sort the data 92 $prof->sort(field => $sort, reverse => $reverse); 93 94 # all done, print it out 95 if ($dumpnodes) { 96 $Data::Dumper::Indent = 1; 97 $Data::Dumper::Terse = 1; 98 $Data::Dumper::Useqq = 1; 99 $Data::Dumper::Deparse = 0; 100 print Dumper($prof->nodes); 101 } 102 else { 103 print $prof->report(number => $number); 104 } 105 exit 0; 106 107 __END__ 108 109 =head1 NAME 110 111 dbiprof - command-line client for DBI::ProfileData 112 113 =head1 SYNOPSIS 114 115 See a report of the ten queries with the longest total runtime in the 116 profile dump file F<prof1.out>: 117 118 dbiprof prof1.out 119 120 See the top 10 most frequently run queries in the profile file 121 F<dbi.prof> (the default): 122 123 dbiprof --sort count 124 125 See the same report with 15 entries: 126 127 dbiprof --sort count --number 15 128 129 =head1 DESCRIPTION 130 131 This tool is a command-line client for the DBI::ProfileData. It 132 allows you to analyze the profile data file produced by 133 DBI::ProfileDumper and produce various useful reports. 134 135 =head1 OPTIONS 136 137 This program accepts the following options: 138 139 =over 4 140 141 =item --number N 142 143 Produce this many items in the report. Defaults to 10. If set to 144 "all" then all results are shown. 145 146 =item --sort field 147 148 Sort results by the given field. Sorting by multiple fields isn't currently 149 supported (patches welcome). The available sort fields are: 150 151 =over 4 152 153 =item total 154 155 Sorts by total time run time across all runs. This is the default 156 sort. 157 158 =item longest 159 160 Sorts by the longest single run. 161 162 =item count 163 164 Sorts by total number of runs. 165 166 =item first 167 168 Sorts by the time taken in the first run. 169 170 =item shortest 171 172 Sorts by the shortest single run. 173 174 =item key1 175 176 Sorts by the value of the first element in the Path, which should be numeric. 177 You can also sort by C<key2> and C<key3>. 178 179 =back 180 181 =item --reverse 182 183 Reverses the selected sort. For example, to see a report of the 184 shortest overall time: 185 186 dbiprof --sort total --reverse 187 188 =item --match keyN=value 189 190 Consider only items where the specified key matches the given value. 191 Keys are numbered from 1. For example, let's say you used a 192 DBI::Profile Path of: 193 194 [ DBIprofile_Statement, DBIprofile_Methodname ] 195 196 And called dbiprof as in: 197 198 dbiprof --match key2=execute 199 200 Your report would only show execute queries, leaving out prepares, 201 fetches, etc. 202 203 If the value given starts and ends with slashes (C</>) then it will be 204 treated as a regular expression. For example, to only include SELECT 205 queries where key1 is the statement: 206 207 dbiprof --match key1=/^SELECT/ 208 209 By default the match expression is matched case-insensitively, but 210 this can be changed with the --case-sensitive option. 211 212 =item --exclude keyN=value 213 214 Remove items for where the specified key matches the given value. For 215 example, to exclude all prepare entries where key2 is the method name: 216 217 dbiprof --exclude key2=prepare 218 219 Like C<--match>, If the value given starts and ends with slashes 220 (C</>) then it will be treated as a regular expression. For example, 221 to exclude UPDATE queries where key1 is the statement: 222 223 dbiprof --match key1=/^UPDATE/ 224 225 By default the exclude expression is matched case-insensitively, but 226 this can be changed with the --case-sensitive option. 227 228 =item --case-sensitive 229 230 Using this option causes --match and --exclude to work 231 case-sensitively. Defaults to off. 232 233 =item --delete 234 235 Sets the C<DeleteFiles> option to L<DBI::ProfileData> which causes the 236 files to be deleted after reading. See L<DBI::ProfileData> for more details. 237 238 =item --dumpnodes 239 240 Print the list of nodes in the form of a perl data structure. 241 Use the C<-sort> option if you want the list sorted. 242 243 =item --version 244 245 Print the dbiprof version number and exit. 246 247 =back 248 249 =head1 AUTHOR 250 251 Sam Tregar <sam@tregar.com> 252 253 =head1 COPYRIGHT AND LICENSE 254 255 Copyright (C) 2002 Sam Tregar 256 257 This program is free software; you can redistribute it and/or modify 258 it under the same terms as Perl 5 itself. 259 260 =head1 SEE ALSO 261 262 L<DBI::ProfileDumper|DBI::ProfileDumper>, 263 L<DBI::Profile|DBI::Profile>, L<DBI|DBI>. 264 265 =cut 266
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |