|
19 | 19 | #include "llvm/Support/CommandLine.h"
|
20 | 20 | #include "llvm/Support/Debug.h"
|
21 | 21 | #include "llvm/Support/Format.h"
|
| 22 | +#include "llvm/Support/JSON.h" |
22 | 23 | #include "llvm/Support/LLVMDriver.h"
|
23 | 24 | #include "llvm/Support/ManagedStatic.h"
|
24 | 25 | #include "llvm/Support/MemoryBuffer.h"
|
@@ -88,7 +89,7 @@ static std::vector<std::string> InputFilenames;
|
88 | 89 | static std::string ConvertFilename;
|
89 | 90 | static std::vector<std::string> ArchFilters;
|
90 | 91 | static std::string OutputFilename;
|
91 |
| -static std::string AggregateJsonFile; |
| 92 | +static std::string JsonSummaryFile; |
92 | 93 | static bool Verify;
|
93 | 94 | static unsigned NumThreads;
|
94 | 95 | static uint64_t SegmentSize;
|
@@ -140,8 +141,8 @@ static void parseArgs(int argc, char **argv) {
|
140 | 141 | if (const llvm::opt::Arg *A = Args.getLastArg(OPT_out_file_EQ))
|
141 | 142 | OutputFilename = A->getValue();
|
142 | 143 |
|
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(); |
145 | 146 |
|
146 | 147 | Verify = Args.hasArg(OPT_verify);
|
147 | 148 |
|
@@ -525,25 +526,25 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
|
525 | 526 | Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
|
526 | 527 | OS << category << " occurred " << count << " time(s)\n";
|
527 | 528 | });
|
528 |
| - if (!AggregateJsonFile.empty()) { |
| 529 | + if (!JsonSummaryFile.empty()) { |
529 | 530 | 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); |
531 | 532 | if (EC) {
|
532 |
| - OS << "error opening aggregate error json file '" << AggregateJsonFile |
| 533 | + OS << "error opening aggregate error json file '" << JsonSummaryFile |
533 | 534 | << "' for writing: " << EC.message() << '\n';
|
534 | 535 | return 1;
|
535 | 536 | }
|
536 |
| - JsonStream << "{\"errors\":[\n"; |
537 |
| - bool prev = false; |
| 537 | + |
| 538 | + llvm::json::Object Categories; |
538 | 539 | 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)); |
545 | 543 | });
|
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)); |
547 | 548 | }
|
548 | 549 | return 0;
|
549 | 550 | }
|
|
0 commit comments