Skip to content

Commit e346005

Browse files
committed
Terminate postprocessing after profiler was disengaged.
1 parent db6f284 commit e346005

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

sdks/python/container/profiler.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func startProfilerBackgroundTasks(ctx context.Context, logger *tools.Logger) {
146146
}
147147

148148
if pcfg.Agent == "memray" {
149-
go postProcessProfilesLoop(ctx, logger, pcfg.TempLocation, pcfg.PostprocessIntervalSec)
149+
go postProcessProfilesLoop(ctx, logger, pcfg)
150150
}
151151

152152
if pcfg.Agent == "pystack_coredump" {
@@ -257,18 +257,22 @@ func syncProfilesToGCS(ctx context.Context, logger *tools.Logger, localDir, gcsD
257257
}
258258

259259
// postProcessProfilesLoop runs a background loop that periodically triggers profile post-processing if enabled.
260-
func postProcessProfilesLoop(ctx context.Context, logger *tools.Logger, profilesDir string, intervalSec int) {
261-
if intervalSec <= 0 {
260+
func postProcessProfilesLoop(ctx context.Context, logger *tools.Logger, pcfg *ProfilerConfig) {
261+
if pcfg.PostprocessIntervalSec <= 0 {
262262
return
263263
}
264264

265265
for {
266-
runPostProcessingSweep(ctx, logger, profilesDir, intervalSec)
266+
runPostProcessingSweep(ctx, logger, pcfg.TempLocation, pcfg.PostprocessIntervalSec)
267+
268+
if isProfilerDisengaged(pcfg) {
269+
return
270+
}
267271

268272
select {
269273
case <-ctx.Done():
270274
return
271-
case <-time.After(time.Duration(intervalSec) * time.Second):
275+
case <-time.After(time.Duration(pcfg.PostprocessIntervalSec) * time.Second):
272276
// Block until the sleep completes before starting the next sweep
273277
}
274278
}

0 commit comments

Comments
 (0)