|
18 | 18 | #include "llvm/Support/CommandLine.h"
|
19 | 19 | #include "llvm/Support/Debug.h"
|
20 | 20 | #include "llvm/Support/Format.h"
|
| 21 | +#include "llvm/Support/JSON.h" |
21 | 22 | #include "llvm/Support/LLVMDriver.h"
|
22 | 23 | #include "llvm/Support/ManagedStatic.h"
|
23 | 24 | #include "llvm/Support/MemoryBuffer.h"
|
@@ -87,6 +88,7 @@ static std::vector<std::string> InputFilenames;
|
87 | 88 | static std::string ConvertFilename;
|
88 | 89 | static std::vector<std::string> ArchFilters;
|
89 | 90 | static std::string OutputFilename;
|
| 91 | +static std::string JsonSummaryFile; |
90 | 92 | static bool Verify;
|
91 | 93 | static unsigned NumThreads;
|
92 | 94 | static uint64_t SegmentSize;
|
@@ -138,6 +140,9 @@ static void parseArgs(int argc, char **argv) {
|
138 | 140 | if (const llvm::opt::Arg *A = Args.getLastArg(OPT_out_file_EQ))
|
139 | 141 | OutputFilename = A->getValue();
|
140 | 142 |
|
| 143 | + if (const llvm::opt::Arg *A = Args.getLastArg(OPT_json_summary_file_EQ)) |
| 144 | + JsonSummaryFile = A->getValue(); |
| 145 | + |
141 | 146 | Verify = Args.hasArg(OPT_verify);
|
142 | 147 |
|
143 | 148 | 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 &) {
|
515 | 520 | // Call error() if we have an error and it will exit with a status of 1
|
516 | 521 | if (auto Err = convertFileToGSYM(Aggregation))
|
517 | 522 | error("DWARF conversion failed: ", std::move(Err));
|
| 523 | + |
518 | 524 | // Report the errors from aggregator:
|
519 | 525 | Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
|
520 | 526 | OS << category << " occurred " << count << " time(s)\n";
|
521 | 527 | });
|
| 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 | + } |
522 | 551 | return 0;
|
523 | 552 | }
|
524 | 553 |
|
|
0 commit comments