Skip to content

Commit da1880c

Browse files
kevinfreiKevin Frei
and
Kevin Frei
authored
GSym aggregated output to JSON file (#81763)
In order to make tooling around dwarf health easier, I've added an `--json-summary-file` option to `llvm-gsymutil` that will spit out error summary data with counts to a JSON file. I've added the same capability to `llvm-dwarfdump` in a [different PR.](#81762) The format of the json is: ```JSON { "error-categories": { "<first category description>": {"count": 1234}, "<next category description>": {"count":4321} }, "error-count": 5555 } ``` for a clean run: ```JSON { "error-categories": {}, "error-count": 0 } ``` --------- Co-authored-by: Kevin Frei <[email protected]>
1 parent a23d4ce commit da1880c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/tools/llvm-gsymutil/Opts.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ defm address : Eq<"address", "Lookup an address in a GSYM file">;
3535
def addresses_from_stdin :
3636
FF<"addresses-from-stdin",
3737
"Lookup addresses in a GSYM file that are read from stdin\nEach input line is expected to be of the following format: <addr> <gsym-path>">;
38+
defm json_summary_file :
39+
Eq<"json-summary-file",
40+
"Output a categorized summary of errors into the JSON file specified.">;

llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/CommandLine.h"
1919
#include "llvm/Support/Debug.h"
2020
#include "llvm/Support/Format.h"
21+
#include "llvm/Support/JSON.h"
2122
#include "llvm/Support/LLVMDriver.h"
2223
#include "llvm/Support/ManagedStatic.h"
2324
#include "llvm/Support/MemoryBuffer.h"
@@ -87,6 +88,7 @@ static std::vector<std::string> InputFilenames;
8788
static std::string ConvertFilename;
8889
static std::vector<std::string> ArchFilters;
8990
static std::string OutputFilename;
91+
static std::string JsonSummaryFile;
9092
static bool Verify;
9193
static unsigned NumThreads;
9294
static uint64_t SegmentSize;
@@ -138,6 +140,9 @@ static void parseArgs(int argc, char **argv) {
138140
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_out_file_EQ))
139141
OutputFilename = A->getValue();
140142

143+
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_json_summary_file_EQ))
144+
JsonSummaryFile = A->getValue();
145+
141146
Verify = Args.hasArg(OPT_verify);
142147

143148
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_num_threads_EQ)) {
@@ -515,10 +520,34 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
515520
// Call error() if we have an error and it will exit with a status of 1
516521
if (auto Err = convertFileToGSYM(Aggregation))
517522
error("DWARF conversion failed: ", std::move(Err));
523+
518524
// Report the errors from aggregator:
519525
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
520526
OS << category << " occurred " << count << " time(s)\n";
521527
});
528+
if (!JsonSummaryFile.empty()) {
529+
std::error_code EC;
530+
raw_fd_ostream JsonStream(JsonSummaryFile, EC, sys::fs::OF_Text);
531+
if (EC) {
532+
OS << "error opening aggregate error json file '" << JsonSummaryFile
533+
<< "' for writing: " << EC.message() << '\n';
534+
return 1;
535+
}
536+
537+
llvm::json::Object Categories;
538+
uint64_t ErrorCount = 0;
539+
Aggregation.EnumerateResults([&](StringRef Category, unsigned Count) {
540+
llvm::json::Object Val;
541+
Val.try_emplace("count", Count);
542+
Categories.try_emplace(Category, std::move(Val));
543+
ErrorCount += Count;
544+
});
545+
llvm::json::Object RootNode;
546+
RootNode.try_emplace("error-categories", std::move(Categories));
547+
RootNode.try_emplace("error-count", ErrorCount);
548+
549+
JsonStream << llvm::json::Value(std::move(RootNode));
550+
}
522551
return 0;
523552
}
524553

0 commit comments

Comments
 (0)