Skip to content

JSON Reporting #80

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 6 commits into from
May 17, 2024
Merged

JSON Reporting #80

merged 6 commits into from
May 17, 2024

Conversation

fosterbrereton
Copy link
Contributor

@fosterbrereton fosterbrereton commented May 16, 2024

This PR adds a new flag to ORC's config file, output_file_mode. Fixes #79.

The flag determines what format should be used for content written to external report files defined by either output_file or relative_output_file. The options are text or json. text will mirror all output sent to stdout and stderr to the file. json will limit output file contents to the ODRV report. This mode enumerates all object files with conflicting symbols, so can be quite verbose. It is intended for programmatic consumption. The default value is text.

This PR also removes the resource_metrics capability of the tool. It's been decided Tracy is a better solution to meet such a need. Therefore the flag and the code associated with supporting it have been pulled out.

An example snippet of the JSON output looks something like:

{
  "synopsis": {
    "dies_processed": 163925,
    "dies_skipped": 122239,
    "dies_skipped_pct": 74.57007777947231,
    "object_files_scanned": 92,
    "unique_symbols": 3435,
    "violations": 11
  },
  "violations": {
    "example_struct": {
      "attributes": [
        "structure:byte_size",
        "structure:calling_convention"
      ],
      "definitions": [
        {
          "attributes": {
            "byte_size": 624
          },
          "count": 33,
          "locations": {
            "/path/to/library/header.h:430": {
              "/path/to/library.a": [
                "foo.o",
                "bar.o",
                "baz.o",
...

@fosterbrereton fosterbrereton marked this pull request as ready for review May 16, 2024 20:32
assert(globals._odrv_count == violations.size());

if (json_mode && globals._fp.is_open()) {
globals._fp << orc::to_json(violations);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the JSON object is serialized to the file.

@@ -85,8 +87,10 @@ template <class F>
void ostream_safe(std::ostream& s, F&& f) {
std::lock_guard<std::mutex> lock{ostream_safe_mutex()};
std::forward<F>(f)(s);
if (globals::instance()._fp.is_open()) {
std::forward<F>(f)(globals::instance()._fp);
if (settings::instance()._output_file_mode == settings::output_file_mode::json) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This circumvents writing anything to the file if we're in json output mode.

Copy link
Contributor

@leethomason leethomason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@fosterbrereton fosterbrereton merged commit 88b553f into main May 17, 2024
3 checks passed
@fosterbrereton fosterbrereton deleted the fosterbrereton/json-reports branch May 17, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON Output Mode
2 participants