[BUG]: Missing calls from a cProfile profile when calling into a pybind11 extension
Maintainer antworten meist innerhalb von 3 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne mit dem Python-cProfile-Beispiel und den pybind11-Erweiterungsdefinitionen für CppClass.call_me und ext.return_zero und vergleiche deren Profile unter Python 3.10 und 3.12. Verfolge den pybind11-Aufrufpfad im Vergleich mit dem im Issue erwähnten handgefertigten C-API-Vergleich. Als erledigt gilt die Aufgabe, wenn Aufrufe von call_me und der sie umgebenden Python-Funktion im erzeugten Profil korrekt erscheinen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
tried with both 2.13.6 and master
Problem description
Consider the following Python code using cProfile:
import cProfile
import sys
import ext
def call_me() -> None:
obj = ext.CppClass()
for _ in range(10):
obj.call_me()
def main() -> None:
print("Profiling...\n\n")
cProfile.run("call_me()")
if __name__ == "__main__":
main()
where ext is the following pybind11 extension:
#include <pybind11/pybind11.h>
namespace myspace {
class CppClass {};
} // namespace myspace
namespace py = pybind11;
PYBIND11_MODULE(ext, m) {
m.doc() = "Simple C++ Python extension using pybind11";
m.def("return_zero", []() { return 0; });
py::class_<myspace::CppClass>(m, "CppClass")
.def(py::init<>())
.def("call_me", [](myspace::CppClass& self) {
printf("hello!\n");
return 0;
});
}
Running this under Python 3.12.8 produces the following output:
Profiling...
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
1 function calls in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
Notably, the resulting profile doesn't include anything about the Python call to call_me(), nor the 10 calls to the pybind11 call_me() method on the obj instance. We can see from the "hello" prints in the output that the method was indeed called.
Interestingly, when changing the call inside the loop to ext.return_zero() instead, the profile produced is as expected:
Profiling...
14 function calls in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 repro.py:11(call_me)
1 0.000 0.000 0.000 0.000 {built-in method builtins.exec}
10 0.000 0.000 0.000 0.000 {built-in method ext.return_zero}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
Using Python 3.10 instead of 3.12, the second profile is identical, while the first one is still missing some calls, but it's not missing the initial Python call_me() call:
Profiling...
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
hello!
4 function calls in 0.000 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 repro.py:11(call_me)
1 0.000 0.000 0.000 0.000 {built-in method builtins.exec}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
I think this is likely pybind11-specific, because I tried reproducing this with an equivalent C++ extension using hand crafted C-API, and couldn't observe the issue.
Reproducible example code
Is this a regression? Put the last known working version here if it is.
Not a regression
- Vorherrschende Sprache
- C++
- Sterne
- 18k
- Forks
- 2.3k
- Ø Merge
- 5 T. 7 Std.
- Gemergte PRs (30 T.)
- 53
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus pybind/pybind11
-
triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 3 Tagen
-
triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 62/100
pybind/pybind11#5604 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
-
triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 3 Tagen
-
docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
pybind/pybind11#747 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 3 Tagen
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)Evtl. vergeben @henryiii hat das heute übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in pybind/pybind11
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
patrick-hudson/put.gd-desktop#2044 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
uxlfoundation/oneDNN#6604 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Evtl. vergeben @fmu1337 hat das heute übernommen. OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
alliedmodders/sourcemod#2627 ·
Maintainer antworten meist innerhalb von 1 Tag