Skip to content

Commit 55c7094

Browse files
committed
Python profile, show_profiles() and dump_profiles(), should throw an error with a better message
1 parent 73d9067 commit 55c7094

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

python/pyspark/context.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,20 @@ def runJob(self, rdd, partitionFunc, partitions=None, allowLocal=False):
997997

998998
def show_profiles(self):
999999
""" Print the profile stats to stdout """
1000-
self.profiler_collector.show_profiles()
1000+
if self.profiler_collector is not None:
1001+
self.profiler_collector.show_profiles()
1002+
else:
1003+
raise RuntimeError("'spark.python.profile' configuration must be set "
1004+
"to 'true' to enable Python profile.")
10011005

10021006
def dump_profiles(self, path):
10031007
""" Dump the profile stats into directory `path`
10041008
"""
1005-
self.profiler_collector.dump_profiles(path)
1009+
if self.profiler_collector is not None:
1010+
self.profiler_collector.dump_profiles(path)
1011+
else:
1012+
raise RuntimeError("'spark.python.profile' configuration must be set "
1013+
"to 'true' to enable Python profile.")
10061014

10071015
def getConf(self):
10081016
conf = SparkConf()

python/pyspark/tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,22 @@ def heavy_foo(x):
12841284
rdd.foreach(heavy_foo)
12851285

12861286

1287+
class ProfilerTests2(unittest.TestCase):
1288+
def test_profiler_disabled(self):
1289+
sc = SparkContext(conf=SparkConf().set("spark.python.profile", "false"))
1290+
try:
1291+
self.assertRaisesRegexp(
1292+
RuntimeError,
1293+
"'spark.python.profile' configuration must be set",
1294+
lambda: sc.show_profiles())
1295+
self.assertRaisesRegexp(
1296+
RuntimeError,
1297+
"'spark.python.profile' configuration must be set",
1298+
lambda: sc.dump_profiles("/tmp/abc"))
1299+
finally:
1300+
sc.stop()
1301+
1302+
12871303
class InputFormatTests(ReusedPySparkTestCase):
12881304

12891305
@classmethod

0 commit comments

Comments
 (0)