Skip to content

Commit 79eb9e4

Browse files
Kevin Freikevinfrei
authored andcommitted
Updated with Clayborg's feedback
1 parent 6f9cc12 commit 79eb9e4

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

llvm/tools/llvm-gsymutil/Opts.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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.">;
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: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Support/CommandLine.h"
2020
#include "llvm/Support/Debug.h"
2121
#include "llvm/Support/Format.h"
22+
#include "llvm/Support/JSON.h"
2223
#include "llvm/Support/LLVMDriver.h"
2324
#include "llvm/Support/ManagedStatic.h"
2425
#include "llvm/Support/MemoryBuffer.h"
@@ -88,7 +89,7 @@ static std::vector<std::string> InputFilenames;
8889
static std::string ConvertFilename;
8990
static std::vector<std::string> ArchFilters;
9091
static std::string OutputFilename;
91-
static std::string AggregateJsonFile;
92+
static std::string JsonSummaryFile;
9293
static bool Verify;
9394
static unsigned NumThreads;
9495
static uint64_t SegmentSize;
@@ -140,8 +141,8 @@ static void parseArgs(int argc, char **argv) {
140141
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_out_file_EQ))
141142
OutputFilename = A->getValue();
142143

143-
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_aggregate_error_file_EQ))
144-
AggregateJsonFile = A->getValue();
144+
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_json_summary_file_EQ))
145+
JsonSummaryFile = A->getValue();
145146

146147
Verify = Args.hasArg(OPT_verify);
147148

@@ -525,25 +526,25 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
525526
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
526527
OS << category << " occurred " << count << " time(s)\n";
527528
});
528-
if (!AggregateJsonFile.empty()) {
529+
if (!JsonSummaryFile.empty()) {
529530
std::error_code EC;
530-
raw_fd_ostream JsonStream(AggregateJsonFile, EC, sys::fs::OF_Text);
531+
raw_fd_ostream JsonStream(JsonSummaryFile, EC, sys::fs::OF_Text);
531532
if (EC) {
532-
OS << "error opening aggregate error json file '" << AggregateJsonFile
533+
OS << "error opening aggregate error json file '" << JsonSummaryFile
533534
<< "' for writing: " << EC.message() << '\n';
534535
return 1;
535536
}
536-
JsonStream << "{\"errors\":[\n";
537-
bool prev = false;
537+
538+
llvm::json::Object Categories;
538539
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
539-
if (prev)
540-
JsonStream << ",\n";
541-
JsonStream << "{\"category\":\"";
542-
llvm::printEscapedString(category, JsonStream);
543-
JsonStream << "\",\"count\":" << count << "}";
544-
prev = true;
540+
llvm::json::Object Val;
541+
Val.try_emplace("count", count);
542+
Categories.try_emplace(category, std::move(Val));
545543
});
546-
JsonStream << "\n]}\n";
544+
llvm::json::Object RootNode;
545+
RootNode.try_emplace("error-categories", std::move(Categories));
546+
547+
JsonStream << llvm::json::Value(std::move(RootNode));
547548
}
548549
return 0;
549550
}

0 commit comments

Comments
 (0)