Skip to content

Commit 0be3fc8

Browse files
committed
Support pystack as profiler agent to collect native stacktraces and core dumps
1 parent 63f1c5e commit 0be3fc8

17 files changed

Lines changed: 179 additions & 0 deletions

sdks/python/apache_beam/options/pipeline_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,10 @@ def validate(self, validator):
17431743
_LOGGER.info(
17441744
'Setting --profile_location to %s since profiling is enabled.',
17451745
self.profile_location)
1746+
1747+
if self.profiler_agent == 'pystack_coredump':
1748+
debug_options = self.view_as(DebugOptions)
1749+
debug_options.add_experiment('core_pattern=/tmp/core.%e.%p')
17461750
return errors
17471751

17481752

sdks/python/apache_beam/options/pipeline_options_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,14 @@ def test_profiling_agent_is_exclusive_with_legacy_profiling_options(self):
686686
self.assertTrue(
687687
any('--profiler_agent is mutually exclusive' in err for err in errors))
688688

689+
def test_profiling_agent_pystack_coredump_adds_core_pattern(self):
690+
options = PipelineOptions(['--profiler_agent=pystack_coredump'])
691+
validator = PipelineOptionsValidator(options, None)
692+
self.assertEqual(validator.validate(), [])
693+
debug_options = options.view_as(DebugOptions)
694+
self.assertEqual(
695+
debug_options.lookup_experiment('core_pattern'), '/tmp/core.%e.%p')
696+
689697
def test_profile_location_defaulting_and_opt_out(self):
690698
options = PipelineOptions(
691699
['--profiler_agent=memray', '--temp_location=gs://bucket/temp'])

sdks/python/container/base_image_requirements_manual.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ guppy3
4242
memray==1.19.3
4343
mmh3 # Optimizes execution of some Beam codepaths. TODO: Make it Beam's dependency.
4444
nltk # Commonly used for natural language processing.
45+
pystack
4546
google-crc32c
4647
scipy
4748
scikit-learn

sdks/python/container/boot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ func launchSDKProcess() error {
365365

366366
logger.Printf(ctx, "Executing Python (%v): %v %v", envStr, currentProg, strings.Join(currentArgs, " "))
367367
cmd := StartCommandEnv(currentEnv, os.Stdin, bufLogger, bufLogger, currentProg, currentArgs...)
368+
logger.Printf(ctx, "Started worker %s with PID %d", workerId, cmd.Process.Pid)
368369
activePids = append(activePids, cmd.Process.Pid)
369370
workerMu.Unlock()
370371

sdks/python/container/ml/py310/base_image_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ PyMySQL==1.2.0
181181
pyOpenSSL==26.2.0
182182
pyparsing==3.3.2
183183
pyproject_hooks==1.2.0
184+
pystack==1.7.0
184185
pytest==9.1.1
185186
pytest-timeout==2.4.0
186187
pytest-xdist==3.8.0

sdks/python/container/ml/py310/gpu_image_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ PyMySQL==1.2.0
256256
pyOpenSSL==26.2.0
257257
pyparsing==3.3.2
258258
pyproject_hooks==1.2.0
259+
pystack==1.7.0
259260
pytest==9.1.1
260261
pytest-timeout==2.4.0
261262
pytest-xdist==3.8.0

sdks/python/container/ml/py311/base_image_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ PyMySQL==1.2.0
180180
pyOpenSSL==26.2.0
181181
pyparsing==3.3.2
182182
pyproject_hooks==1.2.0
183+
pystack==1.7.0
183184
pytest==9.1.1
184185
pytest-timeout==2.4.0
185186
pytest-xdist==3.8.0

sdks/python/container/ml/py311/gpu_image_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ PyMySQL==1.2.0
255255
pyOpenSSL==26.2.0
256256
pyparsing==3.3.2
257257
pyproject_hooks==1.2.0
258+
pystack==1.7.0
258259
pytest==9.1.1
259260
pytest-timeout==2.4.0
260261
pytest-xdist==3.8.0

sdks/python/container/ml/py312/base_image_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ PyMySQL==1.2.0
178178
pyOpenSSL==26.2.0
179179
pyparsing==3.3.2
180180
pyproject_hooks==1.2.0
181+
pystack==1.7.0
181182
pytest==9.1.1
182183
pytest-timeout==2.4.0
183184
pytest-xdist==3.8.0

sdks/python/container/ml/py312/gpu_image_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ PyMySQL==1.2.0
253253
pyOpenSSL==26.2.0
254254
pyparsing==3.3.2
255255
pyproject_hooks==1.2.0
256+
pystack==1.7.0
256257
pytest==9.1.1
257258
pytest-timeout==2.4.0
258259
pytest-xdist==3.8.0

0 commit comments

Comments
 (0)