func()

in sigar_aix.go [292:325]


func (self *CpuList) Get() error {
	cpudata := C.perfstat_cpu_t{}
	id := C.perfstat_id_t{}
	id.name[0] = 0

	// Retrieve the number of cpu using perfstat_cpu
	capacity, err := C.perfstat_cpu(nil, nil, C.sizeof_perfstat_cpu_t, 0)
	if err != nil {
		return fmt.Errorf("error while retrieving CPU number: %s", err)
	}
	list := make([]Cpu, 0, capacity)

	for {
		if _, err := C.perfstat_cpu(&id, &cpudata, C.sizeof_perfstat_cpu_t, 1); err != nil {
			return fmt.Errorf("perfstat_cpu: %s", err)
		}

		cpu := Cpu{}
		cpu.User = tick2msec(uint64(cpudata.user))
		cpu.Sys = tick2msec(uint64(cpudata.sys))
		cpu.Idle = tick2msec(uint64(cpudata.idle))
		cpu.Wait = tick2msec(uint64(cpudata.wait))

		list = append(list, cpu)

		if id.name[0] == 0 {
			break
		}
	}

	self.List = list

	return nil
}