Skip to content

Submit a batch of code optimizations#72

Merged
hao022 merged 7 commits intoccfos:mainfrom
hao-lee:main
Nov 25, 2025
Merged

Submit a batch of code optimizations#72
hao022 merged 7 commits intoccfos:mainfrom
hao-lee:main

Conversation

@hao-lee
Copy link
Copy Markdown
Contributor

@hao-lee hao-lee commented Nov 24, 2025

There were no functional changes; only code efficiency was optimized and some logic was simplified.

Introduce BuildCSSToContainerID so we can reuse an existing
container map, and switch the OOM tracer to call it instead of making a second
lookup.

Signed-off-by: Hao Li <[email protected]>
Store victim container ID in a local variable before updating
containerOOMCounter. This avoids repeating the cts[...] lookup and makes the
code easier to read.

Signed-off-by: Hao Li <[email protected]>
The trigger/victim formatting logic duplicated the same fallback, hostname, and
counter code. Move this into helper functions so the main event loop reads
linearly

Signed-off-by: Hao Li <[email protected]>
- Add pod.BuildCSSToContainer to build css->*Container maps for a given subsystem.
- Use GetNormalContainers + BuildCSSToContainer in startRunqlatTracerWork so the
  CSS mapping is built once per loop instead of per-entry GetContainerByCSS calls.
- Keeps the runqlat hot path simple while avoiding repeated full container scans.

Signed-off-by: Hao Li <[email protected]>
GetContainerByCSS was called for every perf event, which repeatedly traversed
all containers. Keep a css->container cache with a short TTL, refresh it on
expiry, and re-check on misses. Preserve the original tongue-in-cheek comment
about ignoring non-container events so the context remains.

Signed-off-by: Hao Li <[email protected]>
Go strings are immutable, and any operation that appears to modify a string, such as
strings.Trim, actually creates a new string. When we convert a byte slice
(buf[:]) to a string, and then trim it, we are creating an intermediate
string, which results in extra memory allocation and copying. Frequent
allocations from repeated string conversions and trimming can increase the load
on the Go runtime's garbage collector, which can impact overall performance
especially when there are lots of events.

Multiple tracers converted fixed-size C buffers into Go strings via
string()+strings.Trim(…x00), which causes two allocations per event.

Introduce internal/utils/bytesutil.CString to stop at the first zero byte, then
switch all comm/name parsing (OOM, memory reclaim, softirq/softlockup,
dropwatch, netrecvlat, netdev txqueue timeout, hungtask, perf parser,
iotracing, and container CSS helpers) to call it. This removes the repeated
trim boilerplate and cuts allocations in these hot paths.

Signed-off-by: Hao Li <[email protected]>
Expose BuildCSSToContainer to map css addresses directly to container pointers.
Runqlat now builds its cpu css cache via the helper using GetNormalContainers.
This removes repeated manual css map construction and redundant GetContainerByCSS scans.

Signed-off-by: Hao Li <[email protected]>
@hao022 hao022 merged commit 9e32d1a into ccfos:main Nov 25, 2025
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.

2 participants