@@ -456,22 +456,46 @@ class HLL::Backend::MoarVM {
456
456
my $ mapping := nqp :: shift ($ obj );
457
457
my $ pieces := nqp ::list_s();
458
458
my $ empty-array := nqp ::list_s();
459
+
460
+ nqp ::push_s($ pieces , " INSERT INTO routines VALUES ('" );
461
+
462
+ my $ is-first := 1 ;
463
+
459
464
for $ mapping -> $ k {
460
465
my $ v := $ mapping {$ k };
461
466
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 }
463
471
nqp ::push_s($ pieces ,
464
472
nqp :: join (" ','" ,
465
473
nqp ::list(
466
474
nqp ::iterkey_s($ k ),
467
475
literal_subst(~ $ v <name >, " '" , " ''" ),
468
476
~ $ v <line >,
469
477
~ $ v <file >))
470
- ~ " '); \n " );
478
+ ~ " ')" );
471
479
}
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 }
473
498
my $ type-info := % type-info {nqp ::iterkey_s($ k )};
474
- nqp ::push_s($ pieces , " INSERT INTO types VALUES ('" );
475
499
nqp ::push_s($ pieces ,
476
500
nqp :: join (" ','" ,
477
501
nqp ::list_s(
@@ -482,13 +506,15 @@ class HLL::Backend::MoarVM {
482
506
~ to_sql_json($ type-info [1 ])
483
507
~ " ,"
484
508
~ " json_object()"
485
- ~ " ); \n " );
509
+ ~ " )" );
486
510
}
487
511
if nqp :: elems ($ pieces ) > 500 {
488
- $ profile_fh . say (nqp :: join (" " , $ pieces ));
512
+ $ profile_fh . print (nqp :: join (" " , $ pieces ));
489
513
nqp :: splice ($ pieces , $ empty-array , 0 , nqp :: elems ($ pieces ));
490
514
}
491
515
}
516
+ nqp ::push_s($ pieces , " ;\n " );
517
+
492
518
for $ obj -> $ thread {
493
519
my $ thisprof := nqp ::list;
494
520
$ thisprof [4 ] := " NULL" ;
@@ -506,57 +532,103 @@ class HLL::Backend::MoarVM {
506
532
}
507
533
elsif $ k eq ' gcs' {
508
534
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
+
509
543
for $ v -> $ gc {
544
+ if ! $ is-first {
545
+ nqp ::push_s($ pieces , " ,\n (" );
546
+ }
547
+ else { $ is-first := 0 }
510
548
my @ g := nqp ::list_s();
511
549
for <time retained_bytes promoted_bytes gen2_roots full responsible cleared_bytes start_time sequence > -> $ f {
512
550
nqp ::push_s(@ g , ~ ($ gc {$ f } // ' 0' ));
513
551
}
514
552
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 ) ~ " )" );
525
554
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
+ }
528
584
}
529
585
}
586
+ nqp ::push_s($ pieces , " ;\n " );
530
587
}
531
588
}
532
589
elsif $ k eq ' parent' {
533
590
$ thisprof [3 ] := ~ $ v ;
534
591
}
535
592
elsif $ k eq ' call_graph' {
593
+ my $ is_first := 1 ;
594
+
536
595
my % call_rec_depth ;
537
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
+
538
603
sub collect_calls (str $ parent_id , % call_graph ) {
539
604
my str $ call_id := ~ $ node_id ;
540
605
$ node_id ++ ;
541
606
my @ call := nqp ::list_s($ call_id , $ parent_id );
542
607
for <id osr spesh_entries jit_entries inlined_entries inclusive_time exclusive_time entries deopt_one deopt_all > -> $ f {
543
608
nqp ::push_s(@ call , ~ (% call_graph {$ f } // ' 0' ));
544
609
}
610
+ if $ is_first {
611
+ $ is_first := 0 ;
612
+ }
613
+ else {
614
+ nqp ::push_s($ pieces , " ),\n " );
615
+ }
545
616
my str $ routine_id := ~ % call_graph <id >;
546
617
% call_rec_depth {$ routine_id } := 0 unless % call_rec_depth {$ routine_id };
547
618
nqp ::push_s(@ call , ~ % call_rec_depth {$ routine_id });
548
619
nqp ::push_s(@ call , ~ % call_graph <first_entry_time >);
549
620
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 ));
552
622
if % call_graph <allocations > {
553
623
for % call_graph <allocations > -> $ a {
554
624
my @ a := nqp ::list_s($ call_id );
555
625
for <id spesh jit count replaced > -> $ f {
556
626
nqp ::push_s(@ a , ~ ($ a {$ f } // ' 0' ));
557
627
}
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 ) ~ " )" );
560
632
}
561
633
}
562
634
if % call_graph <callees > {
@@ -567,21 +639,25 @@ class HLL::Backend::MoarVM {
567
639
% call_rec_depth {$ routine_id }-- ;
568
640
}
569
641
if nqp :: elems ($ pieces ) > 500 {
570
- $ profile_fh . say (nqp :: join (" " , $ pieces ));
642
+ $ profile_fh . print (nqp :: join (" " , $ pieces ));
571
643
nqp :: splice ($ pieces , $ empty-array , 0 , nqp :: elems ($ pieces ));
572
644
}
573
645
}
574
646
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
+ }
575
651
}
576
652
}
577
653
nqp ::push_s($ pieces , ' INSERT INTO profile VALUES (' );
578
654
nqp ::push_s($ pieces , nqp :: join (' ,' , $ thisprof ) ~ " );\n " );
579
655
if nqp :: elems ($ pieces ) > 500 {
580
- $ profile_fh . say (nqp :: join (" " , $ pieces ));
656
+ $ profile_fh . print (nqp :: join (" " , $ pieces ));
581
657
nqp :: splice ($ pieces , $ empty-array , 0 , nqp :: elems ($ pieces ));
582
658
}
583
659
}
584
- $ profile_fh . say (nqp :: join (" " , $ pieces ));
660
+ $ profile_fh . print (nqp :: join (" " , $ pieces ));
585
661
nqp :: splice ($ pieces , $ empty-array , 0 , nqp :: elems ($ pieces ));
586
662
}
587
663
0 commit comments