github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fs/proc/loadavg.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package proc 16 17 import ( 18 "bytes" 19 "fmt" 20 21 "github.com/SagerNet/gvisor/pkg/context" 22 "github.com/SagerNet/gvisor/pkg/sentry/fs/proc/seqfile" 23 ) 24 25 // LINT.IfChange 26 27 // loadavgData backs /proc/loadavg. 28 // 29 // +stateify savable 30 type loadavgData struct{} 31 32 // NeedsUpdate implements seqfile.SeqSource.NeedsUpdate. 33 func (*loadavgData) NeedsUpdate(generation int64) bool { 34 return true 35 } 36 37 // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. 38 func (d *loadavgData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { 39 if h != nil { 40 return nil, 0 41 } 42 43 var buf bytes.Buffer 44 45 // TODO(b/62345059): Include real data in fields. 46 // Column 1-3: CPU and IO utilization of the last 1, 5, and 10 minute periods. 47 // Column 4-5: currently running processes and the total number of processes. 48 // Column 6: the last process ID used. 49 fmt.Fprintf(&buf, "%.2f %.2f %.2f %d/%d %d\n", 0.00, 0.00, 0.00, 0, 0, 0) 50 51 return []seqfile.SeqData{ 52 { 53 Buf: buf.Bytes(), 54 Handle: (*loadavgData)(nil), 55 }, 56 }, 0 57 } 58 59 // LINT.ThenChange(../../fsimpl/proc/tasks_files.go)