forked from OSchip/llvm-project
[llvm-dwarfdump] --statistics: switch to json::OStream. NFC
Then it is trivial to make the output indented (the second parameter of json::OStream::OStream specifies the indentation). Reviewed By: jhenderson, echristo Differential Revision: https://reviews.llvm.org/D86045
This commit is contained in:
parent
58c08c4446
commit
ddde8bebb0
|
@ -469,46 +469,52 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
|
|||
/// Print machine-readable output.
|
||||
/// The machine-readable format is single-line JSON output.
|
||||
/// \{
|
||||
static void printDatum(raw_ostream &OS, const char *Key, json::Value Value) {
|
||||
OS << ",\"" << Key << "\":" << Value;
|
||||
static void printDatum(json::OStream &J, const char *Key, json::Value Value) {
|
||||
J.attribute(Key, Value);
|
||||
LLVM_DEBUG(llvm::dbgs() << Key << ": " << Value << '\n');
|
||||
}
|
||||
|
||||
static void printLocationStats(raw_ostream &OS, const char *Key,
|
||||
static void printLocationStats(json::OStream &J, const char *Key,
|
||||
std::vector<unsigned> &LocationStats) {
|
||||
OS << ",\"" << Key << " with 0% of parent scope covered by DW_AT_location\":"
|
||||
<< LocationStats[0];
|
||||
J.attribute(
|
||||
(Twine(Key) + " with 0% of parent scope covered by DW_AT_location").str(),
|
||||
LocationStats[0]);
|
||||
LLVM_DEBUG(
|
||||
llvm::dbgs() << Key
|
||||
<< " with 0% of parent scope covered by DW_AT_location: \\"
|
||||
<< LocationStats[0] << '\n');
|
||||
OS << ",\"" << Key
|
||||
<< " with (0%,10%) of parent scope covered by DW_AT_location\":"
|
||||
<< LocationStats[1];
|
||||
J.attribute(
|
||||
(Twine(Key) + " with (0%,10%) of parent scope covered by DW_AT_location")
|
||||
.str(),
|
||||
LocationStats[1]);
|
||||
LLVM_DEBUG(llvm::dbgs()
|
||||
<< Key
|
||||
<< " with (0%,10%) of parent scope covered by DW_AT_location: "
|
||||
<< LocationStats[1] << '\n');
|
||||
for (unsigned i = 2; i < NumOfCoverageCategories - 1; ++i) {
|
||||
OS << ",\"" << Key << " with [" << (i - 1) * 10 << "%," << i * 10
|
||||
<< "%) of parent scope covered by DW_AT_location\":" << LocationStats[i];
|
||||
J.attribute((Twine(Key) + " with [" + Twine((i - 1) * 10) + "%," +
|
||||
Twine(i * 10) + "%) of parent scope covered by DW_AT_location")
|
||||
.str(),
|
||||
LocationStats[i]);
|
||||
LLVM_DEBUG(llvm::dbgs()
|
||||
<< Key << " with [" << (i - 1) * 10 << "%," << i * 10
|
||||
<< "%) of parent scope covered by DW_AT_location: "
|
||||
<< LocationStats[i]);
|
||||
}
|
||||
OS << ",\"" << Key
|
||||
<< " with 100% of parent scope covered by DW_AT_location\":"
|
||||
<< LocationStats[NumOfCoverageCategories - 1];
|
||||
J.attribute(
|
||||
(Twine(Key) + " with 100% of parent scope covered by DW_AT_location")
|
||||
.str(),
|
||||
LocationStats[NumOfCoverageCategories - 1]);
|
||||
LLVM_DEBUG(
|
||||
llvm::dbgs() << Key
|
||||
<< " with 100% of parent scope covered by DW_AT_location: "
|
||||
<< LocationStats[NumOfCoverageCategories - 1]);
|
||||
}
|
||||
|
||||
static void printSectionSizes(raw_ostream &OS, const SectionSizes &Sizes) {
|
||||
static void printSectionSizes(json::OStream &J, const SectionSizes &Sizes) {
|
||||
for (const auto &DebugSec : Sizes.DebugSectionSizes)
|
||||
OS << ",\"#bytes in " << DebugSec.getKey() << "\":" << DebugSec.getValue();
|
||||
J.attribute((Twine("#bytes in ") + DebugSec.getKey()).str(),
|
||||
int64_t(DebugSec.getValue()));
|
||||
}
|
||||
|
||||
/// \}
|
||||
|
@ -587,101 +593,102 @@ bool dwarfdump::collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
|
|||
|
||||
// Print summary.
|
||||
OS.SetBufferSize(1024);
|
||||
OS << "{\"version\":" << Version;
|
||||
json::OStream J(OS);
|
||||
J.objectBegin();
|
||||
J.attribute("version", Version);
|
||||
LLVM_DEBUG(llvm::dbgs() << "Variable location quality metrics\n";
|
||||
llvm::dbgs() << "---------------------------------\n");
|
||||
|
||||
printDatum(OS, "file", Filename.str());
|
||||
printDatum(OS, "format", FormatName);
|
||||
printDatum(J, "file", Filename.str());
|
||||
printDatum(J, "format", FormatName);
|
||||
|
||||
printDatum(OS, "#functions", NumFunctions);
|
||||
printDatum(OS, "#functions with location", NumFuncsWithSrcLoc);
|
||||
printDatum(OS, "#inlined functions", NumInlinedFunctions);
|
||||
printDatum(OS, "#inlined functions with abstract origins",
|
||||
NumAbstractOrigins);
|
||||
printDatum(J, "#functions", NumFunctions);
|
||||
printDatum(J, "#functions with location", NumFuncsWithSrcLoc);
|
||||
printDatum(J, "#inlined functions", NumInlinedFunctions);
|
||||
printDatum(J, "#inlined functions with abstract origins", NumAbstractOrigins);
|
||||
|
||||
// This includes local variables and formal parameters.
|
||||
printDatum(OS, "#unique source variables", VarParamUnique);
|
||||
printDatum(OS, "#source variables", VarParamTotal);
|
||||
printDatum(OS, "#source variables with location", VarParamWithLoc);
|
||||
printDatum(J, "#unique source variables", VarParamUnique);
|
||||
printDatum(J, "#source variables", VarParamTotal);
|
||||
printDatum(J, "#source variables with location", VarParamWithLoc);
|
||||
|
||||
printDatum(OS, "#call site entries", GlobalStats.CallSiteEntries);
|
||||
printDatum(OS, "#call site DIEs", GlobalStats.CallSiteDIEs);
|
||||
printDatum(OS, "#call site parameter DIEs", GlobalStats.CallSiteParamDIEs);
|
||||
printDatum(J, "#call site entries", GlobalStats.CallSiteEntries);
|
||||
printDatum(J, "#call site DIEs", GlobalStats.CallSiteDIEs);
|
||||
printDatum(J, "#call site parameter DIEs", GlobalStats.CallSiteParamDIEs);
|
||||
|
||||
printDatum(OS, "sum_all_variables(#bytes in parent scope)",
|
||||
printDatum(J, "sum_all_variables(#bytes in parent scope)",
|
||||
GlobalStats.ScopeBytes);
|
||||
printDatum(OS,
|
||||
printDatum(J,
|
||||
"sum_all_variables(#bytes in parent scope covered by "
|
||||
"DW_AT_location)",
|
||||
GlobalStats.ScopeBytesCovered);
|
||||
printDatum(OS,
|
||||
printDatum(J,
|
||||
"sum_all_variables(#bytes in parent scope covered by "
|
||||
"DW_OP_entry_value)",
|
||||
GlobalStats.ScopeEntryValueBytesCovered);
|
||||
|
||||
printDatum(OS, "sum_all_params(#bytes in parent scope)",
|
||||
printDatum(J, "sum_all_params(#bytes in parent scope)",
|
||||
GlobalStats.ParamScopeBytes);
|
||||
printDatum(
|
||||
OS,
|
||||
"sum_all_params(#bytes in parent scope covered by DW_AT_location)",
|
||||
GlobalStats.ParamScopeBytesCovered);
|
||||
printDatum(OS,
|
||||
printDatum(J,
|
||||
"sum_all_params(#bytes in parent scope covered by DW_AT_location)",
|
||||
GlobalStats.ParamScopeBytesCovered);
|
||||
printDatum(J,
|
||||
"sum_all_params(#bytes in parent scope covered by "
|
||||
"DW_OP_entry_value)",
|
||||
GlobalStats.ParamScopeEntryValueBytesCovered);
|
||||
|
||||
printDatum(OS, "sum_all_local_vars(#bytes in parent scope)",
|
||||
printDatum(J, "sum_all_local_vars(#bytes in parent scope)",
|
||||
GlobalStats.LocalVarScopeBytes);
|
||||
printDatum(OS,
|
||||
printDatum(J,
|
||||
"sum_all_local_vars(#bytes in parent scope covered by "
|
||||
"DW_AT_location)",
|
||||
GlobalStats.LocalVarScopeBytesCovered);
|
||||
printDatum(OS,
|
||||
printDatum(J,
|
||||
"sum_all_local_vars(#bytes in parent scope covered by "
|
||||
"DW_OP_entry_value)",
|
||||
GlobalStats.LocalVarScopeEntryValueBytesCovered);
|
||||
|
||||
printDatum(OS, "#bytes witin functions", GlobalStats.FunctionSize);
|
||||
printDatum(OS, "#bytes witin inlined functions",
|
||||
printDatum(J, "#bytes witin functions", GlobalStats.FunctionSize);
|
||||
printDatum(J, "#bytes witin inlined functions",
|
||||
GlobalStats.InlineFunctionSize);
|
||||
|
||||
// Print the summary for formal parameters.
|
||||
printDatum(OS, "#params", ParamTotal);
|
||||
printDatum(OS, "#params with source location", ParamWithSrcLoc);
|
||||
printDatum(OS, "#params with type", ParamWithType);
|
||||
printDatum(OS, "#params with binary location", ParamWithLoc);
|
||||
printDatum(J, "#params", ParamTotal);
|
||||
printDatum(J, "#params with source location", ParamWithSrcLoc);
|
||||
printDatum(J, "#params with type", ParamWithType);
|
||||
printDatum(J, "#params with binary location", ParamWithLoc);
|
||||
|
||||
// Print the summary for local variables.
|
||||
printDatum(OS, "#local vars", LocalVarTotal);
|
||||
printDatum(OS, "#local vars with source location", LocalVarWithSrcLoc);
|
||||
printDatum(OS, "#local vars with type", LocalVarWithType);
|
||||
printDatum(OS, "#local vars with binary location", LocalVarWithLoc);
|
||||
printDatum(J, "#local vars", LocalVarTotal);
|
||||
printDatum(J, "#local vars with source location", LocalVarWithSrcLoc);
|
||||
printDatum(J, "#local vars with type", LocalVarWithType);
|
||||
printDatum(J, "#local vars with binary location", LocalVarWithLoc);
|
||||
|
||||
// Print the debug section sizes.
|
||||
printSectionSizes(OS, Sizes);
|
||||
printSectionSizes(J, Sizes);
|
||||
|
||||
// Print the location statistics for variables (includes local variables
|
||||
// and formal parameters).
|
||||
printDatum(OS, "#variables processed by location statistics",
|
||||
printDatum(J, "#variables processed by location statistics",
|
||||
LocStats.NumVarParam);
|
||||
printLocationStats(OS, "#variables", LocStats.VarParamLocStats);
|
||||
printLocationStats(OS, "#variables - entry values",
|
||||
printLocationStats(J, "#variables", LocStats.VarParamLocStats);
|
||||
printLocationStats(J, "#variables - entry values",
|
||||
LocStats.VarParamNonEntryValLocStats);
|
||||
|
||||
// Print the location statistics for formal parameters.
|
||||
printDatum(OS, "#params processed by location statistics", LocStats.NumParam);
|
||||
printLocationStats(OS, "#params", LocStats.ParamLocStats);
|
||||
printLocationStats(OS, "#params - entry values",
|
||||
printDatum(J, "#params processed by location statistics", LocStats.NumParam);
|
||||
printLocationStats(J, "#params", LocStats.ParamLocStats);
|
||||
printLocationStats(J, "#params - entry values",
|
||||
LocStats.ParamNonEntryValLocStats);
|
||||
|
||||
// Print the location statistics for local variables.
|
||||
printDatum(OS, "#local vars processed by location statistics",
|
||||
printDatum(J, "#local vars processed by location statistics",
|
||||
LocStats.NumVar);
|
||||
printLocationStats(OS, "#local vars", LocStats.LocalVarLocStats);
|
||||
printLocationStats(OS, "#local vars - entry values",
|
||||
printLocationStats(J, "#local vars", LocStats.LocalVarLocStats);
|
||||
printLocationStats(J, "#local vars - entry values",
|
||||
LocStats.LocalVarNonEntryValLocStats);
|
||||
OS << "}\n";
|
||||
J.objectEnd();
|
||||
OS << '\n';
|
||||
LLVM_DEBUG(
|
||||
llvm::dbgs() << "Total Availability: "
|
||||
<< (int)std::round((VarParamWithLoc * 100.0) / VarParamTotal)
|
||||
|
|
Loading…
Reference in New Issue