spark icon indicating copy to clipboard operation
spark copied to clipboard

[SPARK-47069][PYTHON][CONNECT] Introduce `spark.profile.show/dump` for SparkSession-based profiling

Open xinrong-meng opened this issue 1 year ago • 1 comments

What changes were proposed in this pull request?

Introduce spark.profile.show/dump for SparkSession-based profiling for non-Spark-Connect.

Why are the changes needed?

SparkContext-based profiling has sc.dump_profiles/show_profiles for both perf and memory profiling. Currently SparkSession-based has spark.dump/showPerfProfiles and spark.dump/showMemoryProfiles for perf and memory profiling separately. It would be more consistent and user-friendly to consolidate them to a uniform interface as spark.profile.dump/show.

Does this PR introduce any user-facing change?

Yes. spark.profile.show/dump is supported, whereas (not-released yet) APIs below are removed -spark.dumpPerfProfiles -spark.dumpMemoryProfiles -spark.showPerfProfiles -spark.showMemoryProfiles

>>> spark.conf.set("spark.sql.pyspark.udf.profiler", "perf")  # enable cProfiler
>>> 
>>> @udf("string")
... def f(x):
...       return str(x)
... 
>>> df = spark.range(10).select(f(col("id")))
>>> df.collect()
[Row(f(id)='0'), ...]
>>> spark.profile.show()
============================================================
Profile of UDF<id=2>
============================================================
...

>>> spark.profile.show(type="memory")
>>> spark.profile.show(type="perf")
============================================================
Profile of UDF<id=2>
============================================================
...

>>> spark.profile.show(2, type="perf")
============================================================
Profile of UDF<id=2>
============================================================
...

>>> spark.profile.show(2, type="memory")

How was this patch tested?

Unit tests.

Was this patch authored or co-authored using generative AI tooling?

No.

xinrong-meng avatar Feb 15 '24 23:02 xinrong-meng

Adjusted PR description.

xinrong-meng avatar Feb 17 '24 00:02 xinrong-meng

Had to rebase the master change, the latest changes after review are ad98eb3 and 46118f9.

xinrong-meng avatar Feb 20 '24 18:02 xinrong-meng

Thanks! merging to master.

ueshin avatar Feb 22 '24 19:02 ueshin

Thank you!

xinrong-meng avatar Feb 23 '24 01:02 xinrong-meng