From 25e2b5cacc01116e9a009de2712684bf27ef55d0 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 4 Feb 2025 14:22:39 -0500 Subject: [PATCH] Fix the bug that fails to trigger the event when ccall has an arg that's a method (#553) --- src/viztracer/modules/snaptrace.c | 6 ++++++ tests/test_regression.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/viztracer/modules/snaptrace.c b/src/viztracer/modules/snaptrace.c index 508792d6..30fdd54e 100644 --- a/src/viztracer/modules/snaptrace.c +++ b/src/viztracer/modules/snaptrace.c @@ -765,6 +765,12 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg) if (PyCFunction_Check(meth)) { return (PyObject*)((PyCFunctionObject*)meth); } + } else if (Py_TYPE(callable) == &PyMethod_Type) { + PyObject* func = PyMethod_GET_FUNCTION(callable); + if (func && PyCFunction_Check(func)) { + Py_INCREF(func); + return func; + } } return NULL; } diff --git a/tests/test_regression.py b/tests/test_regression.py index 1a0225e6..438f769d 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -7,6 +7,7 @@ import signal import sys import tempfile +import textwrap import unittest import viztracer @@ -332,6 +333,21 @@ def call_self(n): expected_entries=6) +class TestIssue552(CmdlineTmpl): + def test_issue552(self): + script = textwrap.dedent(""" + from viztracer import VizTracer + class A: + f = classmethod(repr) + with VizTracer(): + A().f() + """) + + self.template([sys.executable, "cmdline_test.py"], script=script, + expected_output_file="result.json", + expected_entries=1) + + file_timestamp_disorder = """ def g(): pass