From 4c26ead649e3118c016577279ed1fec491cca453 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 28 Jun 2010 16:32:01 +0200 Subject: [PATCH] generate profile output --- lib/MojoFacets/Plugin/NYTProf.pm | 2 +- lib/MojoFacets/Profile.pm | 30 ++++++++++++++++++++++++++++++ templates/admin.html.ep | 2 +- templates/profile/index.html.ep | 11 +++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 lib/MojoFacets/Profile.pm create mode 100644 templates/profile/index.html.ep diff --git a/lib/MojoFacets/Plugin/NYTProf.pm b/lib/MojoFacets/Plugin/NYTProf.pm index 7cf729a..4bc2f5a 100644 --- a/lib/MojoFacets/Plugin/NYTProf.pm +++ b/lib/MojoFacets/Plugin/NYTProf.pm @@ -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 index 0000000..689f49e --- /dev/null +++ b/lib/MojoFacets/Profile.pm @@ -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 diff --git a/templates/admin.html.ep b/templates/admin.html.ep index 5d01f8e..d98a64c 100644 --- a/templates/admin.html.ep +++ b/templates/admin.html.ep @@ -21,7 +21,7 @@ items: % if ( my $id = stash('nytprof.id') ) { · -profile +profile % } diff --git a/templates/profile/index.html.ep b/templates/profile/index.html.ep new file mode 100644 index 0000000..fea1ecb --- /dev/null +++ b/templates/profile/index.html.ep @@ -0,0 +1,11 @@ +% layout 'default'; + + + +
<%= dumper $profiles %>
-- 2.20.1