mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
Merge pull request #2395 from calmh/printhashrate
Print the single thread hash performance at startup
This commit is contained in:
commit
a7e95922c1
@ -516,6 +516,7 @@ func syncthingMain() {
|
|||||||
|
|
||||||
l.Infoln(LongVersion)
|
l.Infoln(LongVersion)
|
||||||
l.Infoln("My ID:", myID)
|
l.Infoln("My ID:", myID)
|
||||||
|
printHashRate()
|
||||||
|
|
||||||
// Emit the Starting event, now that we know who we are.
|
// Emit the Starting event, now that we know who we are.
|
||||||
|
|
||||||
@ -836,6 +837,22 @@ func syncthingMain() {
|
|||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// printHashRate prints the hashing performance in MB/s, formatting it with
|
||||||
|
// appropriate precision for the value, i.e. 182 MB/s, 18 MB/s, 1.8 MB/s, 0.18
|
||||||
|
// MB/s.
|
||||||
|
func printHashRate() {
|
||||||
|
hashRate := cpuBench(3, 100*time.Millisecond)
|
||||||
|
|
||||||
|
decimals := 0
|
||||||
|
if hashRate < 1 {
|
||||||
|
decimals = 2
|
||||||
|
} else if hashRate < 10 {
|
||||||
|
decimals = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
l.Infof("Single thread hash performance is ~%.*f MB/s", decimals, hashRate)
|
||||||
|
}
|
||||||
|
|
||||||
func loadConfig(cfgFile string) (*config.Wrapper, string, error) {
|
func loadConfig(cfgFile string) (*config.Wrapper, string, error) {
|
||||||
info, err := os.Stat(cfgFile)
|
info, err := os.Stat(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -112,15 +112,7 @@ func reportData(cfg *config.Wrapper, m *model.Model) map[string]interface{} {
|
|||||||
var mem runtime.MemStats
|
var mem runtime.MemStats
|
||||||
runtime.ReadMemStats(&mem)
|
runtime.ReadMemStats(&mem)
|
||||||
res["memoryUsageMiB"] = (mem.Sys - mem.HeapReleased) / 1024 / 1024
|
res["memoryUsageMiB"] = (mem.Sys - mem.HeapReleased) / 1024 / 1024
|
||||||
|
res["sha256Perf"] = cpuBench(5, 125*time.Millisecond)
|
||||||
var perf float64
|
|
||||||
for i := 0; i < 5; i++ {
|
|
||||||
p := cpuBench()
|
|
||||||
if p > perf {
|
|
||||||
perf = p
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res["sha256Perf"] = perf
|
|
||||||
|
|
||||||
bytes, err := memorySize()
|
bytes, err := memorySize()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -301,7 +293,17 @@ func (s *usageReportingService) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
// cpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
|
||||||
func cpuBench() float64 {
|
func cpuBench(iterations int, duration time.Duration) float64 {
|
||||||
|
var perf float64
|
||||||
|
for i := 0; i < iterations; i++ {
|
||||||
|
if v := cpuBenchOnce(duration); v > perf {
|
||||||
|
perf = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return perf
|
||||||
|
}
|
||||||
|
|
||||||
|
func cpuBenchOnce(duration time.Duration) float64 {
|
||||||
chunkSize := 100 * 1 << 10
|
chunkSize := 100 * 1 << 10
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
bs := make([]byte, chunkSize)
|
bs := make([]byte, chunkSize)
|
||||||
@ -309,7 +311,7 @@ func cpuBench() float64 {
|
|||||||
|
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
b := 0
|
b := 0
|
||||||
for time.Since(t0) < 125*time.Millisecond {
|
for time.Since(t0) < duration {
|
||||||
h.Write(bs)
|
h.Write(bs)
|
||||||
b += chunkSize
|
b += chunkSize
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user