python / python/cpython

Add runtime control for `profiling.sampling`

未关闭
#145,411 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-profiling type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Feature or enhancement

Proposal:

The idea is to add an optional control channel (socket? named pipe?), so another process can start, stop etc. profiling without killing/restarting the profiler completely. Right now, the only option is to interact with it via TUI mode or just stop it via Ctrl-C.

While working on https://github.com/psf/pyperf/pull/230 I ran into the following problem: some parts (eg: warming up) of benchmarking should not be profiled, as they do not add any value. My only option was sending SIGINT signal.

Generally, the current flow is nice for headful sessions but it could be improved for (especially long-running) headless sessions.

perf record --control does it in a similar way:

       --control=fifo:ctl-fifo[,ack-fifo], --control=fd:ctl-fd[,ack-fd]
           ctl-fifo / ack-fifo are opened and used as ctl-fd / ack-fd as
           follows. Listen on ctl-fd descriptor for command to control
           measurement.

       Available commands:

       •   enable : enable events
       •   disable : disable events
       •   enable name : enable event name
       •   disable name : disable event name
       •   snapshot : AUX area tracing snapshot).
       •   stop : stop perf record
       •   ping : ping
       •   'evlist [-v|-g|-F] : display all events
               -F  Show just the sample frequency used for each event.
               -v  Show all fields.
               -g  Show event group information.

Specifically:

  • We could start with just enable and disable initially. snapshot next but it'd be lovely to dump without loosing accumulated data. Or maybe even set_rate.
  • Possible transport layers could be Unix sockets (works great on Linux) or named pipe. One option might be portable, another not?
  • Possble new arguments like --control unix:/tmp/tachyon-ctl.sock or --control fifo:/tmp/tachyon-ctl, similar to what perf record --control does.

It could be also ommited from the documentation initially, so we don't limit ourselves too early.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-149958

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先跟踪现有的 profiling.sampling 流程,以及 TUI 模式和 SIGINT 当前如何控制 profiling。将提议的启用/禁用控制流程与 perf record --control 进行比较,包括 Unix socket 或 named pipe 选项以及提议的 --control 参数。完成意味着定义一个运行时控制接口,支持无需重启 profiler 的无头 profiling。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
performance, tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。