internal/sysinfo: implement CPUName on bsd systems

sysctl machdep.cpu.brand_string seems to be standard
across the BSDs. There does not seem to be a standard
way to get the CPU frequency.

Change-Id: Ic986d6c81dd54e1b84544317f2a53ce16801319b
Reviewed-on: https://go-review.googlesource.com/c/go/+/520636
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Bypass: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Russ Cox 2023-08-17 15:44:20 -04:00
parent 2e1003e2f7
commit ed9aed1c9d
4 changed files with 37 additions and 1 deletions

View file

@ -0,0 +1,14 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || freebsd || netbsd || openbsd
package sysinfo
import "syscall"
func osCpuInfoName() string {
cpu, _ := syscall.Sysctl("machdep.cpu.brand_string")
return cpu
}

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !linux
//go:build !(darwin || freebsd || linux || netbsd || openbsd)
package sysinfo

View file

@ -0,0 +1,7 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sysinfo
var XosCpuInfoName = osCpuInfoName

View file

@ -0,0 +1,15 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sysinfo_test
import (
. "internal/sysinfo"
"testing"
)
func TestCPUName(t *testing.T) {
t.Logf("CPUName: %s", CPUName())
t.Logf("osCpuInfoName: %s", XosCpuInfoName())
}