Skip to content

observability: add built-in profiling hooks to charly — pprof CPU/heap/trace via env, phase timers, and per-process counters (project loads, plugin connects, git calls) #1343

Backlog

Description

@aitrawog

Category

category:runtime

Type

type:feat

Remedy / files the remedy will touch

charly/main.go (process-lifetime profile start/stop on every exit path incl. the kong error path), a small observability package in sdk shared by charly and served plugins (CHARLY_PROFILE_DIR →

/-.{cpu,heap,trace}.pprof per process, so plugin children are covered), counters exposed by CHARLY_STATS=1 on exit; docs in /charly-internals:go

Cited design decision or org-rulebook rule (or none)

none

Classification

Non-blocking — genuinely separable; left unclaimed for a later session to pick up.

Evidence (verified: commands with output, file:line, measurements)

charly has no profiling hook: no flag or env enables pprof, no phase timers, and no counters for project loads, plugin connects or git calls. Profiling it took a patched main.go plus a 60 s timer, because many commands do not return to a clean stop point. The result of that patched build on charly config check-pod-overlay:

$ go tool pprof -top -cum -nodecount=14 charly-prof cpu.prof
Duration: 60s, Total samples = 99.95s (166.58%)
Showing nodes accounting for 3.09s, 3.09% of 99.95s total
Dropped 1461 nodes (cum <= 0.50s)
Showing top 14 nodes out of 317
      flat  flat%   sum%        cum   cum%
     0.03s  0.03%  0.03%     55.01s 55.04%  runtime.systemstack
     0.01s  0.01%  0.04%     53.12s 53.15%  runtime.gcBgMarkWorker
         0     0%  0.04%     53.10s 53.13%  runtime.gcBgMarkWorker.func2
     0.66s  0.66%   0.7%     53.09s 53.12%  runtime.gcDrain
     2.39s  2.39%  3.09%     43.98s 44.00%  runtime.scanSpan
         0     0%  3.09%     38.82s 38.84%  runtime.gcDrainMarkWorkerIdle (inline)
         0     0%  3.09%     36.70s 36.72%  github.com/opencharly/sdk/loaderkit.LoadUnified
         0     0%  3.09%     36.37s 36.39%  github.com/opencharly/plugin-loader/candy/plugin-loader.(*provider).LoadUnified
         0     0%  3.09%     36.01s 36.03%  main.LoadUnified
         0     0%  3.09%     35.52s 35.54%  github.com/opencharly/sdk/loaderkit.(*walker).walkFile
         0     0%  3.09%     35.27s 35.29%  github.com/opencharly/sdk/loaderkit.(*walker).walkProject
         0     0%  3.09%     33.84s 33.86%  github.com/opencharly/sdk/loaderkit.Walk
         0     0%  3.09%     33.48s 33.50%  github.com/opencharly/plugin-loader/candy/plugin-loader.(*provider).WalkProject

Counting project loads, connect passes and their callers took three more ad-hoc patches. Their results are in #1340 and #1341. Process-level counters came from strace -f -e trace=execve: 82 git and 38 git-remote-https children for one command.

Mechanism

charly imports no runtime/pprof or runtime/trace, keeps no counters, and plugin processes are separate go-plugin children with their own heaps. The only instruments are external ones: strace, /usr/bin/time, or a patched binary.

Missed control

Performance has no instrument and no budget test. The 5-9+ min project resolution in charly#1024 sat measured-but-unexplained until a patched build profiled it.

Blast radius

Every performance RCA in the org. Without counters, regressions like charly#1340 (110 loads per command) land silently.

Root fix

Built-in, zero-cost-when-off hooks: CHARLY_PROFILE_DIR enables CPU+heap (+ optional runtime/trace) for charly and every served plugin process, stopped on every exit path; CHARLY_STATS=1 prints per-process counters (LoadUnified calls/full loads, kind-connect passes, plugin connects, git subprocesses, wall per phase) on exit. Plus a test that pins the load count for a fixture project, so #1340-class regressions fail CI.

Spike (its result, or none with the reason)

The spike hook is in a throwaway build, not committed:

if pf := os.Getenv("CHARLY_SPIKE_CPUPROFILE"); pf != "" {
	if f, err := os.Create(pf); err == nil {
		_ = pprof.StartCPUProfile(f)
		go func() { time.Sleep(60 * time.Second); pprof.StopCPUProfile(); _ = f.Close() }()
	}
}

It produced the profile above: GC at 53% and loaderkit.LoadUnified at 36.7% cumulative. That profile named the mechanism behind charly#1340, #1341 and #1024. Two gaps remain: the 60 s timer truncates longer commands, and child plugin processes (go-plugin) are not covered.

Agent: vol-cdi · Claude Code session 8daa865c-d43e-447b-90b3-7d16ccc921d7
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (analysed on a live system)

Activity

  1. added
    category:runtime
    type:feat
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:runtimetype:feat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions