[llvm] GSym aggregated output to JSON file (PR #81763)
Kevin Frei via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 09:12:35 PST 2024
https://github.com/kevinfrei updated https://github.com/llvm/llvm-project/pull/81763
>From 9be8370fc599eea03bc86f9fbcf7715a52bf03b2 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/4] 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 6f2bb141f8ec30e8ab2336e4cd69151481daae15 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/4] 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;
}
>From 7df0ccd9b94a30e6101e2d590232ca10d2c231d3 Mon Sep 17 00:00:00 2001
From: Kevin Frei <freik at meta.com>
Date: Wed, 14 Feb 2024 16:06:04 -0800
Subject: [PATCH 3/4] Updated with Clayborg's feedback
---
llvm/tools/llvm-gsymutil/Opts.td | 6 ++---
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | 31 +++++++++++-----------
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/llvm/tools/llvm-gsymutil/Opts.td b/llvm/tools/llvm-gsymutil/Opts.td
index 00e81a9f85aa70..3aabc8029ccbe7 100644
--- a/llvm/tools/llvm-gsymutil/Opts.td
+++ b/llvm/tools/llvm-gsymutil/Opts.td
@@ -35,6 +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.">;
+defm json_summary_file :
+ Eq<"json-summary-file",
+ "Output a categorized summary of errors into the JSON file specified.">;
diff --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index 608c75e7e2fef0..727d578bcad5e9 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -19,6 +19,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"
@@ -88,7 +89,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 std::string JsonSummaryFile;
static bool Verify;
static unsigned NumThreads;
static uint64_t SegmentSize;
@@ -140,8 +141,8 @@ 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();
+ if (const llvm::opt::Arg *A = Args.getLastArg(OPT_json_summary_file_EQ))
+ JsonSummaryFile = A->getValue();
Verify = Args.hasArg(OPT_verify);
@@ -525,25 +526,25 @@ int llvm_gsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
OS << category << " occurred " << count << " time(s)\n";
});
- if (!AggregateJsonFile.empty()) {
+ if (!JsonSummaryFile.empty()) {
std::error_code EC;
- raw_fd_ostream JsonStream(AggregateJsonFile, EC, sys::fs::OF_Text);
+ raw_fd_ostream JsonStream(JsonSummaryFile, EC, sys::fs::OF_Text);
if (EC) {
- OS << "error opening aggregate error json file '" << AggregateJsonFile
+ OS << "error opening aggregate error json file '" << JsonSummaryFile
<< "' for writing: " << EC.message() << '\n';
return 1;
}
- JsonStream << "{\"errors\":[\n";
- bool prev = false;
+
+ llvm::json::Object Categories;
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
- if (prev)
- JsonStream << ",\n";
- JsonStream << "{\"category\":\"";
- llvm::printEscapedString(category, JsonStream);
- JsonStream << "\",\"count\":" << count << "}";
- prev = true;
+ llvm::json::Object Val;
+ Val.try_emplace("count", count);
+ Categories.try_emplace(category, std::move(Val));
});
- JsonStream << "\n]}\n";
+ llvm::json::Object RootNode;
+ RootNode.try_emplace("error-categories", std::move(Categories));
+
+ JsonStream << llvm::json::Value(std::move(RootNode));
}
return 0;
}
>From 01a88dd333025ca843a8d9172106280cd7d27030 Mon Sep 17 00:00:00 2001
From: Kevin Frei <freik at meta.com>
Date: Thu, 15 Feb 2024 09:07:58 -0800
Subject: [PATCH 4/4] Removed a header leftover from earlier draft
---
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index 727d578bcad5e9..2256d7e9f28663 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#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"
More information about the llvm-commits
mailing list