Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {

c := InfoStat{CPU: -1, Cores: 1}
for _, line := range lines {
fields := strings.Split(line, ":")
fields := strings.SplitN(line, ":", 2)
if len(fields) < 2 {
continue
}
Expand Down Expand Up @@ -476,7 +476,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
currentInfo = make(map[string]int)
continue
}
fields := strings.Split(line, ":")
fields := strings.SplitN(line, ":", 2)
if len(fields) < 2 {
continue
}
Expand Down
11 changes: 11 additions & 0 deletions cpu/cpu_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ func TestCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/shirou/
expected := 8
assert.Equalf(t, expected, count, "expected %v, got %v", expected, count)
}

func TestCPUInfoModelNameWithColon_1958(t *testing.T) { // https://github.com/shirou/gopsutil/issues/1958
t.Setenv("HOST_PROC", "testdata/linux/1958/proc")

info, err := Info()
require.NoError(t, err)
require.Len(t, info, 1)

expected := "Hygon C86-4G (OPN:5435)"
assert.Equalf(t, expected, info[0].ModelName, "expected %v, got %v", expected, info[0].ModelName)
}
21 changes: 21 additions & 0 deletions cpu/testdata/linux/1958/proc/cpuinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
processor : 0
vendor_id : HygonGenuine
cpu family : 24
model : 6
model name : Hygon C86-4G (OPN:5435)
stepping : 1
microcode : 0x90610009
cpu MHz : 2799.751
cache size : 512 KB
physical id : 0
siblings : 32
core id : 0
cpu cores : 16
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 16
wp : yes
flags : fpu vme de pse
bogomips : 5599.50