[Discussion] DTrace Support in Python: Should We Remove It Completely or Restore Pre-3.12 Functionality?

Hi folks, sorry to take up everyone’s time.

I’d like to formally initiate a discussion in DPO regarding DTrace support in Python (this might also be the final discussion about this feature).

First, please allow me to list some prerequisite discussions:

  1. https://github.com/python/cpython/issues/104280

  2. https://github.com/python/cpython/pull/125019

In short, we officially introduced partial DTrace support around Python 3.6 as part of Python’s supported static tracing technologies.

However, it was removed in Python 3.12 due to the implementation of PEP 669, and has not been re-added since.

The official documentation is still in an unupdated state: https://docs.python.org/3/howto/instrumentation.html

From my perspective, we currently face two choices:

  1. We completely remove DTrace and clean up the related documentation

  2. We restore support to pre-3.12 levels

Regarding the reasons for removing DTrace support, @markshannon has provided some explanations in both Issue 104280 and PR 125019, roughly as follows:

  1. We now have PEP 669 as low-cost tracing

  2. If it can’t be compatible with JIT, it has limited value

From my personal sentiment and practical use case perspective, I hope to support DTrace for the following reasons:

  1. From an engineering scenario standpoint, DTrace, PEP 669, and the Remote Debugging support coming in 3.15 differ significantly in principles and use cases. A common use case for DTrace is that specific users employ non-intrusive instrumentation to obtain audit and operational information. Additionally, people also use more general technology stacks like eBPF to assist in program monitoring: https://github.com/cloudflare/ebpf_exporter/blob/master/examples/usdt.bpf.c#L17-L27

  2. Regarding JIT scenarios, please forgive my presumption. In the near future or medium-term timeframe, I believe widespread use of JIT in production environments won’t be commonplace. In this situation, people might choose to disable JIT to continue using CPython (this point was also mentioned in PR125019). In such cases, DTrace won’t become worthless; on the contrary, it will be extremely valuable in specific scenarios.

The interaction between DTrace and JIT is actually a solvable problem. However, I think we need to make a decision now: whether DTrace will continue to be maintained in the CPython codebase.

3 Likes

Official binaries for Python 3.14 will be released with JIT support. How useful will it be to add/restore support for a Unix profiling feature that will need to be removed in a couple of versions’ time, if it doesn’t support the JIT? I expect the pace of adoption will increase, especially as experimentation with it becomes easier.

More broadly, who will maintain support? DTrace requires special configure options, meaning it requires dedicated testing, as opposed to something like sys.monitoring.

A

Can we enable DTrace support conditional on the JIT not being enabled until we land full DTrace support with JIT? I understand and applaud the functionality provided by sys.monitoring but it handles a use case that is fundamentally distinct from that handled by DTrace.

I’m happy to contribute time and resourcing to ensure that this particular corner of Python becomes functional again.

I recently encountered the need described here while analyzing a complex code base. I’ve made this library which stitches the new-style sys.monitoring interfaces up to USDT, so that bpftrace can observe python and kernel activity simultaneously … hopefully its useful to others who arrive here :slight_smile:

I originally added dtrace to Python 3.6 and I would like to restore the probes that we can restore. For 3.15 it’s feasible to restore function calls but not per-line execution. That seems to be the workable solution for us now.

I would like to make a more clear PR to restore it if the core developer make the decision

Yes, but it seems the different core developer have different view on this. Do we need the DTrace or not? I think maybe we need to make a decision. The feature is totally different with docs since 3.12.. it’s too long I think