Skip to content

[SPARK-51087][PYTHON][CONNECT] Raise a warning when memory-profiler is not installed for memory profiling #49797

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

Closed
Closed
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
21 changes: 20 additions & 1 deletion python/pyspark/sql/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pstats
from threading import RLock
from typing import Any, Callable, Dict, Literal, Optional, Tuple, Union, TYPE_CHECKING, overload
import warnings

from pyspark.accumulators import (
Accumulator,
Expand All @@ -28,7 +29,13 @@
_accumulatorRegistry,
)
from pyspark.errors import PySparkValueError
from pyspark.profiler import CodeMapDict, MemoryProfiler, MemUsageParam, PStatsParam
from pyspark.profiler import (
CodeMapDict,
MemoryProfiler,
MemUsageParam,
PStatsParam,
has_memory_profiler,
)

if TYPE_CHECKING:
from pyspark.sql._typing import ProfileResults
Expand Down Expand Up @@ -130,6 +137,12 @@ def show_memory_profiles(self, id: Optional[int] = None) -> None:
with self._lock:
code_map = self._memory_profile_results

if not has_memory_profiler and not code_map:
warnings.warn(
"Install the 'memory_profiler' library in the cluster to enable memory profiling",
UserWarning,
)

def show(id: int) -> None:
cm = code_map.get(id)
if cm is not None:
Expand Down Expand Up @@ -208,6 +221,12 @@ def dump_memory_profiles(self, path: str, id: Optional[int] = None) -> None:
with self._lock:
code_map = self._memory_profile_results

if not has_memory_profiler and not code_map:
warnings.warn(
"Install the 'memory_profiler' library in the cluster to enable memory profiling",
UserWarning,
)

def dump(id: int) -> None:
cm = code_map.get(id)

Expand Down