Skip to content

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.

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
@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

3 participants