xinrong-meng commented on code in PR #45129:
URL: https://github.com/apache/spark/pull/45129#discussion_r1493048255
##########
python/pyspark/sql/profiler.py:
##########
@@ -239,3 +241,72 @@ def _profile_results(self) -> "ProfileResults":
with self._lock:
value = self._accumulator.value
return value if value is not None else {}
+
+
+class Profile:
+ """User-facing profile API. This instance can be accessed by
+ :attr:`spark.profile`.
+
+ .. versionadded: 4.0.0
+ """
+
+ def __init__(self, sparkSession: "SparkSession"):
+ self.sparkSession = sparkSession
+
+ def show(self, *, type: Optional[str] = None, id: Optional[int] = None) ->
None:
Review Comment:
Your suggestion makes more sense. Thanks!
##########
python/pyspark/sql/profiler.py:
##########
@@ -239,3 +241,72 @@ def _profile_results(self) -> "ProfileResults":
with self._lock:
value = self._accumulator.value
return value if value is not None else {}
+
+
+class Profile:
+ """User-facing profile API. This instance can be accessed by
+ :attr:`spark.profile`.
+
+ .. versionadded: 4.0.0
+ """
+
+ def __init__(self, sparkSession: "SparkSession"):
+ self.sparkSession = sparkSession
+
+ def show(self, *, type: Optional[str] = None, id: Optional[int] = None) ->
None:
+ """
+ Show the profile results.
+
+ .. versionadded:: 4.0.0
+
+ Parameters
+ ----------
+ type : str, optional
+ The profiler type, which can be either "perf" or "memory".
+ id : int, optional
+ A UDF ID to be shown. If not specified, all the results will be
shown.
+ """
+ if type == "memory":
+ self.sparkSession.showMemoryProfiles(id)
+ elif type == "perf" or type is None:
+ self.sparkSession.showPerfProfiles(id)
+ if type is None: # Show both perf and memory profiles
+ self.sparkSession.showMemoryProfiles(id)
+ else:
+ raise PySparkValueError(
+ error_class="VALUE_NOT_ALLOWED",
+ message_parameters={
+ "arg_name": "type",
+ "allowed_values": str(["perf", "memory"]),
+ },
+ )
+
+ def dump(self, path: str, *, type: Optional[str] = None, id: Optional[int]
= None) -> None:
Review Comment:
Adjusted
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]