@@ -590,48 +590,46 @@ class HLL::Backend::MoarVM {
590
590
$ thisprof [3 ] := ~ $ v ;
591
591
}
592
592
elsif $ k eq ' call_graph' {
593
- my $ prev-outputted := " " ;
593
+ my $ is_first := 1 ;
594
594
595
595
my % call_rec_depth ;
596
596
$ thisprof [4 ] := ~ $ node_id ;
597
+
598
+ my $ allocation_pieces := nqp ::list_s;
599
+ nqp ::push_s($ allocation_pieces , ' INSERT INTO allocations VALUES (' );
600
+
601
+ nqp ::push_s($ pieces , ' INSERT INTO calls VALUES ' );
602
+
597
603
sub collect_calls (str $ parent_id , % call_graph ) {
598
604
my str $ call_id := ~ $ node_id ;
599
605
$ node_id ++ ;
600
606
my @ call := nqp ::list_s($ call_id , $ parent_id );
601
607
for <id osr spesh_entries jit_entries inlined_entries inclusive_time exclusive_time entries deopt_one deopt_all > -> $ f {
602
608
nqp ::push_s(@ call , ~ (% call_graph {$ f } // ' 0' ));
603
609
}
610
+ if $ is_first {
611
+ $ is_first := 0 ;
612
+ }
613
+ else {
614
+ nqp ::push_s($ pieces , " ),\n " );
615
+ }
604
616
my str $ routine_id := ~ % call_graph <id >;
605
617
% call_rec_depth {$ routine_id } := 0 unless % call_rec_depth {$ routine_id };
606
618
nqp ::push_s(@ call , ~ % call_rec_depth {$ routine_id });
607
619
nqp ::push_s(@ call , ~ % call_graph <first_entry_time >);
608
620
nqp ::push_s(@ call , ~ % call_graph <highest_child_id >);
609
- if $ prev-outputted ne " calls" {
610
- nqp ::push_s($ pieces , ' INSERT INTO calls VALUES ' );
611
- }
612
- else {
613
- nqp ::push_s($ pieces , " ),\n " );
614
- }
615
621
nqp ::push_s($ pieces , " (" ~ nqp :: join (' ,' , @ call ));
616
- $ prev-outputted := " calls" ;
617
622
if % call_graph <allocations > {
618
623
for % call_graph <allocations > -> $ a {
619
624
my @ a := nqp ::list_s($ call_id );
620
625
for <id spesh jit count replaced > -> $ f {
621
626
nqp ::push_s(@ a , ~ ($ a {$ f } // ' 0' ));
622
627
}
623
- if $ prev-outputted eq " allocations" {
624
- nqp ::push_s($ pieces , " ,\n (" );
625
- }
626
- else {
627
- nqp ::push_s($ pieces , " );\n " );
628
- nqp ::push_s($ pieces , ' INSERT INTO allocations VALUES (' );
628
+ if nqp :: elems ($ allocation_pieces ) > 1 {
629
+ nqp ::push_s($ allocation_pieces , " ,\n (" );
629
630
}
630
- nqp ::push_s($ pieces , nqp :: join (' ,' , @ a ) ~ " )" );
631
- $ prev-outputted := " allocations" ;
631
+ nqp ::push_s($ allocation_pieces , nqp :: join (' ,' , @ a ) ~ " )" );
632
632
}
633
- nqp ::push_s($ pieces , " ;\n " );
634
- $ prev-outputted := " allocs" ;
635
633
}
636
634
if % call_graph <callees > {
637
635
% call_rec_depth {$ routine_id }++ ;
@@ -646,7 +644,10 @@ class HLL::Backend::MoarVM {
646
644
}
647
645
}
648
646
collect_calls(~ $ node_id , $ v );
649
- # nqp::push_s($pieces, ");\n");
647
+ nqp ::push_s($ pieces , " );\n " );
648
+ if nqp :: elems ($ allocation_pieces ) > 1 {
649
+ nqp ::push_s($ pieces , nqp :: join (' ' , $ allocation_pieces ) ~ " ;\n " );
650
+ }
650
651
}
651
652
}
652
653
nqp ::push_s($ pieces , ' INSERT INTO profile VALUES (' );
0 commit comments