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

Use strings.Cut where possible #4470

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Commits on Nov 7, 2024

  1. exec: use strings.Cut to parse --cgroup

    Using strings.Cut (added in Go 1.18, see [1]) results in faster and
    cleaner code with less allocations (as we're not using a slice).
    
    This part of code is covered by tests in tests/integration/exec.bats.
    
    [1]: golang/go#46336
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    23b5b4a View commit details
    Browse the repository at this point in the history
  2. libct/cg/fs: getPercpuUsage: rm TODO

    Nowadays strings.Fields are as fast as strings.SplitN so remove TODO.
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    c767345 View commit details
    Browse the repository at this point in the history
  3. libct/cg/fs: refactor getCpusetStat

    Using strings.Cut (added in Go 1.18, see [1]) results in faster and
    cleaner code with less allocations (as we're not using a slice). This
    also drops the check for extra dash (we're unlikely to get it from the
    kernel anyway).
    
    While at it, rename min/max -> from/to to avoid collision with Go
    min/max builtins.
    
    This code is tested by TestCPUSetStats* tests.
    
    [1]: golang/go#46336
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    586ce8b View commit details
    Browse the repository at this point in the history
  4. libcontainer/cgroups/fs: some refactoring

    Remove extra global constants that are only used in a single place and
    make it harder to read the code.
    
    Rename nanosecondsInSecond -> nsInSec.
    
    This code is tested by unit tests.
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    c54ae03 View commit details
    Browse the repository at this point in the history
  5. libct/cg/fs2: simplify parseCgroupFromReader

    For cgroup v2, we always expect /proc/$PID/cgroup contents like this:
    
    > 0::/user.slice/user-1000.slice/[email protected]/app.slice/vte-spawn-f71c3fb8-519d-4e2d-b13e-9252594b1e05.scope
    
    So, it does not make sense to parse it using strings.Split, we can just
    cut the prefix and return the rest.
    
    Code tested by TestParseCgroupFromReader.
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    d38a3d5 View commit details
    Browse the repository at this point in the history
  6. libct/cg/fs2: use strings.Cut in setUnified

    Using strings.Cut (added in Go 1.18, see [1]) results in faster and
    cleaner code with less allocations (as we're not using a slice).
    
    The code is tested by testCgroupResourcesUnified.
    
    [1]: golang/go#46336
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    421e97e View commit details
    Browse the repository at this point in the history
  7. libct/cg/fs2: use strings.Cut in parsePSIData

    Using strings.Cut (added in Go 1.18, see [1]) results in faster and
    cleaner code with less allocations (as we're not using a slice).
    
    This code is tested by TestStatCPUPSI.
    
    [1]: golang/go#46336
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    b5d1767 View commit details
    Browse the repository at this point in the history
  8. libct/cg/fscommon: use strings.Cut in RDMA parser

    Using strings.Cut (added in Go 1.18, see [1]) results in faster and
    cleaner code with less allocations (as we're not using a slice).
    
    Also, use switch in parseRdmaKV.
    
    [1]: golang/go#46336
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    9446fc7 View commit details
    Browse the repository at this point in the history
  9. libct/cg/fscommon: use strings.Cut

    Use strings.Cut in ParseKeyValue and GetValueByKey.
    
    Using strings.Cut (added in Go 1.18, see [1]) results in faster and
    cleaner code with less allocations (as we're not using a slice).
    
    [1]: golang/go#46336
    
    Signed-off-by: Kir Kolyshkin <[email protected]>
    kolyshkin committed Nov 7, 2024
    Configuration menu
    Copy the full SHA
    ae23108 View commit details
    Browse the repository at this point in the history