MCPcopy Index your code
hub / github.com/coder/envbox / readCPUQuotaCGroupV1

Function readCPUQuotaCGroupV1

xunix/sys.go:96–124  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

94}
95
96func readCPUQuotaCGroupV1(ctx context.Context) (CPUQuota, error) {
97 fs := GetFS(ctx)
98 periodRaw, err := afero.ReadFile(fs, CPUPeriodPathCGroupV1)
99 if err != nil {
100 return CPUQuota{}, xerrors.Errorf("read cpu.cfs_period_us outside container: %w", err)
101 }
102
103 quotaRaw, err := afero.ReadFile(fs, CPUQuotaPathCGroupV1)
104 if err != nil {
105 return CPUQuota{}, xerrors.Errorf("read cpu.cfs_quota_us outside container: %w", err)
106 }
107
108 periodStr := string(bytes.TrimSpace(periodRaw))
109 period, err := strconv.Atoi(periodStr)
110 if err != nil {
111 return CPUQuota{}, xerrors.Errorf("period %s not an int: %w", periodStr, err)
112 }
113
114 quotaStr := string(bytes.TrimSpace(quotaRaw))
115 quota, err := strconv.Atoi(quotaStr)
116 if err != nil {
117 return CPUQuota{}, xerrors.Errorf("quota %s not an int: %w", quotaStr, err)
118 }
119
120 return CPUQuota{
121 Quota: quota,
122 Period: period,
123 }, nil
124}
125
126// readCGroup attempts to determine the cgroup for the container by
127// reading the fields of /proc/self/cgroup (third field)

Callers 1

ReadCPUQuotaFunction · 0.85

Calls 2

GetFSFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected