Skip to content
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

Add --profile option to regal lint #361

Merged
merged 1 commit into from
Oct 3, 2023
Merged

Add --profile option to regal lint #361

merged 1 commit into from
Oct 3, 2023

Conversation

anderseknert
Copy link
Member

@anderseknert anderseknert commented Oct 2, 2023

This sets a profiler on eval in each goroutine, and then accumulates the result from each into a final report. At this point we're only including this in the JSON output format (similar to --metrics) but we'll want to support this for each format some time later.

Fixes #334

go run main.go lint -f json --profile bundle
{
  "violations": [],
  "summary": {
    "files_scanned": 98,
    "files_failed": 0,
    "files_skipped": 0,
    "num_violations": 0
  },
  "profile": [
    {
      "location": "/regal/ast.rego:278",
      "total_time_ns": 1329484096,
      "num_eval": 4,
      "num_redo": 27214,
      "num_gen_expr": 4
    },
    {
      "location": "/regal/config/config.rego:90",
      "total_time_ns": 1122320502,
      "num_eval": 176,
      "num_redo": 88,
      "num_gen_expr": 4
    },
    {
      "location": "/regal/ast.rego:218",
      "total_time_ns": 984304114,
      "num_eval": 130766,
      "num_redo": 66674,
      "num_gen_expr": 6
    },
    {
      "location": "/regal/main.rego:69",
      "total_time_ns": 795476410,
      "num_eval": 252,
      "num_redo": 84,
      "num_gen_expr": 6
    },
    {
      "location": "/regal/config/config.rego:39",
      "total_time_ns": 792559582,
      "num_eval": 88,
      "num_redo": 0,
      "num_gen_expr": 2
    },
    {
      "location": "/regal/ast.rego:307",
      "total_time_ns": 726335912,
      "num_eval": 140,
      "num_redo": 102,
      "num_gen_expr": 4
    },
    {
      "location": "/regal/main.rego:46",
      "total_time_ns": 648658586,
      "num_eval": 84,
      "num_redo": 0,
      "num_gen_expr": 2
    },
    {
      "location": "/regal/main.rego:44",
      "total_time_ns": 576676664,
      "num_eval": 252,
      "num_redo": 84,
      "num_gen_expr": 6
    },
    {
      "location": "/regal/rules/testing/metasyntactic_variable.rego:48",
      "total_time_ns": 530986756,
      "num_eval": 16,
      "num_redo": 24,
      "num_gen_expr": 4
    },
    {
      "location": "/regal/config/config.rego:17",
      "total_time_ns": 526488250,
      "num_eval": 8,
      "num_redo": 8,
      "num_gen_expr": 8
    }
  ]
}

This sets a profiler on eval in each goroutine, and
then accumulates the result from each into a final
report. At this point we're only including this in
the JSON output format (similar to `--metrics`) but
we'll want to support this for each format some time
later.

Fixes #334

Signed-off-by: Anders Eknert <anders@styra.com>
Copy link
Member

@charlieegan3 charlieegan3 left a comment

Choose a reason for hiding this comment

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

LGTM

@anderseknert anderseknert merged commit 28a51f7 into main Oct 3, 2023
1 check passed
@anderseknert anderseknert deleted the profiling branch October 3, 2023 09:04
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.

Profiling
2 participants