[llvm] GSym aggregated output to JSON file (PR #81763)
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 14:05:59 PST 2024
================
@@ -515,10 +520,31 @@ 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);
+ 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) {
+ if (prev)
+ JsonStream << ",\n";
+ JsonStream << "{\"category\":\"";
+ llvm::printEscapedString(category, JsonStream);
+ JsonStream << "\",\"count\":" << count << "}";
+ prev = true;
+ });
+ JsonStream << "\n]}\n";
----------------
clayborg wrote:
To create this kind of thing with objects the JSON code would look like:
```
llvm::json::Object category_dict;
Aggregation.EnumerateResults([&](StringRef category, unsigned count) {
llvm::json::Object category_info;
category_info.try_emplace("count", count);
category_dict.try_emplace(category, category_info);
});
llvm::json::Object json_output;
json_output.try_emplace("error-categories", category_dict);
// Convert JSON objects to a string
std::string s;
llvm::raw_string_ostream strm(s);
strm << json_output;
```
https://github.com/llvm/llvm-project/pull/81763
More information about the llvm-commits
mailing list