github.com/livekit/protocol@v1.39.3/utils/hwstats/memory.go (about) 1 // Copyright 2023 LiveKit, Inc. 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 hwstats 16 17 // This object returns cgroup quota aware memory stats. On other systems than Linux, 18 // it falls back to full system stats 19 20 type platformMemoryGetter interface { 21 getMemory() (uint64, uint64, error) 22 } 23 24 type MemoryStats struct { 25 platform platformMemoryGetter 26 } 27 28 func NewMemoryStats() (*MemoryStats, error) { 29 p, err := newPlatformMemoryGetter() 30 if err != nil { 31 return nil, err 32 } 33 34 return &MemoryStats{ 35 platform: p, 36 }, nil 37 } 38 39 func (m *MemoryStats) GetMemory() (uint64, uint64, error) { 40 return m.platform.getMemory() 41 }