[New-bugs-announce] [issue44530] Propagate qualname from the compiler unit to code objects for finer grained profiling data

Gabriele N Tornetta report at bugs.python.org
Mon Jun 28 18:35:33 EDT 2021


New submission from Gabriele N Tornetta <phoenix1987 at gmail.com>:

When dumping profiling data out of code objects using out-of-process tools like Austin (https://github.com/p403n1x87/austin) one has access only to file name, function name, and line number. Consider the flame graph generated by running the following script, and aggregating on function names

----
class Foo:
    def on_cpu(self, n):
        a = []
        for i in range(n):
            a.append(i)


class Bar:
    def on_cpu(self, n):
        a = []
        for i in range(n):
            a.append(i)


if __name__ == "__main__":
    f = Foo()
    b = Bar()

    f.on_cpu(1_000_000)
    b.on_cpu(5_000_000)
----

Without the extra information coming from the actual Python source, one would not be able to tell, by looking at the flame graph alone, that on_cpu has contributions from two different methods. By propagating the qualname information from the compiler to code objects, such names would be disambiguated and the resulting flame graph would be clearer.

I would like to propose adding the co_qualname field to the PyCodeObject structure, which is to be set to NULL except for when the code object is created by the compiler in compile.c.

----------
components: C API
files: py_main.png
messages: 396667
nosy: Gabriele Tornetta
priority: normal
severity: normal
status: open
title: Propagate qualname from the compiler unit to code objects for finer grained profiling data
type: enhancement
versions: Python 3.11
Added file: https://bugs.python.org/file50128/py_main.png

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44530>
_______________________________________


More information about the New-bugs-announce mailing list