generate profile output
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 28 Jun 2010 14:32:01 +0000 (16:32 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 28 Jun 2010 14:32:01 +0000 (16:32 +0200)
lib/MojoFacets/Plugin/NYTProf.pm
lib/MojoFacets/Profile.pm [new file with mode: 0644]
templates/admin.html.ep
templates/profile/index.html.ep [new file with mode: 0644]

index 7cf729a..4bc2f5a 100644 (file)
@@ -28,7 +28,7 @@ sub register {
                        my $duration = Time::HiRes::gettimeofday() - $id;
                        if ( $duration > $p ) {
                                my $path = "/tmp/nytprof.$id";
-                               my $new  = "/tmp/MojoFacets.profile-$id-$duration";
+                               my $new  = "/tmp/MojoFacets.profile.$id-$duration";
                                rename $path, $new;
                                warn "profile $new $duration ", -s $new, " bytes\n";
                        } else {
diff --git a/lib/MojoFacets/Profile.pm b/lib/MojoFacets/Profile.pm
new file mode 100644 (file)
index 0000000..689f49e
--- /dev/null
@@ -0,0 +1,30 @@
+package MojoFacets::Profile;
+
+use strict;
+use warnings;
+
+use base 'Mojolicious::Controller';
+
+use Data::Dump qw(dump);
+use File::Path;
+
+sub index {
+       my $self = shift;
+
+       my $path = '/tmp/MojoFacets.profile.';
+
+       if ( my $profile = $self->param('profile') ) {
+warn "XXX profile $profile\n";
+               my $dir = $self->app->home->rel_dir('public') . "/profile/$profile";
+               mkpath $dir unless -d $dir;
+               system "nytprofhtml --file $path$profile --out $dir";
+               $self->redirect_to("/profile/$profile/index.html");
+       }
+
+
+       $self->render(
+               profiles => [ map { s/^\Q$path\E//; $_ } glob "$path*" ],
+       );
+}
+
+1
index 5d01f8e..d98a64c 100644 (file)
@@ -21,7 +21,7 @@ items:
 
 % if ( my $id = stash('nytprof.id') ) {
 &middot;
-<a href="<%= url_for( controller => 'profile', action => 'index', id => $id ) %>">profile</a>
+<a href="<%= url_for( controller => 'profile', action => 'index', id => 0 ) %>">profile</a>
 % }
 
 <span class=middle>
diff --git a/templates/profile/index.html.ep b/templates/profile/index.html.ep
new file mode 100644 (file)
index 0000000..fea1ecb
--- /dev/null
@@ -0,0 +1,11 @@
+% layout 'default';
+
+<ul>
+% foreach my $profile ( @$profiles ) {
+%  my ( $t, $duration ) = split(/-/,$profile,2);
+<li><a target="<%= $profile %>" href="<%= url_for()->query( profile => $profile ) %>"><%= $t %></a> <%= $duration %>
+</li>
+% }
+</ul>
+
+<pre class=debug><%= dumper $profiles %></pre>