Skip to content

Conversation

@victormlg
Copy link
Contributor

@victormlg victormlg commented Oct 28, 2025

sudo /var/cfengine/bin/cf-agent -Kp | python3 contrib/cf-profile/cf-profile.py --promises --functions --top 5

output:

Component                                                    Location                                                                                                   Time
promise methods                                              /var/cfengine/inputs/cfe_internal/CFE_cfengine.cf:70                                                 1703.08 ms
promise methods                                              /var/cfengine/inputs/cfe_internal/enterprise/mission_portal.cf:91                                    1442.38 ms
promise vars                                                 /var/cfengine/inputs/cfe_internal/enterprise/mission_portal.cf:201                                   1247.32 ms
function datastate                                           /var/cfengine/inputs/cfe_internal/enterprise/mission_portal.cf:201                                    352.50 ms
promise vars                                                 /var/cfengine/inputs/cfe_internal/enterprise/federation/federation.cf:905                             260.92 ms

@nickanderson
Copy link
Member

Nice.

Times could be human readable (N seconds, minutes).

maybe it would be nice to be able to exclude , but probably that's scope creep for no good reason since you can just --top MORE.

@olehermanse
Copy link
Member

@victormlg nice, some things to improve, mainly based on your example output;

  1. Avoid using the word component here since we already have another specific meaning for that. For example Type would be better.
  2. --promises as the filter should exclude methods promises, AKA bundle invocations. To see those, user should specify --bundles as the filter.
  3. The left column reads weird / backwards. Suggest these changes:
    • promise vars -> vars promise.
    • function datastate -> datastate() function call.
    • promise methods -> bundle invocation.
  4. As Nick said, printing seconds / minutes might be nicer. In your example it's not a problem, but imagine a slow policy where things take several minutes, reading 632241.12 ms will not be so nice. To make things simple you could print it like it is now for smaller than 1 second, then switch to printing seconds when it's 1000ms or more (e.g. 2.58s), and then switch again once you pass 60 seconds (1m32s).

@victormlg victormlg force-pushed the cf_profile_py branch 3 times, most recently from 16f8793 to 652623e Compare November 7, 2025 08:36
@github-actions
Copy link

github-actions bot commented Dec 7, 2025

Marking this PR as stale due to inactivity; it will be closed in 7 days.

@github-actions github-actions bot added the stale Pull requests with no recent activity label Dec 7, 2025
@victormlg
Copy link
Contributor Author

To generate a flamegraph:

outputgraph

$ sudo /var/cfengine/bin/cf-agent -Kp > output.json
$ cat output.json | python3 cf-profile.py --flamegraph callstack.txt
$ ./flamegraph callstack.txt > flamegraph.svg

Signed-off-by: Victor Moene <[email protected]>
@victormlg victormlg requested a review from olehermanse December 8, 2025 18:06
@github-actions github-actions bot removed the stale Pull requests with no recent activity label Dec 8, 2025
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.

4 participants