File: mem_aix_cgo.go

package info (click to toggle)
golang-github-shirou-gopsutil 4.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,824 kB
  • sloc: makefile: 76; ansic: 19; sh: 11
file content (51 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix && cgo

package mem

import (
	"context"

	"github.com/power-devops/perfstat"
)

func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
	m, err := perfstat.MemoryTotalStat()
	if err != nil {
		return nil, err
	}
	pagesize := uint64(4096)
	ret := VirtualMemoryStat{
		Total:       uint64(m.RealTotal) * pagesize,
		Available:   uint64(m.RealAvailable) * pagesize,
		Free:        uint64(m.RealFree) * pagesize,
		Used:        uint64(m.RealInUse) * pagesize,
		UsedPercent: 100 * float64(m.RealInUse) / float64(m.RealTotal),
		Active:      uint64(m.VirtualActive) * pagesize,
		SwapTotal:   uint64(m.PgSpTotal) * pagesize,
		SwapFree:    uint64(m.PgSpFree) * pagesize,
	}
	return &ret, nil
}

func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
	m, err := perfstat.MemoryTotalStat()
	if err != nil {
		return nil, err
	}
	pagesize := uint64(4096)
	swapUsed := uint64(m.PgSpTotal-m.PgSpFree-m.PgSpRsvd) * pagesize
	swapTotal := uint64(m.PgSpTotal) * pagesize
	ret := SwapMemoryStat{
		Total:       swapTotal,
		Free:        uint64(m.PgSpFree) * pagesize,
		Used:        swapUsed,
		UsedPercent: float64(100*swapUsed) / float64(swapTotal),
		Sin:         uint64(m.PgSpIn),
		Sout:        uint64(m.PgSpOut),
		PgIn:        uint64(m.PageIn),
		PgOut:       uint64(m.PageOut),
		PgFault:     uint64(m.PageFaults),
	}
	return &ret, nil
}