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


##########
sdks/python/container/profiler.go:
##########
@@ -334,3 +376,212 @@ 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) {
+       if pcfg.PostprocessIntervalSec <= 0 {
+               return
+       }
+
+       interval := time.Duration(pcfg.PostprocessIntervalSec) * time.Second
+       logger.Printf(ctx, "Monitoring core dumps every %v", interval)
+
+       ticker := time.NewTicker(interval)
+       defer ticker.Stop()
+
+       for {
+               select {
+               case <-ctx.Done():
+                       return
+               case <-ticker.C:
+                       processNewCoredumps(ctx, logger, pcfg)
+                       if isProfilerDisengaged(pcfg) {
+                               return
+                       }
+               }
+       }
+}
+
+func processNewCoredumps(ctx context.Context, logger *tools.Logger, pcfg 
*ProfilerConfig) {
+       profilerMu.Lock()
+       defer profilerMu.Unlock()
+
+       // We expect the runner runtime environment to set the core pattern
+       // to /tmp/beam_coredump.%e.%p or similar. To do that, we pass
+       // the --experiment=core_pattern pipeline option, which can be 
interpreted by a runner.
+       coreDir := "/tmp"
+       files, err := os.ReadDir(coreDir)
+       if err != nil {
+               return
+       }
+
+       prefix := "beam_coredump."
+
+       for _, file := range files {
+               if file.IsDir() {
+                       continue
+               }
+               name := file.Name()
+               if !strings.HasPrefix(name, prefix) {
+                       continue
+               }
+
+               corePath := filepath.Join(coreDir, name)
+               var info os.FileInfo
+               var err error
+
+               for {

Review Comment:
   Should we add a deadline (30s?) that we are willing to wait for one file? 



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