After statKind (e3ab7f3bf), os.Stat was still a fifth of what forty /api/drift asks allocated with real accounts: Agent.Detected's look at the agent's file, bundleInfo's and folderSubs' size-and-time stamps for every desktop app, and qoderApp's status files. Each os.Stat makes an os.FileInfo on the heap. They now go through the system call into a Stat_t on the stack: - Detected: statKind (exists, followed through links, as os.Stat). - qoderApp: statFile, a regular file as Mode().IsRegular() says. - bundleInfo, folderSubs: statStamp, mtime and size as ModTime/Size say (Mtimespec on darwin, Mtim on linux; os.Stat elsewhere). Windows and other systems keep os.Stat. Run (at this tree): - mote: go test -count=1 ./internal/agent ok (518s, load high after a reboot); go vet darwin; linux and windows vet clean - wsl-run (Linux): TestStatStamp|TestStatKind|TestQoder ok - win-run (Windows): same set; TestQoderSettingsFromAnIDEPluginIsNotTheCLI red, and red the same on origin/main783cd0f84(#1827: the fixture is an extensionless #!/bin/sh on PATH); the rest ok - TestStatStampAndFileSayWhatStatSays compares with os.Stat for a file, a folder, a link, a gone path and a path under a file; with darwin's statStamp put back on os.Stat by hand it is red (3 allocations for two looks), restored - Real accounts (sandbox HOME copy), 40 /api/drift calls, paired runs: os.Stat 2.0/3.1 MB before, 1.5/0 MB after (left: pencilApp, a glob, provider.stampOf); totals 20.2/19.1 MB before, 18.5/17.5 MB after.
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
//go:build unix
|
|
|
|
package agent
|
|
|
|
import "syscall"
|
|
|
|
// statKind is what is at p, following links, as os.Stat's IsDir would say,
|
|
// without the os.FileInfo os.Stat makes on the heap: detection asks it of
|
|
// some thousand paths on each of the window's 15s drift asks, and the
|
|
// FileInfos were a fifth of what forty asks allocated with real accounts.
|
|
func statKind(p string) (dir, ok bool) {
|
|
var st syscall.Stat_t
|
|
if !statInto(p, &st) {
|
|
return false, false
|
|
}
|
|
return uint32(st.Mode)&syscall.S_IFMT == syscall.S_IFDIR, true
|
|
}
|
|
|
|
// statFile is whether p, links followed, is a regular file, as os.Stat's
|
|
// Mode().IsRegular() would say.
|
|
func statFile(p string) bool {
|
|
var st syscall.Stat_t
|
|
return statInto(p, &st) && uint32(st.Mode)&syscall.S_IFMT == syscall.S_IFREG
|
|
}
|
|
|
|
// statInto is syscall.Stat of p into st, tried again when a signal cuts
|
|
// it short, as os.Stat is.
|
|
func statInto(p string, st *syscall.Stat_t) bool {
|
|
for {
|
|
err := syscall.Stat(p, st)
|
|
if err == syscall.EINTR {
|
|
continue
|
|
}
|
|
return err == nil
|
|
}
|
|
}
|