Skip to content

Commit 5d3a28b

Browse files
authoredMar 14, 2025
Correct syscall host logging (#143)
1 parent 74dcd12 commit 5d3a28b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed
 

‎cmd/stat.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ func scanAndStatInput(input, output *os.File, tsvPath string, debug bool, maximu
193193
var statter stat.Statter = stat.WithTimeout(lstatTimeout, lstatAttempts, lstatConsecutiveFails, appLogger)
194194

195195
if recordStats > 0 {
196-
rstatter, err := startSyscallLogging(statter, filepath.Base(input.Name()))
197-
if err != nil {
198-
die("%s", err)
199-
}
200-
196+
rstatter := startSyscallLogging(statter, filepath.Base(input.Name()))
201197
ctx, stop := context.WithCancel(context.Background())
202198

203199
defer rstatter.Start(ctx)()
@@ -216,17 +212,21 @@ func scanAndStatInput(input, output *os.File, tsvPath string, debug bool, maximu
216212
doScanAndStat(statter, pConfig, input, output, tsvPath)
217213
}
218214

219-
func startSyscallLogging(statter stat.Statter, file string) (*stat.StatsRecorder, error) {
215+
func logSyscallHost(file string) error {
220216
host, err := os.Hostname()
221217
if err != nil {
222-
return nil, fmt.Errorf("failed to get hostname: %w", err)
218+
return fmt.Errorf("failed to get hostname: %w", err)
223219
}
224220

225221
appLogger.Info("syscall logging", "host", host, "file", file)
226222

223+
return nil
224+
}
225+
226+
func startSyscallLogging(statter stat.Statter, file string) *stat.StatsRecorder {
227227
return stat.RecordStats(statter, time.Duration(recordStats)*time.Minute, func(t time.Time, u uint64) {
228228
appLogger.Info("syscalls", "time", t, "file", file, "stats", u)
229-
}), nil
229+
})
230230
}
231231

232232
func doScanAndStat(statter stat.Statter, pConfig stat.PathsConfig, input, output *os.File, tsvPath string) {
@@ -242,6 +242,10 @@ func doScanAndStat(statter stat.Statter, pConfig stat.PathsConfig, input, output
242242

243243
logToFile(input.Name() + statLogOutputFileSuffix)
244244

245+
if err := logSyscallHost(input.Name()); err != nil {
246+
die("%s", err)
247+
}
248+
245249
if err := p.Scan(input); err != nil {
246250
die("%s", err)
247251
}

0 commit comments

Comments
 (0)