Skip to content

Conversation

@victormlg
Copy link
Contributor

@victormlg victormlg commented Oct 14, 2025

The policy evaluation creates multiple copies of the same bundle, promise, and function stack frames. The final evaluation tree is built on the assumption that the correct evaluation tree is the one with the longest execution time.

Example policy:

bundle agent main
{
  commands:
    "/bin/sleep 1";
}

To generate the profiling tree, run:
sudo /var/cfengine/bin/cf-agent -Kpf ~/profiler5.cf

{
  "children": [
    {
      "children": [
        {
          "children": [],
          "elapsed": 1007,
          "filename": "",
          "name": "commands",
          "offset": {
            "end": 0,
            "lineno": 4,
            "start": 67
          },
          "type": "promise"
        }
      ],
      "elapsed": 1012,
      "filename": "/home/vagrant/profiler5.cf",
      "name": "main",
      "offset": {
        "end": 85,
        "lineno": 1,
        "start": 13
      },
      "type": "bundle"
    }
  ],
  "elapsed": 1012,
  "filename": "",
  "name": "",
  "offset": {
    "end": 0,
    "lineno": 0,
    "start": 0
  },
  "type": "policy"
}

Depends on NorthernTechHQ/libntech#258

@victormlg
Copy link
Contributor Author

victormlg commented Oct 14, 2025

I still need to add functions execution in the profiler

edit: this is done

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@victormlg victormlg force-pushed the profiler-3 branch 2 times, most recently from 20debf1 to 7f623aa Compare October 20, 2025 13:22
@victormlg victormlg force-pushed the profiler-3 branch 3 times, most recently from 6347574 to 1c3e1ca Compare October 21, 2025 09:21
@victormlg victormlg requested a review from larsewi October 21, 2025 10:09
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

Some smaller comments

Changelog: The policy profiling logic is now implemented natively within the cf-agent, replacing the previous reliance on cf-agent logs and the cf-profile.pl script for faster execution.
Ticket: ENT-8096
Signed-off-by: Victor Moene <victor.moene@northern.tech>
{
assert(ctx != NULL);
assert(last_event != NULL);
SeqAppend(ctx->events, last_event); // keep track of EventFrames for cleanup
Copy link
Member

Choose a reason for hiding this comment

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

@victormlg I think this part (pushing an event into the Seq) is the only thing we want to do while evaluating policy. The rest (building a nice tree, hashmaps, summarizing, sorting, etc. Should all appen by iterating over the events after policy evaluation is done.

return;
}

JsonElement *tree = EventFrameTreeToJson(ctx->root);
Copy link
Member

Choose a reason for hiding this comment

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

Here we should loop over the "unprocessed" events in the Seq, and convert them to the proper tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants