shirou / gopsutil

psutil for golang
Other
10.56k stars 1.58k forks source link

start to using CGO on cpu/cpu_darwin #66

Open shirou opened 9 years ago

shirou commented 9 years ago

I know there are many people who want to get CPUTimes on darwin using CGO. I had rejected because of easy cross-compiling. I had wrote using helper process. But yes, this is bad approach. And I think there is no way to get host_processer_info from pure Go because this is belongs to Mach part of darwin.

So, now, I have changed my mind.

Since 47f6760cf36f1ee42b4adf32a201835eb5c2ae57, cpu_darwin uses CGO. Current code is borrowed from influxdb/telegraf. Thank you using gopsutil!)

If someone want to remove CGO dependency, please write comments for this issue. I will remove quickly.

I always grateful to such a many people using, discussing, and contributing gopsutil.

reference

vrecan commented 9 years ago

:+1:

dadgar commented 9 years ago

I would prefer this removed because as you said it makes cross compiling difficult. Using tools like gox is much harder with this now.

shirou commented 9 years ago

@dadgar thank you for the :-1:

I have an idea about to use a build tag to easy cross compiling. It means, make two kind of files about darwin.

If you want to cross compile (and can accept could not get CPUTimes on darwin), type go build -tags=cross. Then, cpu_darwin_cross.go is used for cross-compile.

How do you feel it? Thank you.

dadgar commented 9 years ago

Yeah I like your thinking. You could probably use the cgo tag right? `

shirou commented 9 years ago

Ah! cgo build tag is the right way. Totaly agree. I made a PR #89. could you check it out?

Comdex commented 8 years ago

Let user to choose use cgo or not when compile the code is a good idea

shirou commented 8 years ago

@Comdex You can change CGO_ENABLE environment variable.

jesse-c commented 7 years ago

Quick tip for anyone wondering, it's CGO_ENABLED. See: https://golang.org/cmd/cgo/.