Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parent frame indiscriminately in nested provenance #666

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions legate/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from __future__ import annotations

import inspect
import traceback
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -53,16 +52,11 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any:
...


def find_last_user_frame(libname: str) -> str:
for frame, _ in traceback.walk_stack(inspect.currentframe()):
if "__name__" not in frame.f_globals:
continue
if not any(
frame.f_globals["__name__"].startswith(prefix)
for prefix in (libname, "legate")
):
break

def caller_frameinfo() -> str:
frame = inspect.currentframe()
if frame is None or frame.f_back is None or frame.f_back.f_back is None:
return "<unknown>"
frame = frame.f_back.f_back
return f"{frame.f_code.co_filename}:{frame.f_lineno}"


Expand Down Expand Up @@ -350,7 +344,7 @@ def track_provenance(
if nested:

def wrapper(*args: Any, **kwargs: Any) -> Any:
self.push_provenance(find_last_user_frame(self._libname))
self.push_provenance(caller_frameinfo())
result = func(*args, **kwargs)
self.pop_provenance()
return result
Expand All @@ -359,7 +353,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:

def wrapper(*args: Any, **kwargs: Any) -> Any:
if self.provenance is None:
self.set_provenance(find_last_user_frame(self._libname))
self.set_provenance(caller_frameinfo())
result = func(*args, **kwargs)
self.reset_provenance()
else:
Expand Down