Skip to content

GSym aggregated output to JSON file #81763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/tools/llvm-gsymutil/Opts.td
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ defm address : Eq<"address", "Lookup an address in a GSYM file">;
def addresses_from_stdin :
FF<"addresses-from-stdin",
"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>">;
defm json_summary_file :
Eq<"json-summary-file",
"Output a categorized summary of errors into the JSON file specified.">;
29 changes: 29 additions & 0 deletions llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
Expand Down Expand Up @@ -87,6 +88,7 @@ static std::vector<std::string> InputFilenames;
static std::string ConvertFilename;
static std::vector<std::string> ArchFilters;
static std::string OutputFilename;
static std::string JsonSummaryFile;
static bool Verify;
static unsigned NumThreads;
static uint64_t SegmentSize;
Expand Down Expand Up @@ -138,6 +140,9 @@ static void parseArgs(int argc, char **argv) {
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_out_file_EQ))
OutputFilename = A->getValue();

if (const llvm::opt::Arg *A = Args.getLastArg(OPT_json_summary_file_EQ))
JsonSummaryFile = A->getValue();

Verify = Args.hasArg(OPT_verify);

if (const llvm::opt::Arg *A = Args.getLastArg(OPT_num_threads_EQ)) {
Expand Down Expand Up @@ -515,10 +520,34 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
// Call error() if we have an error and it will exit with a status of 1
if (auto Err = convertFileToGSYM(Aggregation))
error("DWARF conversion failed: ", std::move(Err));

// Report the errors from aggregator:
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
OS << category << " occurred " << count << " time(s)\n";
});
if (!JsonSummaryFile.empty()) {
std::error_code EC;
raw_fd_ostream JsonStream(JsonSummaryFile, EC, sys::fs::OF_Text);
if (EC) {
OS << "error opening aggregate error json file '" << JsonSummaryFile
<< "' for writing: " << EC.message() << '\n';
return 1;
}

llvm::json::Object Categories;
uint64_t ErrorCount = 0;
Aggregation.EnumerateResults([&](StringRef Category, unsigned Count) {
llvm::json::Object Val;
Val.try_emplace("count", Count);
Categories.try_emplace(Category, std::move(Val));
ErrorCount += Count;
});
llvm::json::Object RootNode;
RootNode.try_emplace("error-categories", std::move(Categories));
RootNode.try_emplace("error-count", ErrorCount);

JsonStream << llvm::json::Value(std::move(RootNode));
}
return 0;
}

Expand Down