storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/sys/stats_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 /* 5 * MinIO Cloud Storage, (C) 2016,2017 MinIO, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package sys 21 22 import ( 23 "syscall" 24 "unsafe" 25 26 "golang.org/x/sys/windows" 27 ) 28 29 var ( 30 modkernel32 = windows.NewLazySystemDLL("kernel32.dll") 31 procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx") 32 ) 33 34 type memoryStatusEx struct { 35 cbSize uint32 36 dwMemoryLoad uint32 37 ullTotalPhys uint64 // in bytes 38 ullAvailPhys uint64 39 ullTotalPageFile uint64 40 ullAvailPageFile uint64 41 ullTotalVirtual uint64 42 ullAvailVirtual uint64 43 ullAvailExtendedVirtual uint64 44 } 45 46 // GetStats - return system statistics for windows. 47 func GetStats() (stats Stats, err error) { 48 var memInfo memoryStatusEx 49 memInfo.cbSize = uint32(unsafe.Sizeof(memInfo)) 50 if mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo))); mem == 0 { 51 err = syscall.GetLastError() 52 } else { 53 stats.TotalRAM = memInfo.ullTotalPhys 54 } 55 56 return stats, err 57 }