Skip to content

Commit ead2670

Browse files
committed
make profiler sql even smaller
by splitting all calls and allocations into two long runs rather than switching back and forth as we traverse the call graph.
1 parent 236c7eb commit ead2670

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/vm/moar/HLL/Backend.nqp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -590,48 +590,46 @@ class HLL::Backend::MoarVM {
590590
$thisprof[3] := ~$v;
591591
}
592592
elsif $k eq 'call_graph' {
593-
my $prev-outputted := "";
593+
my $is_first := 1;
594594

595595
my %call_rec_depth;
596596
$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+
597603
sub collect_calls(str $parent_id, %call_graph) {
598604
my str $call_id := ~$node_id;
599605
$node_id++;
600606
my @call := nqp::list_s($call_id, $parent_id);
601607
for <id osr spesh_entries jit_entries inlined_entries inclusive_time exclusive_time entries deopt_one deopt_all> -> $f {
602608
nqp::push_s(@call, ~(%call_graph{$f} // '0'));
603609
}
610+
if $is_first {
611+
$is_first := 0;
612+
}
613+
else {
614+
nqp::push_s($pieces, "),\n ");
615+
}
604616
my str $routine_id := ~%call_graph<id>;
605617
%call_rec_depth{$routine_id} := 0 unless %call_rec_depth{$routine_id};
606618
nqp::push_s(@call, ~%call_rec_depth{$routine_id});
607619
nqp::push_s(@call, ~%call_graph<first_entry_time>);
608620
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-
}
615621
nqp::push_s($pieces, "(" ~ nqp::join(',', @call));
616-
$prev-outputted := "calls";
617622
if %call_graph<allocations> {
618623
for %call_graph<allocations> -> $a {
619624
my @a := nqp::list_s($call_id);
620625
for <id spesh jit count replaced> -> $f {
621626
nqp::push_s(@a, ~($a{$f} // '0'));
622627
}
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 (");
629630
}
630-
nqp::push_s($pieces, nqp::join(',', @a) ~ ")");
631-
$prev-outputted := "allocations";
631+
nqp::push_s($allocation_pieces, nqp::join(',', @a) ~ ")");
632632
}
633-
nqp::push_s($pieces, ";\n");
634-
$prev-outputted := "allocs";
635633
}
636634
if %call_graph<callees> {
637635
%call_rec_depth{$routine_id}++;
@@ -646,7 +644,10 @@ class HLL::Backend::MoarVM {
646644
}
647645
}
648646
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+
}
650651
}
651652
}
652653
nqp::push_s($pieces, 'INSERT INTO profile VALUES (');

0 commit comments

Comments
 (0)