-
Notifications
You must be signed in to change notification settings - Fork 950
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
Duplicate and unnecessary system call in pkg/kernel/GetVersionInfo() #2459
Comments
Good idea, you may assume that kernel version is fixed for most cases, but for kexec? Since kexec can be dynamically switch the kernel version :-) |
@houstar |
This is trade-off problem 👍 Let's the architects make the decision. If plan to merge, add this kexec problem as Limitation 💯 |
I'm totally agree with you @HusterWan since this is trade-off problem and add kexec as limitation. |
have you compare it with package main
import (
"fmt"
"syscall"
)
func main() {
err := syscall.Uname(&buf)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(charsToString(buf.Release[:]))
}
func charsToString(ca []int8) string {
s := make([]byte, len(ca))
var lens int
for ; lens < len(ca); lens++ {
if ca[lens] == 0 {
break
}
s[lens] = uint8(ca[lens])
}
return string(s[0:lens])
} $ root@pouch:~/go/src/github.com/t# go build main.go
$ root@pouch:~/go/src/github.com/t# ./main
4.4.0-137-generic What's the performance of this one? |
@zhuangqh I've just tried a simple test, use |
@zhuangqh here is my code: func GetKernelVersionByUnix() (*VersionInfo, error) {
var (
kernel, major, minor int
flavor string
)
buf := unix.Utsname{}
err := unix.Uname(&buf)
if err != nil {
return nil, err
}
release := string(buf.Release[:])
parsed, _ := fmt.Sscanf(release, "%d.%d.%d-%s", &kernel, &major, &minor, &flavor)
if parsed < 3 {
return nil, fmt.Errorf("Can't parse kernel version, release: %s" + release)
}
return &VersionInfo{
Kernel: kernel,
Major: major,
Minor: minor,
Flavor: flavor,
}, nil
} |
good job! Could you submit a pull request? |
bench in multi-implementation === RUN TestGetKernelVersion Codes: |
Ⅰ. Issue Description
as the image (perf record to flame graph) below, i found a CPU hot point in the pkg/kernel/GetVersionInfo().
this method may only need to be called once, because the kernel version is fixed after the system is up. ?
Ⅱ. Describe what happened
Ⅲ. Describe what you expected to happen
Ⅳ. How to reproduce it (as minimally and precisely as possible)
Ⅴ. Anything else we need to know?
Ⅵ. Environment:
pouch version
): 1.0.0uname -a
):The text was updated successfully, but these errors were encountered: