tvalentyn commented on code in PR #39484:
URL: https://github.com/apache/beam/pull/39484#discussion_r3683094342


##########
sdks/python/container/profiler.go:
##########
@@ -334,3 +354,185 @@ func needsProcessing(binInfo os.FileInfo, path string) 
bool {
        // Don't regenerate when there were no updates to the profile.
        return binInfo.ModTime().After(info.ModTime())
 }
+
+func monitorCoredumpsLoop(ctx context.Context, logger *tools.Logger, pcfg 
*ProfilerConfig) {
+       // We require the core file pattern to be configured as 
"/tmp/core.%e.%p" via pipeline
+       // options experiments (which is automatically set by the Python SDK). 
This ensures
+       // that core dumps are written in /tmp/ with a prefix matching "core.".
+       coreDir := "/tmp"
+       interval := 5 * time.Second
+       if pcfg.PostprocessIntervalSec > 0 {
+               interval = time.Duration(pcfg.PostprocessIntervalSec) * 
time.Second
+       }
+       logger.Printf(ctx, "Monitoring directory %s for core dumps matching 
prefix core. every %v", coreDir, interval)
+
+       ticker := time.NewTicker(interval)
+       defer ticker.Stop()
+
+       for {
+               select {
+               case <-ctx.Done():
+                       return
+               case <-ticker.C:
+                       processNewCoredumps(ctx, logger, pcfg, coreDir)
+                       if isProfilerDisengaged(pcfg) {
+                               return
+                       }
+               }
+       }
+}
+
+func processNewCoredumps(ctx context.Context, logger *tools.Logger, pcfg 
*ProfilerConfig, coreDir string) {
+       files, err := os.ReadDir(coreDir)
+       if err != nil {
+               return
+       }
+
+       prefix := "core."

Review Comment:
   good point, fortunately we control the pattern, so we can specify a more 
unique prefix. beam_py_coredump perhaps.



-- 
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]

Reply via email to