Skip to content

Commit 783bf9a

Browse files
committed
Revert "write out json pieces directly; allow .json profile filenames"
This reverts commit 466d719. flussence++ made a better pull request
1 parent 466d719 commit 783bf9a

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

src/vm/moar/HLL/Backend.nqp

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,6 @@ class HLL::Backend::MoarVM {
5050
$res;
5151
}
5252
method dump_profile_data($data, $filename) {
53-
# Insert it into a template and write it.
54-
# (but only use the template if we want an html output file at all)
55-
56-
my $wants-html := !nqp::defined($filename) || ($filename ~~ / '.html' $ /).Bool;
57-
58-
# in this variable we store anything that comes after the json data
59-
my $post-text := "";
60-
$filename := $filename || ('profile-' ~ nqp::time_n() ~ '.html');
61-
62-
my $profiler-fh := nqp::open($filename, "w");
63-
64-
if $wants-html {
65-
my str $template := try slurp('src/vm/moar/profiler/template.html');
66-
unless $template {
67-
$template := slurp(nqp::backendconfig()<prefix> ~ '/share/nqp/lib/profiler/template.html');
68-
}
69-
70-
if $template {
71-
my $find_placeholder := $template ~~ /'{{{PROFIELR_OUTPUT}}}'/;
72-
73-
nqp::printfh($profiler-fh, nqp::substr($template, 0, $find_placeholder.from));
74-
75-
$post-text := nqp::substr($template, $find_placeholder.to);
76-
} else {
77-
nqp::sayfh(nqp::getstderr(), "couldn't find the profiler template.html; will output raw json instead");
78-
}
79-
}
80-
8153
my @pieces := nqp::list_s();
8254

8355
sub post_process_call_graph_node($node) {
@@ -148,8 +120,8 @@ class HLL::Backend::MoarVM {
148120
nqp::die("Don't know how to dump a " ~ $obj.HOW.name($obj));
149121
}
150122
if nqp::elems(@pieces) > 4096 {
151-
nqp::printfh($profiler-fh, nqp::join('', @pieces));
152-
nqp::setelems(@pieces, 0);
123+
nqp::bindpos_s(@pieces, 0, nqp::join('', @pieces));
124+
nqp::setelems(@pieces, 1);
153125
}
154126
}
155127

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

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

165-
nqp::printfh($profiler-fh, $post-text);
166-
167-
nqp::sayfh(nqp::getstderr(), "Wrote profiler output to $filename");
137+
# Insert it into a template and write it.
138+
my $template := try slurp('src/vm/moar/profiler/template.html');
139+
unless $template {
140+
$template := slurp(nqp::backendconfig()<prefix> ~ '/share/nqp/lib/profiler/template.html');
141+
}
142+
my $results := subst($template, /'{{{PROFIELR_OUTPUT}}}'/, $json);
143+
if nqp::defined($filename) {
144+
spew($filename, $results);
145+
}
146+
else {
147+
my $filename := 'profile-' ~ nqp::time_n() ~ '.html';
148+
spew($filename, $results);
149+
nqp::sayfh(nqp::getstderr(), "Wrote profiler output to $filename");
150+
}
168151
}
169152

170153
method run_traced($level, $what) {

0 commit comments

Comments
 (0)