Skip to content

Commit d8bb96f

Browse files
committed
Merge branch 'smaller_profile_sql_output'
2 parents afa965c + d340e97 commit d8bb96f

File tree

1 file changed

+101
-25
lines changed

1 file changed

+101
-25
lines changed

src/vm/moar/HLL/Backend.nqp

Lines changed: 101 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -456,22 +456,46 @@ class HLL::Backend::MoarVM {
456456
my $mapping := nqp::shift($obj);
457457
my $pieces := nqp::list_s();
458458
my $empty-array := nqp::list_s();
459+
460+
nqp::push_s($pieces, "INSERT INTO routines VALUES ('");
461+
462+
my $is-first := 1;
463+
459464
for $mapping -> $k {
460465
my $v := $mapping{$k};
461466
if nqp::ishash($v) {
462-
nqp::push_s($pieces, "INSERT INTO routines VALUES ('");
467+
if !$is-first {
468+
nqp::push_s($pieces, ",\n('");
469+
}
470+
else { $is-first := 0 }
463471
nqp::push_s($pieces,
464472
nqp::join("','",
465473
nqp::list(
466474
nqp::iterkey_s($k),
467475
literal_subst(~$v<name>, "'", "''"),
468476
~$v<line>,
469477
~$v<file>))
470-
~ "');\n");
478+
~ "')");
471479
}
472-
else {
480+
if nqp::elems($pieces) > 500 {
481+
$profile_fh.print(nqp::join("", $pieces));
482+
nqp::splice($pieces, $empty-array, 0, nqp::elems($pieces));
483+
}
484+
}
485+
nqp::push_s($pieces, ";\n");
486+
487+
$is-first := 1;
488+
489+
nqp::push_s($pieces, "INSERT INTO types VALUES ('");
490+
491+
for $mapping -> $k {
492+
my $v := $mapping{$k};
493+
if !nqp::ishash($v) {
494+
if !$is-first {
495+
nqp::push_s($pieces, ",\n('");
496+
}
497+
else { $is-first := 0 }
473498
my $type-info := %type-info{nqp::iterkey_s($k)};
474-
nqp::push_s($pieces, "INSERT INTO types VALUES ('");
475499
nqp::push_s($pieces,
476500
nqp::join("','",
477501
nqp::list_s(
@@ -482,13 +506,15 @@ class HLL::Backend::MoarVM {
482506
~ to_sql_json($type-info[1])
483507
~ ","
484508
~ "json_object()"
485-
~ ");\n");
509+
~ ")");
486510
}
487511
if nqp::elems($pieces) > 500 {
488-
$profile_fh.say(nqp::join("", $pieces));
512+
$profile_fh.print(nqp::join("", $pieces));
489513
nqp::splice($pieces, $empty-array, 0, nqp::elems($pieces));
490514
}
491515
}
516+
nqp::push_s($pieces, ";\n");
517+
492518
for $obj -> $thread {
493519
my $thisprof := nqp::list;
494520
$thisprof[4] := "NULL";
@@ -506,57 +532,103 @@ class HLL::Backend::MoarVM {
506532
}
507533
elsif $k eq 'gcs' {
508534
my str $thread_id := $thread<thread>;
535+
if nqp::elems($v) > 0 {
536+
nqp::push_s($pieces, "INSERT INTO gcs VALUES (");
537+
}
538+
539+
my $any-deallocs := 0;
540+
541+
my $is-first := 1;
542+
509543
for $v -> $gc {
544+
if !$is-first {
545+
nqp::push_s($pieces, ",\n(");
546+
}
547+
else { $is-first := 0 }
510548
my @g := nqp::list_s();
511549
for <time retained_bytes promoted_bytes gen2_roots full responsible cleared_bytes start_time sequence> -> $f {
512550
nqp::push_s(@g, ~($gc{$f} // '0'));
513551
}
514552
nqp::push_s(@g, $thread_id);
515-
nqp::push_s($pieces, 'INSERT INTO gcs VALUES (');
516-
nqp::push_s($pieces, nqp::join(',', @g) ~ ");\n");
517-
if nqp::existskey($gc, 'deallocs') {
518-
my $deallocs := $gc<deallocs>;
519-
520-
for $deallocs -> $entry {
521-
@g := nqp::list_s($gc<sequence>, $thread_id);
522-
for <id nursery_fresh nursery_seen gen2> -> $f {
523-
nqp::push_s(@g, ~($entry{$f} // '0'));
524-
}
553+
nqp::push_s($pieces, nqp::join(',', @g) ~ ")");
525554

526-
nqp::push_s($pieces, 'INSERT INTO deallocations VALUES (');
527-
nqp::push_s($pieces, nqp::join(',', @g) ~ ");\n");
555+
if $any-deallocs == 0 && nqp::existskey($gc, 'deallocs') {
556+
$any-deallocs := 1
557+
}
558+
}
559+
if nqp::elems($v) > 0 {
560+
nqp::push_s($pieces, ";\n");
561+
}
562+
563+
if $any-deallocs {
564+
nqp::push_s($pieces, "INSERT INTO deallocations VALUES (");
565+
$is-first := 1;
566+
567+
for $v -> $gc {
568+
if nqp::existskey($gc, 'deallocs') {
569+
my @g;
570+
my $deallocs := $gc<deallocs>;
571+
572+
for $deallocs -> $entry {
573+
if !$is-first {
574+
nqp::push_s($pieces, ",\n(");
575+
}
576+
else { $is-first := 0 }
577+
@g := nqp::list_s($gc<sequence>, $thread_id);
578+
for <id nursery_fresh nursery_seen gen2> -> $f {
579+
nqp::push_s(@g, ~($entry{$f} // '0'));
580+
}
581+
582+
nqp::push_s($pieces, nqp::join(',', @g) ~ ')');
583+
}
528584
}
529585
}
586+
nqp::push_s($pieces, ";\n");
530587
}
531588
}
532589
elsif $k eq 'parent' {
533590
$thisprof[3] := ~$v;
534591
}
535592
elsif $k eq 'call_graph' {
593+
my $is_first := 1;
594+
536595
my %call_rec_depth;
537596
$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+
538603
sub collect_calls(str $parent_id, %call_graph) {
539604
my str $call_id := ~$node_id;
540605
$node_id++;
541606
my @call := nqp::list_s($call_id, $parent_id);
542607
for <id osr spesh_entries jit_entries inlined_entries inclusive_time exclusive_time entries deopt_one deopt_all> -> $f {
543608
nqp::push_s(@call, ~(%call_graph{$f} // '0'));
544609
}
610+
if $is_first {
611+
$is_first := 0;
612+
}
613+
else {
614+
nqp::push_s($pieces, "),\n");
615+
}
545616
my str $routine_id := ~%call_graph<id>;
546617
%call_rec_depth{$routine_id} := 0 unless %call_rec_depth{$routine_id};
547618
nqp::push_s(@call, ~%call_rec_depth{$routine_id});
548619
nqp::push_s(@call, ~%call_graph<first_entry_time>);
549620
nqp::push_s(@call, ~%call_graph<highest_child_id>);
550-
nqp::push_s($pieces, 'INSERT INTO calls VALUES (');
551-
nqp::push_s($pieces, nqp::join(',', @call) ~ ");\n");
621+
nqp::push_s($pieces, "(" ~ nqp::join(',', @call));
552622
if %call_graph<allocations> {
553623
for %call_graph<allocations> -> $a {
554624
my @a := nqp::list_s($call_id);
555625
for <id spesh jit count replaced> -> $f {
556626
nqp::push_s(@a, ~($a{$f} // '0'));
557627
}
558-
nqp::push_s($pieces, 'INSERT INTO allocations VALUES (');
559-
nqp::push_s($pieces, nqp::join(',', @a) ~ ");\n");
628+
if nqp::elems($allocation_pieces) > 1 {
629+
nqp::push_s($allocation_pieces, ",\n(");
630+
}
631+
nqp::push_s($allocation_pieces, nqp::join(',', @a) ~ ")");
560632
}
561633
}
562634
if %call_graph<callees> {
@@ -567,21 +639,25 @@ class HLL::Backend::MoarVM {
567639
%call_rec_depth{$routine_id}--;
568640
}
569641
if nqp::elems($pieces) > 500 {
570-
$profile_fh.say(nqp::join("", $pieces));
642+
$profile_fh.print(nqp::join("", $pieces));
571643
nqp::splice($pieces, $empty-array, 0, nqp::elems($pieces));
572644
}
573645
}
574646
collect_calls(~$node_id, $v);
647+
nqp::push_s($pieces, ");\n");
648+
if nqp::elems($allocation_pieces) > 1 {
649+
nqp::push_s($pieces, nqp::join('', $allocation_pieces) ~ ";\n");
650+
}
575651
}
576652
}
577653
nqp::push_s($pieces, 'INSERT INTO profile VALUES (');
578654
nqp::push_s($pieces, nqp::join(',', $thisprof) ~ ");\n");
579655
if nqp::elems($pieces) > 500 {
580-
$profile_fh.say(nqp::join("", $pieces));
656+
$profile_fh.print(nqp::join("", $pieces));
581657
nqp::splice($pieces, $empty-array, 0, nqp::elems($pieces));
582658
}
583659
}
584-
$profile_fh.say(nqp::join("", $pieces));
660+
$profile_fh.print(nqp::join("", $pieces));
585661
nqp::splice($pieces, $empty-array, 0, nqp::elems($pieces));
586662
}
587663

0 commit comments

Comments
 (0)