@@ -469,46 +469,52 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
469
469
// / Print machine-readable output.
470
470
// / The machine-readable format is single-line JSON output.
471
471
// / \{
472
- static void printDatum (raw_ostream &OS , const char *Key, json::Value Value) {
473
- OS << " , \" " << Key << " \" : " << Value;
472
+ static void printDatum (json::OStream &J , const char *Key, json::Value Value) {
473
+ J. attribute (Key, Value) ;
474
474
LLVM_DEBUG (llvm::dbgs () << Key << " : " << Value << ' \n ' );
475
475
}
476
476
477
- static void printLocationStats (raw_ostream &OS , const char *Key,
477
+ static void printLocationStats (json::OStream &J , const char *Key,
478
478
std::vector<unsigned > &LocationStats) {
479
- OS << " ,\" " << Key << " with 0% of parent scope covered by DW_AT_location\" :"
480
- << LocationStats[0 ];
479
+ J.attribute (
480
+ (Twine (Key) + " with 0% of parent scope covered by DW_AT_location" ).str (),
481
+ LocationStats[0 ]);
481
482
LLVM_DEBUG (
482
483
llvm::dbgs () << Key
483
484
<< " with 0% of parent scope covered by DW_AT_location: \\ "
484
485
<< LocationStats[0 ] << ' \n ' );
485
- OS << " ,\" " << Key
486
- << " with (0%,10%) of parent scope covered by DW_AT_location\" :"
487
- << LocationStats[1 ];
486
+ J.attribute (
487
+ (Twine (Key) + " with (0%,10%) of parent scope covered by DW_AT_location" )
488
+ .str (),
489
+ LocationStats[1 ]);
488
490
LLVM_DEBUG (llvm::dbgs ()
489
491
<< Key
490
492
<< " with (0%,10%) of parent scope covered by DW_AT_location: "
491
493
<< LocationStats[1 ] << ' \n ' );
492
494
for (unsigned i = 2 ; i < NumOfCoverageCategories - 1 ; ++i) {
493
- OS << " ,\" " << Key << " with [" << (i - 1 ) * 10 << " %," << i * 10
494
- << " %) of parent scope covered by DW_AT_location\" :" << LocationStats[i];
495
+ J.attribute ((Twine (Key) + " with [" + Twine ((i - 1 ) * 10 ) + " %," +
496
+ Twine (i * 10 ) + " %) of parent scope covered by DW_AT_location" )
497
+ .str (),
498
+ LocationStats[i]);
495
499
LLVM_DEBUG (llvm::dbgs ()
496
500
<< Key << " with [" << (i - 1 ) * 10 << " %," << i * 10
497
501
<< " %) of parent scope covered by DW_AT_location: "
498
502
<< LocationStats[i]);
499
503
}
500
- OS << " ,\" " << Key
501
- << " with 100% of parent scope covered by DW_AT_location\" :"
502
- << LocationStats[NumOfCoverageCategories - 1 ];
504
+ J.attribute (
505
+ (Twine (Key) + " with 100% of parent scope covered by DW_AT_location" )
506
+ .str (),
507
+ LocationStats[NumOfCoverageCategories - 1 ]);
503
508
LLVM_DEBUG (
504
509
llvm::dbgs () << Key
505
510
<< " with 100% of parent scope covered by DW_AT_location: "
506
511
<< LocationStats[NumOfCoverageCategories - 1 ]);
507
512
}
508
513
509
- static void printSectionSizes (raw_ostream &OS , const SectionSizes &Sizes) {
514
+ static void printSectionSizes (json::OStream &J , const SectionSizes &Sizes) {
510
515
for (const auto &DebugSec : Sizes.DebugSectionSizes )
511
- OS << " ,\" #bytes in " << DebugSec.getKey () << " \" :" << DebugSec.getValue ();
516
+ J.attribute ((Twine (" #bytes in " ) + DebugSec.getKey ()).str (),
517
+ int64_t (DebugSec.getValue ()));
512
518
}
513
519
514
520
// / \}
@@ -587,101 +593,102 @@ bool dwarfdump::collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
587
593
588
594
// Print summary.
589
595
OS.SetBufferSize (1024 );
590
- OS << " {\" version\" :" << Version;
596
+ json::OStream J (OS);
597
+ J.objectBegin ();
598
+ J.attribute (" version" , Version);
591
599
LLVM_DEBUG (llvm::dbgs () << " Variable location quality metrics\n " ;
592
600
llvm::dbgs () << " ---------------------------------\n " );
593
601
594
- printDatum (OS , " file" , Filename.str ());
595
- printDatum (OS , " format" , FormatName);
602
+ printDatum (J , " file" , Filename.str ());
603
+ printDatum (J , " format" , FormatName);
596
604
597
- printDatum (OS, " #functions" , NumFunctions);
598
- printDatum (OS, " #functions with location" , NumFuncsWithSrcLoc);
599
- printDatum (OS, " #inlined functions" , NumInlinedFunctions);
600
- printDatum (OS, " #inlined functions with abstract origins" ,
601
- NumAbstractOrigins);
605
+ printDatum (J, " #functions" , NumFunctions);
606
+ printDatum (J, " #functions with location" , NumFuncsWithSrcLoc);
607
+ printDatum (J, " #inlined functions" , NumInlinedFunctions);
608
+ printDatum (J, " #inlined functions with abstract origins" , NumAbstractOrigins);
602
609
603
610
// This includes local variables and formal parameters.
604
- printDatum (OS , " #unique source variables" , VarParamUnique);
605
- printDatum (OS , " #source variables" , VarParamTotal);
606
- printDatum (OS , " #source variables with location" , VarParamWithLoc);
611
+ printDatum (J , " #unique source variables" , VarParamUnique);
612
+ printDatum (J , " #source variables" , VarParamTotal);
613
+ printDatum (J , " #source variables with location" , VarParamWithLoc);
607
614
608
- printDatum (OS , " #call site entries" , GlobalStats.CallSiteEntries );
609
- printDatum (OS , " #call site DIEs" , GlobalStats.CallSiteDIEs );
610
- printDatum (OS , " #call site parameter DIEs" , GlobalStats.CallSiteParamDIEs );
615
+ printDatum (J , " #call site entries" , GlobalStats.CallSiteEntries );
616
+ printDatum (J , " #call site DIEs" , GlobalStats.CallSiteDIEs );
617
+ printDatum (J , " #call site parameter DIEs" , GlobalStats.CallSiteParamDIEs );
611
618
612
- printDatum (OS , " sum_all_variables(#bytes in parent scope)" ,
619
+ printDatum (J , " sum_all_variables(#bytes in parent scope)" ,
613
620
GlobalStats.ScopeBytes );
614
- printDatum (OS ,
621
+ printDatum (J ,
615
622
" sum_all_variables(#bytes in parent scope covered by "
616
623
" DW_AT_location)" ,
617
624
GlobalStats.ScopeBytesCovered );
618
- printDatum (OS ,
625
+ printDatum (J ,
619
626
" sum_all_variables(#bytes in parent scope covered by "
620
627
" DW_OP_entry_value)" ,
621
628
GlobalStats.ScopeEntryValueBytesCovered );
622
629
623
- printDatum (OS , " sum_all_params(#bytes in parent scope)" ,
630
+ printDatum (J , " sum_all_params(#bytes in parent scope)" ,
624
631
GlobalStats.ParamScopeBytes );
625
- printDatum (
626
- OS,
627
- " sum_all_params(#bytes in parent scope covered by DW_AT_location)" ,
628
- GlobalStats.ParamScopeBytesCovered );
629
- printDatum (OS,
632
+ printDatum (J,
633
+ " sum_all_params(#bytes in parent scope covered by DW_AT_location)" ,
634
+ GlobalStats.ParamScopeBytesCovered );
635
+ printDatum (J,
630
636
" sum_all_params(#bytes in parent scope covered by "
631
637
" DW_OP_entry_value)" ,
632
638
GlobalStats.ParamScopeEntryValueBytesCovered );
633
639
634
- printDatum (OS , " sum_all_local_vars(#bytes in parent scope)" ,
640
+ printDatum (J , " sum_all_local_vars(#bytes in parent scope)" ,
635
641
GlobalStats.LocalVarScopeBytes );
636
- printDatum (OS ,
642
+ printDatum (J ,
637
643
" sum_all_local_vars(#bytes in parent scope covered by "
638
644
" DW_AT_location)" ,
639
645
GlobalStats.LocalVarScopeBytesCovered );
640
- printDatum (OS ,
646
+ printDatum (J ,
641
647
" sum_all_local_vars(#bytes in parent scope covered by "
642
648
" DW_OP_entry_value)" ,
643
649
GlobalStats.LocalVarScopeEntryValueBytesCovered );
644
650
645
- printDatum (OS , " #bytes witin functions" , GlobalStats.FunctionSize );
646
- printDatum (OS , " #bytes witin inlined functions" ,
651
+ printDatum (J , " #bytes witin functions" , GlobalStats.FunctionSize );
652
+ printDatum (J , " #bytes witin inlined functions" ,
647
653
GlobalStats.InlineFunctionSize );
648
654
649
655
// Print the summary for formal parameters.
650
- printDatum (OS , " #params" , ParamTotal);
651
- printDatum (OS , " #params with source location" , ParamWithSrcLoc);
652
- printDatum (OS , " #params with type" , ParamWithType);
653
- printDatum (OS , " #params with binary location" , ParamWithLoc);
656
+ printDatum (J , " #params" , ParamTotal);
657
+ printDatum (J , " #params with source location" , ParamWithSrcLoc);
658
+ printDatum (J , " #params with type" , ParamWithType);
659
+ printDatum (J , " #params with binary location" , ParamWithLoc);
654
660
655
661
// Print the summary for local variables.
656
- printDatum (OS , " #local vars" , LocalVarTotal);
657
- printDatum (OS , " #local vars with source location" , LocalVarWithSrcLoc);
658
- printDatum (OS , " #local vars with type" , LocalVarWithType);
659
- printDatum (OS , " #local vars with binary location" , LocalVarWithLoc);
662
+ printDatum (J , " #local vars" , LocalVarTotal);
663
+ printDatum (J , " #local vars with source location" , LocalVarWithSrcLoc);
664
+ printDatum (J , " #local vars with type" , LocalVarWithType);
665
+ printDatum (J , " #local vars with binary location" , LocalVarWithLoc);
660
666
661
667
// Print the debug section sizes.
662
- printSectionSizes (OS , Sizes);
668
+ printSectionSizes (J , Sizes);
663
669
664
670
// Print the location statistics for variables (includes local variables
665
671
// and formal parameters).
666
- printDatum (OS , " #variables processed by location statistics" ,
672
+ printDatum (J , " #variables processed by location statistics" ,
667
673
LocStats.NumVarParam );
668
- printLocationStats (OS , " #variables" , LocStats.VarParamLocStats );
669
- printLocationStats (OS , " #variables - entry values" ,
674
+ printLocationStats (J , " #variables" , LocStats.VarParamLocStats );
675
+ printLocationStats (J , " #variables - entry values" ,
670
676
LocStats.VarParamNonEntryValLocStats );
671
677
672
678
// Print the location statistics for formal parameters.
673
- printDatum (OS , " #params processed by location statistics" , LocStats.NumParam );
674
- printLocationStats (OS , " #params" , LocStats.ParamLocStats );
675
- printLocationStats (OS , " #params - entry values" ,
679
+ printDatum (J , " #params processed by location statistics" , LocStats.NumParam );
680
+ printLocationStats (J , " #params" , LocStats.ParamLocStats );
681
+ printLocationStats (J , " #params - entry values" ,
676
682
LocStats.ParamNonEntryValLocStats );
677
683
678
684
// Print the location statistics for local variables.
679
- printDatum (OS , " #local vars processed by location statistics" ,
685
+ printDatum (J , " #local vars processed by location statistics" ,
680
686
LocStats.NumVar );
681
- printLocationStats (OS , " #local vars" , LocStats.LocalVarLocStats );
682
- printLocationStats (OS , " #local vars - entry values" ,
687
+ printLocationStats (J , " #local vars" , LocStats.LocalVarLocStats );
688
+ printLocationStats (J , " #local vars - entry values" ,
683
689
LocStats.LocalVarNonEntryValLocStats );
684
- OS << " }\n " ;
690
+ J.objectEnd ();
691
+ OS << ' \n ' ;
685
692
LLVM_DEBUG (
686
693
llvm::dbgs () << " Total Availability: "
687
694
<< (int )std::round ((VarParamWithLoc * 100.0 ) / VarParamTotal)
0 commit comments