Skip to content

Commit 91b1af6

Browse files
Kevin Freikevinfrei
authored andcommitted
GSym aggregated output to JSON file
1 parent 1d03d59 commit 91b1af6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-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 aggregate_error_file :
39+
Eq<"aggregate-error-file",
40+
"Output any aggregated errors into the file specified in JSON format.">;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/ADT/STLExtras.h"
10+
#include "llvm/ADT/StringExtras.h"
1011
#include "llvm/DebugInfo/DIContext.h"
1112
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1213
#include "llvm/Object/Archive.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 AggregateJsonFile;
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_aggregate_error_file_EQ))
144+
AggregateJsonFile = 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,28 @@ 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 (!AggregateJsonFile.empty()) {
529+
std::error_code EC;
530+
raw_fd_ostream JsonStream(AggregateJsonFile, EC,
531+
sys::fs::OF_Text | sys::fs::OF_None);
532+
if (EC) {
533+
OS << "error opening aggregate error json file '" << AggregateJsonFile
534+
<< "' for writing: " << EC.message() << '\n';
535+
return 1;
536+
}
537+
JsonStream << "{\"errors\":[\n";
538+
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
539+
JsonStream << "\"category\":\"";
540+
llvm::printEscapedString(category, JsonStream);
541+
JsonStream << "\",\"count\":" << count;
542+
});
543+
JsonStream << "]}\n";
544+
}
522545
return 0;
523546
}
524547

0 commit comments

Comments
 (0)