Debian Codegraph @

internal/cgroups/cgroup.go

raw symbols SCIP
1 // Copyright (c) 2017 Uber Technologies, Inc.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20
21 //go:build linux
22 // +build linux
23
24 package cgroupsscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/
25
26 import (
27 "bufioscip-go gomod github.com/golang/go/src go1.18 bufio/"
28 "ioscip-go gomod github.com/golang/go/src go1.18 io/"
29 "osscip-go gomod github.com/golang/go/src go1.18 os/"
30 "path/filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/"
31 "strconvscip-go gomod github.com/golang/go/src go1.18 strconv/"
32 )
33
34 // CGroup represents the data structure for a Linux control group.
35 type CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup# struct {
36 pathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#path. string
37 }
38
39 // NewCGroup returns a new *CGroup from a given path.
40 func NewCGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/NewCGroup().(path string) *CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup# {
41 return &CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#{pathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#path.: path}
42 }
43
44 // Path returns the path of the CGroup*.
45 func (cg *CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#) Pathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#Path().() string {
46 return cg.pathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#path.
47 }
48
49 // ParamPath returns the path of the given cgroup param under itself.
50 func (cg *CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#) ParamPathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#ParamPath().(param string) string {
51 return filepathscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.18 `path/filepath`/Join().(cg.pathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#path., param)
52 }
53
54 // readFirstLine reads the first line from a cgroup param file.
55 func (cg *CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#) readFirstLinescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#readFirstLine().(param string) (string, error) {
56 paramFile, err := osscip-go gomod github.com/golang/go/src go1.18 os/.Openscip-go gomod github.com/golang/go/src go1.18 os/Open().(cg.ParamPathscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#ParamPath().(param))
57 if err != nil {
58 return "", err
59 }
60 defer paramFile.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().()
61
62 scanner := bufioscip-go gomod github.com/golang/go/src go1.18 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.18 bufio/NewScanner().(paramFile)
63 if scanner.Scanscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Scan().() {
64 return scanner.Textscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Text().(), nil
65 }
66 if err := scanner.Errscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Err().(); err != nil {
67 return "", err
68 }
69 return "", ioscip-go gomod github.com/golang/go/src go1.18 io/.ErrUnexpectedEOFscip-go gomod github.com/golang/go/src go1.18 io/ErrUnexpectedEOF.
70 }
71
72 // readInt parses the first line from a cgroup param file as int.
73 func (cg *CGroupscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#) readIntscip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#readInt().(param string) (int, error) {
74 text, err := cg.readFirstLinescip-go gomod go.uber.org/automaxprocs . `go.uber.org/automaxprocs/internal/cgroups`/CGroup#readFirstLine().(param)
75 if err != nil {
76 return 0, err
77 }
78 return strconvscip-go gomod github.com/golang/go/src go1.18 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.18 strconv/Atoi().(text)
79 }