Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS M1] Backports from upstream to fix cpu.Info() crashes #43

Merged
merged 2 commits into from
Sep 1, 2022

Conversation

KSerrania
Copy link

Since #40, we can build projects containing this gopsutil fork on macOS M1.

However, using cpu.Info() causes a crash: sysctl hw.cpufrequency doesn't return anything on M1, which makes the following snippet crash:

out, err = invoke.Command(sysctl, "hw.cpufrequency")
	if err != nil {
		return ret, err
	}

	values := strings.Fields(string(out))
	hz, err := strconv.ParseFloat(values[1], 64)

with an index out-of-range error.

This PR:

The drawback of this approach is that the CPU frequency won't be available on M1, but according to the discussions in shirou#1000 and giampaolo/psutil#1892, no definitive solution to this issue has been found yet.

Lomanic and others added 2 commits August 13, 2022 23:23
Backport of the fix of shirou#639.

Manual use of sysctl results in crashes on macOS M1 due to sysctl hw.cpufrequency
returning an empty result, which was then unsafely parsed.
Backport of shirou#1192.

sysctl hw.cpufrequency does not return anything on macOS M1. This causes cpu.Info()
to return an error every time it is called on macOS M1.

A partial fix of this issue is to ignore errors, and leave the frequency field with
its default value.
@KSerrania KSerrania merged commit 797e67f into dd Sep 1, 2022
KSerrania added a commit to DataDog/datadog-agent that referenced this pull request Sep 2, 2022
Follow-up of #12627
Updates github.com/DataDog/gopsutil to v1.2.1 to include DataDog/gopsutil#43, which fixes a crash when using cpu.Info() on macOS M1. This was causing crashes in the process-agent (see #12627 comments).
@brycekahle brycekahle deleted the kserrania/fix-cpu-m1 branch January 18, 2024 18:41
@brycekahle brycekahle added backport Change is backported from upstream or has an equivalent upstreamed change has been merged upstream labels Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Change is backported from upstream or has an equivalent upstreamed change has been merged upstream
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants