github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/internal/sysinfo/sysinfo.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package sysinfo implements high level hardware information gathering 6 // that can be used for debugging or information purposes. 7 package sysinfo 8 9 import ( 10 "internal/cpu" 11 "sync" 12 ) 13 14 var cpuInfo struct { 15 once sync.Once 16 name string 17 } 18 19 func CPUName() string { 20 cpuInfo.once.Do(func() { 21 // Try to get the information from internal/cpu. 22 if name := cpu.Name(); name != "" { 23 cpuInfo.name = name 24 return 25 } 26 27 // TODO(martisch): use /proc/cpuinfo and /sys/devices/system/cpu/ on Linux as fallback. 28 if name := osCpuInfoName(); name != "" { 29 cpuInfo.name = name 30 return 31 } 32 }) 33 34 return cpuInfo.name 35 }