Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 9 additions & 18 deletions scalene/scalene_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ def __init__(
try:
Scalene.__malloc_mapfile = ScaleneMapFile("malloc")
Scalene.__memcpy_mapfile = ScaleneMapFile("memcpy")
# Initialize memory profiler
# Scalene.__memory_profiler = ScaleneMemoryProfiler(Scalene.__stats)
Scalene.__memory_profiler.set_mapfiles(
Scalene.__malloc_mapfile, Scalene.__memcpy_mapfile
)
Expand Down Expand Up @@ -366,13 +364,13 @@ def last_profiled_tuple() -> tuple[Filename, LineNumber, ByteCodeIndex]:
__orig_siginterrupt = signal.siginterrupt

@classmethod
def clear_metrics(cls) -> None:
def _clear_metrics(cls) -> None:
"""Clear the various states for forked processes."""
cls.__stats.clear()
cls.child_pids.clear()

@classmethod
def add_child_pid(cls, pid: int) -> None:
def _add_child_pid(cls, pid: int) -> None:
"""Add this pid to the set of children. Used when forking."""
cls.child_pids.add(pid)

Expand All @@ -392,7 +390,7 @@ def after_fork_in_child() -> None:
"""
Scalene.__is_child = True

Scalene.clear_metrics()
Scalene._clear_metrics()
if Scalene.__accelerator and Scalene.__accelerator.has_gpu():
Scalene.__accelerator.reinit()
# Note: __parent_pid of the topmost process is its own pid.
Expand All @@ -406,7 +404,7 @@ def after_fork_in_parent(child_pid: int) -> None:

Invoked by replacement_fork.py.
"""
Scalene.add_child_pid(child_pid)
Scalene._add_child_pid(child_pid)
Scalene.start_signal_queues()

@staticmethod
Expand Down Expand Up @@ -467,7 +465,7 @@ def update_profiled() -> None:
Scalene.update_line()

@staticmethod
def profile(func: Any) -> Any:
def _profile(func: Any) -> Any:
"""Record the file and function name.

Replacement @profile decorator function. Scalene tracks which
Expand Down Expand Up @@ -1719,18 +1717,11 @@ def multiprocessing_warning(
sys.exit(exit_status)


# Install our profile decorator.
def scalene_redirect_profile(func: Any) -> Any:
"""Handle @profile decorators.
# Handle @profile decorators.
# If Scalene encounters any functions decorated by @profile, it will
# only report stats for those functions.

If Scalene encounters any functions decorated by @profile, it will
only report stats for those functions.

"""
return Scalene.profile(func)


builtins.profile = scalene_redirect_profile # type: ignore
builtins.profile = Scalene._profile # type: ignore


def start() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_coverup_137.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def mock_profile(func):
# Apply the patch to the Scalene.profile method
@pytest.fixture
def mock_scalene(monkeypatch):
monkeypatch.setattr("scalene.scalene_profiler.Scalene.profile", mock_profile)
monkeypatch.setattr("scalene.scalene_profiler.Scalene._profile", mock_profile)


def test_scalene_redirect_profile(mock_scalene):
# Assuming scalene_redirect_profile is a function in the scalene_profiler module
from scalene.scalene_profiler import scalene_redirect_profile
from scalene.scalene_profiler import Scalene

# Define a dummy function to be decorated
def dummy_function():
pass

# Decorate the dummy function using the scalene_redirect_profile
decorated_function = scalene_redirect_profile(dummy_function)
decorated_function = Scalene._profile(dummy_function)

# Assert that the function has been 'profiled' by checking the side effect
assert hasattr(decorated_function, "has_been_profiled")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_coverup_96.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def scalene_cleanup():


def test_add_child_pid(scalene_cleanup):
# Test to ensure that add_child_pid adds a pid to the child_pids set
# Test to ensure that _add_child_pid adds a pid to the child_pids set
test_pid = 12345
assert test_pid not in Scalene.child_pids
Scalene.add_child_pid(test_pid)
Scalene._add_child_pid(test_pid)
assert test_pid in Scalene.child_pids
Loading