Author: timbo
Date: Tue May 29 05:20:25 2007
New Revision: 9618

Modified:
   dbi/trunk/Changes
   dbi/trunk/dbiprof.PL
   dbi/trunk/lib/DBI/ProfileData.pm
   dbi/trunk/lib/DBI/ProfileDumper.pm
   dbi/trunk/lib/DBI/ProfileDumper/Apache.pm
   dbi/trunk/t/41prof_dump.t

Log:
Added ability to sort by Path elements.
Added --dumpnodes option.
Added Dir=>... to specify a writable destination directory.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Tue May 29 05:20:25 2007
@@ -8,6 +8,8 @@
 
 Assorted TODO notes:
 
+Protect trace_msg from SIGPIPE?
+
 Add count of identical frozen_request (plus sum(results size)) to Gofer status
 Highlight those seen before.
 
@@ -45,15 +47,20 @@
 
   DBI::ProfileDumper changes:
     Don't write file if there's no profile data.
-    Use full natural precision (was using %.6f).
+    Use full natural precision when saving data (was using %.6f)
     Optimized flush_to_disk().
     Lock the data file while writing.
     Added $profile->filename method.
     Enabled filename to be a code ref for dynamic names.
   DBI::ProfileDumper::Apache changes:
     Added Quiet=>1 to avoid write to STDERR in flush_to_disk().
-    Enable DBI_PROFILE_APACHE_LOG_DIR for mod_perl 1 as well as 2.
+    Added Dir=>... to specify a writable destination directory.
+    Enabled DBI_PROFILE_APACHE_LOG_DIR for mod_perl 1 as well as 2.
     Added parent pid to default data file name.
+  DBI::ProfileData changes:
+    Added ability to sort by Path elements.
+  dbiprof changes:
+    Added --dumpnodes option.
   Added/updated docs for both DBI::ProfileDumper && ::Apache.
 
 =head2 Changes in DBI 1.56 (svn rev 9561),  13th May 2007

Modified: dbi/trunk/dbiprof.PL
==============================================================================
--- dbi/trunk/dbiprof.PL        (original)
+++ dbi/trunk/dbiprof.PL        Tue May 29 05:20:25 2007
@@ -9,6 +9,7 @@
 
 my $VERSION = sprintf("1.%06d", q$Revision$ =~ /(\d+)/o);
 
+use Data::Dumper;
 use DBI::ProfileData;
 use Getopt::Long;
 
@@ -26,6 +27,7 @@
            'help'           => sub { exit usage() },
            'number=i'       => \$number,
            'sort=s'         => \$sort,
+           'dumpnodes!'     => \my $dumpnodes,
            'reverse'        => \$reverse,
            'match=s'        => \%match,
            'exclude=s'      => \%exclude,
@@ -86,7 +88,16 @@
 $prof->sort(field => $sort, reverse => $reverse);
 
 # all done, print it out
-print $prof->report(number => $number);
+if ($dumpnodes) {
+    $Data::Dumper::Indent    = 1;
+    $Data::Dumper::Terse     = 1;
+    $Data::Dumper::Useqq     = 1;
+    $Data::Dumper::Deparse   = 0;
+    print Dumper($prof->nodes);
+}
+else {
+    print $prof->report(number => $number);
+}
 exit 0;
 
 __END__
@@ -130,7 +141,8 @@
 
 =item --sort field
 
-Sort results by the given field.  The available sort fields are:
+Sort results by the given field. Sorting by multiple fields isn't currently
+supported (patches welcome).  The available sort fields are:
 
 =over 4
 
@@ -155,6 +167,11 @@
 
 Sorts by the shortest single run.
 
+=item key1
+
+Sorts by the value of the first element in the Path, which should be numeric.
+You can also sort by C<key2> and C<key3>.
+
 =back
 
 =item --reverse
@@ -209,6 +226,11 @@
 Using this option causes --match and --exclude to work
 case-sensitively.  Defaults to off.
 
+=item --dumpnodes
+
+Print the list of nodes in the form of a perl data structure.
+Use the C<-sort> option if you want the list sorted.
+
 =item --version
 
 Print the dbiprof version number and exit.

Modified: dbi/trunk/lib/DBI/ProfileData.pm
==============================================================================
--- dbi/trunk/lib/DBI/ProfileData.pm    (original)
+++ dbi/trunk/lib/DBI/ProfileData.pm    Tue May 29 05:20:25 2007
@@ -373,6 +373,9 @@
                   total    => TOTAL,
                   count    => COUNT,
                   shortest => SHORTEST,
+                  key1     => PATH+0,
+                  key2     => PATH+1,
+                  key3     => PATH+2,
                  );
     sub sort {
         my $self = shift;

Modified: dbi/trunk/lib/DBI/ProfileDumper.pm
==============================================================================
--- dbi/trunk/lib/DBI/ProfileDumper.pm  (original)
+++ dbi/trunk/lib/DBI/ProfileDumper.pm  Tue May 29 05:20:25 2007
@@ -258,7 +258,9 @@
 
 # empty out profile data
 sub empty {
-    shift->{Data} = undef;
+    my $self = shift;
+    DBI->trace_msg("profile data discarded\n",0) if $self->{Trace};
+    $self->{Data} = undef;
 }
 
 

Modified: dbi/trunk/lib/DBI/ProfileDumper/Apache.pm
==============================================================================
--- dbi/trunk/lib/DBI/ProfileDumper/Apache.pm   (original)
+++ dbi/trunk/lib/DBI/ProfileDumper/Apache.pm   Tue May 29 05:20:25 2007
@@ -55,7 +55,15 @@
 =head2 WRITING PROFILE DATA
 
 The profile data files will be written to your Apache log directory by default.
-You can use the C<DBI_PROFILE_APACHE_LOG_DIR> env var to change that. For 
example:
+
+The user that the httpd processes run as will need write access to the
+directory.  So, for example, if you're running the child httpds as user 
'nobody'
+and using chronolog to write to the logs directory, then you'll need to change
+the default.
+
+You can change the destination directory either by secifying a C<Dir> value
+when creating the profile (like C<File> in the L<DBI::ProfileDumper> docs),
+or you can use the C<DBI_PROFILE_APACHE_LOG_DIR> env var to change that. For 
example:
 
   PerlSetEnv DBI_PROFILE_APACHE_LOG_DIR /server_root/logs
 
@@ -122,7 +130,9 @@
 
 Then restart your server and get back to work.
 
-=head1 MEMORY USAGE
+=head1 OTHER ISSUES
+
+=head2 Memory usage
 
 DBI::Profile can use a lot of memory for very active applications because it
 collects profiling data in memory for each distinct query run.
@@ -178,19 +188,22 @@
     $server_root_dir = eval { Apache->server_root_relative('') } || "/tmp";
 }
 
-my $dest_dir = $ENV{DBI_PROFILE_APACHE_LOG_DIR} || 
File::Spec->catdir($server_root_dir, "logs");
-
 
 if (UNIVERSAL::can($apache_server, "push_handlers")) {
     $apache_server->push_handlers(PerlChildInitHandler => sub {
         $parent_pid = getppid();
         #warn "PerlChildInitHandler pid$$ has ppid $parent_pid";
-        # update dest_dir from DBI_PROFILE_APACHE_LOG_DIR now
-        $dest_dir = $ENV{DBI_PROFILE_APACHE_LOG_DIR} if 
$ENV{DBI_PROFILE_APACHE_LOG_DIR};
         OK();
     });
 }
 
+sub dirname {
+    my $self = shift;
+    return $self->{Dir} if $self->{Dir};
+    $self->{Dir} ||= $ENV{DBI_PROFILE_APACHE_LOG_DIR};
+    return $self->{Dir} || File::Spec->catdir($server_root_dir, "logs");
+}
+
 sub filename {
     my $self = shift;
     my $filename = $self->SUPER::filename(@_);
@@ -199,7 +212,7 @@
     # as well as the pid.
     $filename .= ".$parent_pid.$$";
     return $filename if File::Spec->file_name_is_absolute($filename);
-    return File::Spec->catfile($dest_dir, $filename);
+    return File::Spec->catfile($self->dirname, $filename);
 }
 
 

Modified: dbi/trunk/t/41prof_dump.t
==============================================================================
--- dbi/trunk/t/41prof_dump.t   (original)
+++ dbi/trunk/t/41prof_dump.t   Tue May 29 05:20:25 2007
@@ -83,6 +83,8 @@
 
 # unlink("dbi.prof"); # now done by 'make clean'
 
-require_ok('DBI::ProfileDumper::Apache'); # should be able to load 
DBI::ProfileDumper::Apache outside apache
+# should be able to load DBI::ProfileDumper::Apache outside apache
+# this also naturally checks for syntax errors etc.
+require_ok('DBI::ProfileDumper::Apache');
 
 1;

Reply via email to