Skip to content

Commit

Permalink
Add option --profile-filename=s
Browse files Browse the repository at this point in the history
this makes it easier to automate the generation of profiles
  • Loading branch information
moritz committed Feb 21, 2015
1 parent e4193d1 commit edd4dc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/HLL/Compiler.nqp
Expand Up @@ -20,7 +20,7 @@ class HLL::Compiler does HLL::Backend::Default {
@!stages := nqp::split(' ', 'start parse ast ' ~ $!backend.stages());

# Command options and usage.
@!cmdoptions := nqp::split(' ', 'e=s help|h target=s trace|t=s encoding=s output|o=s combine version|v show-config verbose-config|V stagestats=s? ll-exception rxtrace nqpevent=s profile profile-compile');
@!cmdoptions := nqp::split(' ', 'e=s help|h target=s trace|t=s encoding=s output|o=s combine version|v show-config verbose-config|V stagestats=s? ll-exception rxtrace nqpevent=s profile profile-compile profile-filename=s');
%!config := nqp::hash();
}

Expand Down Expand Up @@ -148,7 +148,7 @@ class HLL::Compiler does HLL::Backend::Default {
}

if (%adverbs<profile>) {
$output := $!backend.run_profiled({ $output(|@args) });
$output := $!backend.run_profiled({ $output(|@args) }, %adverbs<profile-filename>);
}
elsif %adverbs<trace> {
$output := $!backend.run_traced(%adverbs<trace>, { $output(|@args) });
Expand Down
17 changes: 11 additions & 6 deletions src/vm/moar/HLL/Backend.nqp
Expand Up @@ -37,19 +37,19 @@ class HLL::Backend::MoarVM {
)))));
}
}
method run_profiled($what) {
method run_profiled($what, $filename) {
my @END := nqp::gethllsym('perl6', '@END_PHASERS');
@END.push: -> { self.dump_profile_data($prof_end_sub()) } if nqp::defined(@END);
self.ensure_prof_routines();
$prof_start_sub(nqp::hash());
my $res := $what();
unless nqp::defined(@END) {
my $data := $prof_end_sub();
self.dump_profile_data($data);
self.dump_profile_data($data, $filename);
}
$res;
}
method dump_profile_data($data) {
method dump_profile_data($data, $filename) {
my @pieces := nqp::list_s();

sub post_process_call_graph_node($node) {
Expand Down Expand Up @@ -137,9 +137,14 @@ class HLL::Backend::MoarVM {
$template := slurp(nqp::backendconfig()<prefix> ~ '/languages/nqp/lib/profiler/template.html');
}
my $results := subst($template, /'{{{PROFIELR_OUTPUT}}}'/, $json);
my $filename := 'profile-' ~ nqp::time_n() ~ '.html';
spew($filename, $results);
nqp::sayfh(nqp::getstderr(), "Wrote profiler output to $filename");
if nqp::defined($filename) {
spew($filename, $results);
}
else {
my $filename := 'profile-' ~ nqp::time_n() ~ '.html';
spew($filename, $results);
nqp::sayfh(nqp::getstderr(), "Wrote profiler output to $filename");
}
}

method run_traced($level, $what) {
Expand Down

0 comments on commit edd4dc9

Please sign in to comment.