-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Assorted minor nits in libcontainer #2263
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
Conversation
fmt.Sprintf is slow and is not needed here, string concatenation would be sufficient. It is also redundant to convert []byte from string and back, since `bytes` package now provides the same functions as `strings`. Use Fields() instead of TrimSpace() and Split(), mainly for readability (note Fields() is somewhat slower than Split() but here it doesn't matter much). Use Join() to prepend the plus signs. Signed-off-by: Kir Kolyshkin <[email protected]>
1. Return earlier if there is an error. 2. Do not use filepath.Split on every entry, use info.Name() instead. 3. Make readProcsFile() accept file name as an argument, to avoid unnecessary file name and directory splitting and merging. 4. Skip on info.IsDir() -- this avoids an error when cgroup name is set to "cgroup.procs". This is still not very good since filepath.Walk() performs an unnecessary stat(2) on every entry, but better than before. Signed-off-by: Kir Kolyshkin <[email protected]>
It it not needed as it does nothing here. Signed-off-by: Kir Kolyshkin <[email protected]>
| } | ||
| resByte := []byte(res) | ||
| ctrs := bytes.Fields(content) | ||
| res := append([]byte("+"), bytes.Join(ctrs, []byte(" +"))...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giuseppe PTAL
| if info.IsDir() || info.Name() != CgroupProcesses { | ||
| return nil | ||
| } | ||
| cPids, err := readProcsFile(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous change to this code was in #332
| // GetPids returns all pids, that were added to cgroup at path. | ||
| func GetPids(path string) ([]int, error) { | ||
| return readProcsFile(path) | ||
| func GetPids(dir string) ([]int, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaks compatibility if there is non-runc consumer of this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope (I just changed the name of the parameter to be clear it's a directory, otherwise it's doing the same thing).
Please see the individual commits for details.