tka: keep the CompactionDefaults alongside the other limits #6
@@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,6 +21,15 @@ import (
|
|||||||
// using os.Executable. If os.Executable fails (it shouldn't), then
|
// using os.Executable. If os.Executable fails (it shouldn't), then
|
||||||
// "cmd" is returned.
|
// "cmd" is returned.
|
||||||
func CmdName() string {
|
func CmdName() string {
|
||||||
|
// On non-Windows, the modinfo embedded in the running binary is
|
||||||
|
// authoritative and avoids re-reading the executable from disk.
|
||||||
|
// Windows needs the executable-name-based GUI override in cmdName,
|
||||||
|
// so it still takes the slower path.
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
if info, ok := debug.ReadBuildInfo(); ok && info.Path != "" {
|
||||||
|
return path.Base(info.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
e, err := os.Executable()
|
e, err := os.Executable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "cmd"
|
return "cmd"
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package version_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"runtime/debug"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
ts "tailscale.com"
|
ts "tailscale.com"
|
||||||
@@ -49,3 +51,21 @@ func TestShortAllocs(t *testing.T) {
|
|||||||
t.Errorf("allocs = %v; want 0", allocs)
|
t.Errorf("allocs = %v; want 0", allocs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkCmdName(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
for b.Loop() {
|
||||||
|
_ = version.CmdName()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkReadBuildInfo(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
for b.Loop() {
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
b.Fatal("ReadBuildInfo failed")
|
||||||
|
}
|
||||||
|
_ = path.Base(info.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user