Skip to content

[feature][P1] script profiler: function-level hotspot distribution — niu --profile script.sh (deterministic interpreter instrumentation) #815

Closed

Description

@caomengxuan666

Owner directive(2026-10-18:"更重要的基础设施:输入一个脚本,获取所有的性能热点分布,精确到函数上")

设计(M1)

机制:解释器确定性插桩(非外部采样)——rubash 拥有全部执行路径,在函数入口/出口(execute_function 家族)与顶层命令分发点挂钩,Accumulate self/children 时间与调用计数。开销仅 profile 开启时存在(预估 5-15%);关闭时零成本(不回退 #607-#609 热路径优化的任何字节)。

输出:

  1. 文本调用树:函数 self/children 时间 + 调用次数 + 排序
  2. collapsed-stack 格式(兼容 flamegraph/speedscope)
  3. 归因分列:内建 / 外部 spawn / 子壳与命令替换(fork 面与解释器面分开——[bug] declare -r RO PID + coproc on readonly name: rubash leaves the _PID var visible to declare -p (GNU does not) #352 的"内联记账"教训:混记会撒谎)

接口:niu --profile <script> [--profile-output out.collapsed];交互态 PROFILE 开关后置。

杀手级验收(本仓独有打法)

83 套件 GNU 差分全集在 profiler 开启状态下重跑:stdout/stderr/rc 逐字节一致——用自家金标准证明"插桩零语义扰动"。这条过了,profiler 的可信度即成立。

与 #497 的关系

debugger(断言/单步)与 profiler(计时)共用同一执行器插桩点——基础设施一次建、两个消费者;也是 1.5.0 core 拆分后 core 层的天然功能(拆分不阻塞本票:M1 在现行单 crate 上实现,拆分时随层迁移)。

M2(后续,不在本票)

行级精度(sampling 混合)、内存剖析、--profile 交互态。

验收清单

Activity

  1. added
    enhancement
    P1-high
    performance
    on Oct 18, 2026
  2. added a commit that references this issue on Oct 18, 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

    P1-highenhancementperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions