Skip to content

Commit

Permalink
Merge pull request #199 from intel/perfeventwait
Browse files Browse the repository at this point in the history
process last set of events consistently
  • Loading branch information
harp-intel authored Feb 7, 2025
2 parents c4f2157 + 6dfd305 commit 4a9d62c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ func runPerf(myTarget target.Target, noRoot bool, processes []Process, cmd *exec
// The timer will expire when no lines (events) have been received from perf for more than 100ms. This
// works because perf writes the events to stderr in a burst every collection interval, e.g., 5 seconds.
// When the timer expires, this code assumes that perf is done writing events to stderr.
perfEventWaitTime := time.Duration(100 * time.Millisecond) // 100ms is somewhat arbitrary, but is long enough for perf to print a frame of events
// The first duration needs to be longer than the time it takes for perf to print its first line of output.
t1 := time.NewTimer(time.Duration(2 * flagPerfPrintInterval * 1000))
var frameTimestamp float64
Expand Down Expand Up @@ -1291,10 +1292,11 @@ func runPerf(myTarget target.Target, noRoot bool, processes []Process, cmd *exec
done = true // exit the loop
case exitCode := <-exitcodeChannel: // when perf exits, the exit code comes to this channel
slog.Debug("perf exited", slog.Int("exit code", exitCode))
done = true // exit the loop
time.Sleep(perfEventWaitTime) // wait for timer to expire so that last events can be processed
done = true // exit the loop
case line := <-stderrChannel: // perf output comes in on this channel, one line at a time
t1.Stop()
t1.Reset(100 * time.Millisecond) // 100ms is somewhat arbitrary, but seems to work
t1.Reset(perfEventWaitTime)
// accumulate the lines, they will be processed in the goroutine when the timer expires
outputLines = append(outputLines, []byte(line))
}
Expand Down

0 comments on commit 4a9d62c

Please sign in to comment.