From 17f801dc69dc0553a62bb806b13f44abe137eddc Mon Sep 17 00:00:00 2001 From: Max Fitton Date: Fri, 21 Aug 2020 11:02:12 -0700 Subject: [PATCH] Make get_py_stack return more stack frames (#9512) --- python/ray/_raylet.pyx | 19 +++++++++---------- python/ray/tests/test_memstat.py | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/python/ray/_raylet.pyx b/python/ray/_raylet.pyx index dead48d95..1b435d81a 100644 --- a/python/ray/_raylet.pyx +++ b/python/ray/_raylet.pyx @@ -651,33 +651,32 @@ cdef void get_py_stack(c_string* stack_out) nogil: except ValueError: # overhead of exception handling is about 20us stack_out[0] = "".encode("ascii") return - msg = "" - while frame: + msg_frames = [] + while frame and len(msg_frames) < 4: filename = frame.f_code.co_filename # Decode Ray internal frames to add annotations. if filename.endswith("ray/worker.py"): if frame.f_code.co_name == "put": - msg = "(put object) " + msg_frames = ["(put object) "] elif filename.endswith("ray/workers/default_worker.py"): pass elif filename.endswith("ray/remote_function.py"): # TODO(ekl) distinguish between task return objects and # arguments. This can only be done in the core worker. - msg = "(task call) " + msg_frames = ["(task call) "] elif filename.endswith("ray/actor.py"): # TODO(ekl) distinguish between actor return objects and # arguments. This can only be done in the core worker. - msg = "(actor call) " + msg_frames = ["(actor call) "] elif filename.endswith("ray/serialization.py"): if frame.f_code.co_name == "id_deserializer": - msg = "(deserialize task arg) " + msg_frames = ["(deserialize task arg) "] else: - msg += "{}:{}:{}".format( + msg_frames.append("{}:{}:{}".format( frame.f_code.co_filename, frame.f_code.co_name, - frame.f_lineno) - break + frame.f_lineno)) frame = frame.f_back - stack_out[0] = msg.encode("ascii") + stack_out[0] = " | ".join(msg_frames).encode("ascii") cdef shared_ptr[CBuffer] string_to_buffer(c_string& c_str): cdef shared_ptr[CBuffer] empty_metadata diff --git a/python/ray/tests/test_memstat.py b/python/ray/tests/test_memstat.py index 2c8db67fa..b10d09916 100644 --- a/python/ray/tests/test_memstat.py +++ b/python/ray/tests/test_memstat.py @@ -124,7 +124,7 @@ def test_actor_task_refs(ray_start_regular): assert count(info, PINNED_IN_MEMORY) == 1, info assert count(info, USED_BY_PENDING_TASK) == 2, info assert count(info, DESER_ACTOR_TASK_ARG) == 1, info - assert count(info, "test_memstat.py:test_actor_task_refs") == 2, info + assert count(info, "test_memstat.py:test_actor_task_refs") == 3, info assert count(info, "test_memstat.py:make_actor") == 1, info del x_id