Skip to content

Commit

Permalink
Revert "write out json pieces directly; allow .json profile filenames"
Browse files Browse the repository at this point in the history
This reverts commit 466d719.

flussence++ made a better pull request
  • Loading branch information
timo committed Apr 18, 2015
1 parent 466d719 commit 783bf9a
Showing 1 changed file with 17 additions and 34 deletions.
51 changes: 17 additions & 34 deletions src/vm/moar/HLL/Backend.nqp
Expand Up @@ -50,34 +50,6 @@ class HLL::Backend::MoarVM {
$res;
}
method dump_profile_data($data, $filename) {
# Insert it into a template and write it.
# (but only use the template if we want an html output file at all)

my $wants-html := !nqp::defined($filename) || ($filename ~~ / '.html' $ /).Bool;

# in this variable we store anything that comes after the json data
my $post-text := "";
$filename := $filename || ('profile-' ~ nqp::time_n() ~ '.html');

my $profiler-fh := nqp::open($filename, "w");

if $wants-html {
my str $template := try slurp('src/vm/moar/profiler/template.html');
unless $template {
$template := slurp(nqp::backendconfig()<prefix> ~ '/share/nqp/lib/profiler/template.html');
}

if $template {
my $find_placeholder := $template ~~ /'{{{PROFIELR_OUTPUT}}}'/;

nqp::printfh($profiler-fh, nqp::substr($template, 0, $find_placeholder.from));

$post-text := nqp::substr($template, $find_placeholder.to);
} else {
nqp::sayfh(nqp::getstderr(), "couldn't find the profiler template.html; will output raw json instead");
}
}

my @pieces := nqp::list_s();

sub post_process_call_graph_node($node) {
Expand Down Expand Up @@ -148,8 +120,8 @@ class HLL::Backend::MoarVM {
nqp::die("Don't know how to dump a " ~ $obj.HOW.name($obj));
}
if nqp::elems(@pieces) > 4096 {
nqp::printfh($profiler-fh, nqp::join('', @pieces));
nqp::setelems(@pieces, 0);
nqp::bindpos_s(@pieces, 0, nqp::join('', @pieces));
nqp::setelems(@pieces, 1);
}
}

Expand All @@ -160,11 +132,22 @@ class HLL::Backend::MoarVM {

# JSONify the data.
to_json($data);
nqp::printfh($profiler-fh, nqp::join('', @pieces));
my $json := nqp::join('', @pieces);

nqp::printfh($profiler-fh, $post-text);

nqp::sayfh(nqp::getstderr(), "Wrote profiler output to $filename");
# Insert it into a template and write it.
my $template := try slurp('src/vm/moar/profiler/template.html');
unless $template {
$template := slurp(nqp::backendconfig()<prefix> ~ '/share/nqp/lib/profiler/template.html');
}
my $results := subst($template, /'{{{PROFIELR_OUTPUT}}}'/, $json);
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 783bf9a

Please sign in to comment.