Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemInfo ¶
type MemInfo struct {
Total uint64 // 总内存(字节)
Available uint64 // 可用内存(字节)
Used uint64 // 已用内存(字节)
}
MemInfo 包含系统内存信息
func GetMemInfo ¶
GetMemInfo 获取系统内存信息
Example ¶
ExampleGetMemInfo 展示如何使用GetMemInfo函数
memInfo, err := GetMemInfo()
if err != nil {
fmt.Printf("获取内存信息失败: %v\n", err)
return
}
// 计算内存使用率
usagePercent := float64(memInfo.Used) / float64(memInfo.Total) * 100
fmt.Printf("总内存: %d MB\n", memInfo.Total/1024/1024)
fmt.Printf("已用内存: %d MB\n", memInfo.Used/1024/1024)
fmt.Printf("可用内存: %d MB\n", memInfo.Available/1024/1024)
fmt.Printf("内存使用率: %.2f%%\n", usagePercent)
// 输出不确定,所以不做验证
Click to show internal directories.
Click to hide internal directories.