Author: tim.bunce
Date: Sun Nov 23 15:13:57 2008
New Revision: 620

Added:
    trunk/lib/Devel/NYTProf/js/asc.png   (contents, props changed)
    trunk/lib/Devel/NYTProf/js/bg.png   (contents, props changed)
    trunk/lib/Devel/NYTProf/js/desc.png   (contents, props changed)
    trunk/lib/Devel/NYTProf/js/style.tablesorter.css
Modified:
    trunk/Changes
    trunk/MANIFEST
    trunk/bin/nytprofhtml

Log:
Summary tables can be sorted by clicking on header columns. Woot!
Not quite perfect yet, but pretty good.


Modified: trunk/Changes
==============================================================================
--- trunk/Changes       (original)
+++ trunk/Changes       Sun Nov 23 15:13:57 2008
@@ -6,6 +6,8 @@

  =head2 Changes in Devel::NYTProf 2.08

+Core:
+
    Added optimize=0 option to disable the perl optimizer
      so you can see more accurate statement execution counts
      for some kinds of constructs.
@@ -13,10 +15,14 @@
    Added savesrc=1 option to copy source code into the profile
      so reports are not affected by changes to the source files.

+Reporting:
+
    Fixed searching @INC for source files for reports.

    Dramatically increased performance of nytprofhtml
      relative to the 2.07 version.
+
+  Summary tables can be sorted by clicking on header columns.

    Statement timings are now shown as integers in appropriate
      units: seconds, milliseconds, microseconds or nanoseconds.

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Sun Nov 23 15:13:57 2008
@@ -25,8 +25,12 @@
  lib/Devel/NYTProf/SubInfo.pm
  lib/Devel/NYTProf/Test.pm
  lib/Devel/NYTProf/Util.pm
+lib/Devel/NYTProf/js/asc.png
+lib/Devel/NYTProf/js/bg.png
+lib/Devel/NYTProf/js/desc.png
  lib/Devel/NYTProf/js/jquery.min.js
  lib/Devel/NYTProf/js/jquery.tablesorter.min.js
+lib/Devel/NYTProf/js/style.tablesorter.css
  perftest.pl
  ppport.h
  t/00.load.t

Modified: trunk/bin/nytprofhtml
==============================================================================
--- trunk/bin/nytprofhtml       (original)
+++ trunk/bin/nytprofhtml       Sun Nov 23 15:13:57 2008
@@ -36,6 +36,8 @@

  use constant NUMERIC_PRECISION => 5;

+my @on_ready_js;
+
  my %opt = (
      file => 'nytprof.out',
      out  => 'nytprof',
@@ -174,7 +176,7 @@

      my $sortby_desc = ($sortby eq 'excl_time') ? "exclusive  
time" : "inclusive time";
      $sub_links .= qq{
-        <table id="subroutines" border="1" cellpadding="0">
+        <table id="subs_table" border="1" cellpadding="0"  
class="tablesorter">
          <caption>${qualifier}Subroutines &mdash; ordered by  
$sortby_desc</caption>
          <thead>
          <tr>
@@ -236,8 +238,20 @@

          $sub_links .= "</tr>\n";
      }
-    $sub_links .= "</tbody>\n";
-    $sub_links .= "</table>\n";
+    $sub_links .= q{
+        </tbody>
+        </table>
+    };
+    # sort on 4th col (excl_time,desc) then 6th (pkg) and 7th (name)
+    push @on_ready_js, q{
+        $("#subs_table").tablesorter({
+            sortList: [[3,1],[5,0],[6,0]],
+            headers: {
+                3: { sorter: 'fmt_time' },
+                4: { sorter: 'fmt_time' }
+            }
+        });
+    };

      return $sub_links;
  }
@@ -519,9 +533,9 @@

  sub output_js_files {
      my ($profile) = @_;
-    # find the js files installed with Devel::NYTProf
+    # find the js, gif, css etc files installed with Devel::NYTProf
      (my $lib = $INC{"Devel/NYTProf/Data.pm"}) =~ s/Data\.pm$//;
-    for my $src (<$lib/js/*.js>) {
+    for my $src (<$lib/js/*>) {
          (my $file = $src) =~ s/.*\///;
          unlink "$opt{out}/$file";
          copy($src, "$opt{out}/$file")
@@ -602,7 +616,7 @@

      # generate time-sorted sections for files
      print OUT qq{
-        <table border="1" cellspacing="0">
+        <table id="filestable" border="1" cellspacing="0"  
class="tablesorter">
          <caption>Source Code Files &mdash; ordered by exclusive time then  
name</caption>
      };
      print OUT qq{
@@ -662,7 +676,7 @@
              my $eval_fileinfos = grep { $_->eval_line }  
$profile->all_fileinfos;
              $stmt_time_diff = ($stmt_time_diff > 0.000_010)
                  ? sprintf(" and %s", fmt_time($stmt_time_diff)) : "";
-            $t_notes = sprintf "(%d string evals account for a further %d  
statements%s)</i>",
+            $t_notes = sprintf "(%d string evals account for a further %d  
statements%s)",
                  $eval_fileinfos, $allCalls - $t_stmt_exec, $stmt_time_diff;
          }
          print OUT sprintf $stats_fmt, fmt_float($t_stmt_exec),  
fmt_time($t_stmt_time), '',
@@ -680,6 +694,17 @@
          print OUT "</tfoot>\n";
      }
      print OUT '</table>';
+    # sort on 2nd col (excl_time,desc) then 5th (name)
+    push @on_ready_js, q{
+        $("#filestable").tablesorter({
+            sortList: [[1,1],[4,0]],
+            headers: {
+                1: { sorter: 'fmt_time' },
+                2: { sorter: 'fmt_time' },
+                3: { sorter: false      }
+            }
+        });
+    };

      return "";
  }
@@ -787,9 +812,21 @@
      my ($profile) = @_;
      my $version = $Devel::NYTProf::Core::VERSION;

+    my $js = '';
+    if (@on_ready_js) {
+        # XXX I've no idea why this workaround is needed (or works).
+        # without it the file table on the index page isn't sortable
+        @on_ready_js = reverse @on_ready_js;
+        $js = sprintf q{
+            <script type="text/javascript"> $(document).ready(function()  
{ %s } ); </script>
+        }, join("\n", '', @on_ready_js, '');
+        @on_ready_js = ();
+    };
+
      # spacing so links to #line near can put right line at top near the  
bottom of the report
      my $spacing = "<br />" x 10;
      return qq{
+        $js
          <div class="footer">Report produced by the
          <a href="http://search.cpan.org/dist/Devel-NYTProf/";>NYTProf  
$version</a>
          Perl profiler, developed by
@@ -809,15 +846,38 @@
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
  <html xmlns="http://www.w3.org/1999/xhtml";>
  <!--
-This file was generated by Devel::NYTProf::Reader HTML Version $VERSION
-using Devel::NYTProf Version $Devel::NYTProf::Core::VERSION
-These modules are free. They are licensed under the same terms as Perl  
itself.
+This file was generated by Devel::NYTProf version  
$Devel::NYTProf::Core::VERSION
  -->
  <head>
      <meta http-equiv="Content-Type" content="text/html;  
charset=utf-8"></meta>
      <meta http-equiv="Content-Language" content="en-us"></meta>
      <link rel="stylesheet" type="text/css" href="style.css"></link>
      <title>$title</title>
+    <script type="text/javascript" src="jquery.min.js"></script>
+    <script type="text/javascript"  
src="jquery.tablesorter.min.js"></script>
+    <link rel="stylesheet" type="text/css"  
href="style.tablesorter.css"></link>
+    <script type="text/javascript">
+    // add parser through the tablesorter addParser method
+    \$.tablesorter.addParser({
+        id: 'fmt_time',   // name of this parser
+        is: function(s) {
+            return false; // return false so this parser is not auto  
detected
+        },
+        format: function(orig) { // format data for normalization
+            // console.log(orig);
+            var val = orig.replace(/ms/,'');
+            if (val != orig) { return val / (1000); }
+            val = orig.replace(/µs/,''); /* XXX use &micro; ? */
+            if (val != orig) { return val / (1000*1000); }
+            val = orig.replace(/ns/,'');
+            if (val != orig) { return val / (1000*1000*1000); }
+            console.log('no match for fmt_time of '.concat(orig));
+            return orig;
+        },
+        type: 'numeric' // set type, either numeric or text
+    });
+    </script>
+
  </head>
  EOD
  }
@@ -922,7 +982,7 @@
  body { font-family: sans-serif; margin: 0px; }
  .body_content { margin: 8px; }

-.header { font-family: sans-serif; padding-left: 1em; }
+.header { font-family: sans-serif; padding-left: 0.5em; padding-right:  
0.5em; }
  .headerForeground { color: white; padding: 10px; padding-top: 50px; }
  .siteTitle { font-size: 2em; }
  .siteSubTitle { font-size: 1.2em; }
@@ -994,7 +1054,6 @@
    font-family: monospace;
    color: gray;
  }
-
  td.sub_sub {
    text-align: left;
    padding-left: 0;
@@ -1039,18 +1098,10 @@
   *   c3  : path covered or coverage = 100%
   */
  .c0, .c1, .c2, .c3 { text-align: right; }
-.c0 {
-    background-color: #ff9999;
-}
-.c1 {
-    background-color: #ffcc99;
-}
-.c2 {
-    background-color: #ffff99;
-}
-.c3 {
-    background-color: #99ff99;
-}
+.c0 { background-color: #ff9999; }
+.c1 { background-color: #ffcc99; }
+.c2 { background-color: #ffff99; }
+.c3 { background-color: #99ff99; }

  /* warnings */
  .warn {
@@ -1060,7 +1111,6 @@
      text-align: center;
      padding: 5px 0;
  }
-
  .warn_title {
      background-color: #FFFFAA;
      border: 0;
@@ -1086,9 +1136,9 @@
  .calls       a       { color: gray;  text-decoration: none; }
  .calls:hover a       { color: black; text-decoration: underline; }
  .calls:hover a:hover { color: red; }
-
  /* give a little headroom to the summary of calls into a sub */
  .calls .calls_in { margin-top: 5px; }
+
  EOD
  }


Added: trunk/lib/Devel/NYTProf/js/asc.png
==============================================================================
Binary file. No diff available.

Added: trunk/lib/Devel/NYTProf/js/bg.png
==============================================================================
Binary file. No diff available.

Added: trunk/lib/Devel/NYTProf/js/desc.png
==============================================================================
Binary file. No diff available.

Added: trunk/lib/Devel/NYTProf/js/style.tablesorter.css
==============================================================================
--- (empty file)
+++ trunk/lib/Devel/NYTProf/js/style.tablesorter.css    Sun Nov 23 15:13:57  
2008
@@ -0,0 +1,9 @@
+/* tables */
+table.tablesorter thead tr .header {
+    /* background-image: url(bg.png); */
+    background-repeat: no-repeat;
+    background-position: 0% 80%;
+    cursor: pointer;
+}
+table.tablesorter thead tr .headerSortUp   { background-image:  
url(asc.png); }
+table.tablesorter thead tr .headerSortDown { background-image:  
url(desc.png); }

--~--~---------~--~----~------------~-------~--~----~
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.

Group hosted at:  http://groups.google.com/group/develnytprof-dev
Project hosted at:  http://perl-devel-nytprof.googlecode.com
CPAN distribution:  http://search.cpan.org/dist/Devel-NYTProf

To post, email:  [email protected]
To unsubscribe, email:  [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to