@@ -50,34 +50,6 @@ class HLL::Backend::MoarVM {
50
50
$ res ;
51
51
}
52
52
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
-
81
53
my @ pieces := nqp ::list_s();
82
54
83
55
sub post_process_call_graph_node ($ node ) {
@@ -148,8 +120,8 @@ class HLL::Backend::MoarVM {
148
120
nqp ::die(" Don't know how to dump a " ~ $ obj . HOW . name ($ obj ));
149
121
}
150
122
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 );
153
125
}
154
126
}
155
127
@@ -160,11 +132,22 @@ class HLL::Backend::MoarVM {
160
132
161
133
# JSONify the data.
162
134
to_json($ data );
163
- nqp ::printfh( $ profiler-fh , nqp :: join (' ' , @ pieces ) );
135
+ my $ json := nqp :: join (' ' , @ pieces );
164
136
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
+ }
168
151
}
169
152
170
153
method run_traced ($ level , $ what ) {
0 commit comments