[llvm] GSym aggregated output to JSON file (PR #81763)
Kevin Frei via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 10:58:41 PST 2024
https://github.com/kevinfrei updated https://github.com/llvm/llvm-project/pull/81763
>From c9cced726fb2fc94ecdf1809fc2b73ebc022042e Mon Sep 17 00:00:00 2001
From: Kevin Frei <freik at meta.com>
Date: Wed, 14 Feb 2024 09:03:47 -0800
Subject: [PATCH 1/2] GSym aggregated output to JSON file
---
llvm/tools/llvm-gsymutil/Opts.td | 3 +++
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | 23 ++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/llvm/tools/llvm-gsymutil/Opts.td b/llvm/tools/llvm-gsymutil/Opts.td
index 740291479f9323..00e81a9f85aa70 100644
--- a/llvm/tools/llvm-gsymutil/Opts.td
+++ b/llvm/tools/llvm-gsymutil/Opts.td
@@ -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 aggregate_error_file :
+ Eq<"aggregate-error-file",
+ "Output any aggregated errors into the file specified in JSON format.">;
diff --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index 2de9c76fd68c0c..1068ac4e39b266 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/Object/Archive.h"
@@ -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 AggregateJsonFile;
static bool Verify;
static unsigned NumThreads;
static uint64_t SegmentSize;
@@ -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_aggregate_error_file_EQ))
+ AggregateJsonFile = A->getValue();
+
Verify = Args.hasArg(OPT_verify);
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 &) {
// 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 (!AggregateJsonFile.empty()) {
+ std::error_code EC;
+ raw_fd_ostream JsonStream(AggregateJsonFile, EC,
+ sys::fs::OF_Text | sys::fs::OF_None);
+ if (EC) {
+ OS << "error opening aggregate error json file '" << AggregateJsonFile
+ << "' for writing: " << EC.message() << '\n';
+ return 1;
+ }
+ JsonStream << "{\"errors\":[\n";
+ Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
+ JsonStream << "\"category\":\"";
+ llvm::printEscapedString(category, JsonStream);
+ JsonStream << "\",\"count\":" << count;
+ });
+ JsonStream << "]}\n";
+ }
return 0;
}
>From b1f32fe64fc950fadadd88a4ebe9ce238eb8585b Mon Sep 17 00:00:00 2001
From: Kevin Frei <freik at meta.com>
Date: Wed, 14 Feb 2024 09:52:34 -0800
Subject: [PATCH 2/2] Fixed JSON output to be...JSON.
---
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index 1068ac4e39b266..608c75e7e2fef0 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -527,20 +527,23 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
});
if (!AggregateJsonFile.empty()) {
std::error_code EC;
- raw_fd_ostream JsonStream(AggregateJsonFile, EC,
- sys::fs::OF_Text | sys::fs::OF_None);
+ raw_fd_ostream JsonStream(AggregateJsonFile, EC, sys::fs::OF_Text);
if (EC) {
OS << "error opening aggregate error json file '" << AggregateJsonFile
<< "' for writing: " << EC.message() << '\n';
return 1;
}
JsonStream << "{\"errors\":[\n";
+ bool prev = false;
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
- JsonStream << "\"category\":\"";
+ if (prev)
+ JsonStream << ",\n";
+ JsonStream << "{\"category\":\"";
llvm::printEscapedString(category, JsonStream);
- JsonStream << "\",\"count\":" << count;
+ JsonStream << "\",\"count\":" << count << "}";
+ prev = true;
});
- JsonStream << "]}\n";
+ JsonStream << "\n]}\n";
}
return 0;
}
More information about the llvm-commits
mailing list