Skip to content

Commit

Permalink
Merge pull request #342 from KantaTamura/profile-exit-context
Browse files Browse the repository at this point in the history
fix a bug that can't profiling of context close (io.close)
  • Loading branch information
k5342 authored Aug 28, 2024
2 parents bdc81e5 + cd4972b commit 9bf5900
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pfio/v2/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .fs import FS, FileStat, format_repr


class LocalProfileWrapper:
class LocalProfileIOWrapper:
def __init__(self, fp):
self.fp = fp

Expand All @@ -17,7 +17,8 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.fp.__exit__(exc_type, exc_value, traceback)
with record("pfio.v2.Local:exit-context", trace=True):
self.fp.__exit__(exc_type, exc_value, traceback)

def __getattr__(self, name):
attr = getattr(self.fp, name)
Expand Down Expand Up @@ -121,7 +122,7 @@ def open(self, file_path, mode='r',

# Add ppe recorder to io class methods (e.g. read, write)
if self.trace:
return LocalProfileWrapper(fp)
return LocalProfileIOWrapper(fp)
else:
return fp

Expand Down
2 changes: 2 additions & 0 deletions tests/v2_tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def test_local_rw_profiling():

assert "pfio.v2.Local:open" in keys
assert "pfio.v2.Local:write" in keys
assert "pfio.v2.Local:exit-context" in keys

with Local(trace=True) as fs:
ppe.profiler.clear_tracer()
Expand All @@ -320,6 +321,7 @@ def test_local_rw_profiling():

assert "pfio.v2.Local:open" in keys
assert "pfio.v2.Local:read" in keys
assert "pfio.v2.Local:exit-context" in keys

# no profile case
with Local(trace=False) as fs:
Expand Down

0 comments on commit 9bf5900

Please sign in to comment.