pattern_key

Function pattern_key 

Source
pub fn pattern_key(name: &str) -> String
Expand description

Compute the token-normalized skeleton for a name string.

Consumed by crate::ctprof_compare::GroupBy::Comm (thread-name grouping), crate::ctprof_compare::GroupBy::Pcomm (process-name grouping), and crate::ctprof_compare::collect_smaps_rollup (per-pcomm smaps aggregation) — each callsite passes a different field (t.comm, t.pcomm, t.pcomm respectively) and applies its own callsite-level policy on top of the skeleton this function returns.

Splits the input on a separator class ([.\-_/:@+\[\]\s]+), classifies each non-separator token by classify_token, and rejoins with the original separator runs preserved verbatim. The first matching rule wins per token:

  1. Pure digits → {N} (e.g. 42{N}).
  2. Hex-like (all chars [0-9a-f], length ≥ 2, contains at least one digit) → {H} (e.g. abc123def{H}).
  3. Alpha prefix + trailing digits (^[A-Za-z]+\d+$, alpha prefix length ≥ 1) → prefix{N} (e.g. worker7worker{N}, u8u{N}).
  4. Leading digits + alpha suffix (^\d+[A-Za-z]+$) → {N}suffix (e.g. 1H{N}H, 100Hz{N}Hz).
  5. Otherwise: keep literal.

Two names that produce the same skeleton group together at the bucket layer. The singleton-revert policy (“if only one thread / process matches a skeleton, revert to literal”) is a callsite policy enforced by crate::ctprof_compare::build_groupspattern_key itself always returns the skeleton, leaving callsites free to override (and indeed crate::ctprof_compare::collect_smaps_rollup does NOT singleton-revert; see its doc for why).

Examples:

  • whirly-gig-15whirly-gig-{N}.
  • kworker/0:0-wq_reclaimkworker/{N}:{N}-wq_reclaim.
  • kworker/u8:7kworker/u{N}:{N} (single-letter alpha prefix u qualifies under rule 3).
  • session-a1234session-{H} (hex-like).
  • BPF_CUBICBPF_CUBIC (pure alpha, no digits).
  • bloop-tanglerbloop-tangler (pure alpha).