예제 #1
0
파일: ps.go 프로젝트: chen0031/sigar
func GetAllProcInfos(infoTypesMask ProcInfoType) (processes *ProcessInfoList, err error) {

	var procList C.sigar_proc_list_t
	defer util.Panic2Error(&err)
	defer C.sigar_proc_list_destroy(sigar, &procList)

	sigar := GetSigarHandle()

	C.sigar_proc_list_get(sigar, &procList)

	return getProcInfos(&procList, infoTypesMask, sigar)
}
예제 #2
0
파일: ptql.go 프로젝트: huayueh/sigar
func ExecutePtql(ptql string, infoTypesMask ProcInfoType) (result []*ProcessInfo, err error) {
	defer util.Panic2Error(&err)

	var query *C.sigar_ptql_query_t
	var queryError *C.sigar_ptql_error_t
	var proclist C.sigar_proc_list_t

	sigar := GetSigarHandle()
	ptqlC := C.CString(ptql)
	//defer C.sigar_ptql_query_destroy(query)
	defer C.sigar_proc_list_destroy(sigar, &proclist)
	defer C.sigar_ptql_re_impl_set(sigar, nil, nil)
	defer Free(ptqlC)

	if status := C.sigar_ptql_query_create(&query, ptqlC, queryError); status != SIGAR_OK {
		err = fmt.Errorf("Failed to create sigar ptql query for: %v with errorcode: %v", ptql, status)
		return nil, err
	}

	C.sigar_ptql_query_find(sigar, query, &proclist)
	C.sigar_ptql_query_destroy(query)

	/*
		noOfProcesses := int(proclist.number)
		result = make([]*ProcessInfo, noOfProcesses)
		pids :=  *(*[]C.sigar_pid_t) (CArr2SlicePtr(noOfProcesses, proclist.data))
		for i,pid := range pids {
			procInfo,err := GetProcInfo(uint64(pid), infoTypesMask)
			if err != nil {
				return nil,err
			}
			result[i] =  procInfo
		}

		return result,nil*/

	processes, err := getProcInfos(&proclist, infoTypesMask, sigar)
	return processes.Processes, err
}
예제 #3
0
파일: ps.go 프로젝트: chen0031/sigar
func Ps() ([]C.sigar_proc_state_t,
	[]C.sigar_proc_time_t,
	[]C.sigar_proc_mem_t,
	[]C.sigar_proc_disk_io_t,
	[]C.sigar_proc_cumulative_disk_io_t,
	[]C.sigar_proc_cred_t,
	[]C.sigar_proc_cred_name_t,
	[]C.sigar_proc_cpu_t,
	[]C.sigar_proc_args_t,
	[]C.sigar_proc_fd_t,
	[]C.sigar_proc_exe_t) {

	sigar := GetSigarHandle()

	var procList C.sigar_proc_list_t

	C.sigar_proc_list_get(sigar, &procList)
	var length int = int(procList.number)

	var pstate = make([]C.sigar_proc_state_t, length)
	var ptime = make([]C.sigar_proc_time_t, length)
	var pmem = make([]C.sigar_proc_mem_t, length)
	var pdiskio = make([]C.sigar_proc_disk_io_t, length)
	var pcumdiskio = make([]C.sigar_proc_cumulative_disk_io_t, length)
	var pcred = make([]C.sigar_proc_cred_t, length)
	var pcredname = make([]C.sigar_proc_cred_name_t, length)
	var pcpu = make([]C.sigar_proc_cpu_t, length)
	var pargs = make([]C.sigar_proc_args_t, length)
	var pfd = make([]C.sigar_proc_fd_t, length)
	var pexe = make([]C.sigar_proc_exe_t, length)

	cpid := GetGoSlice(length, unsafe.Pointer(procList.data))
	var goPid []C.sigar_pid_t
	goPid = *(*[]C.sigar_pid_t)(unsafe.Pointer(&cpid))

	for i := 0; i < length; i++ {

		C.sigar_proc_state_get(sigar, goPid[i], &pstate[i])
		C.sigar_proc_time_get(sigar, goPid[i], &ptime[i])
		C.sigar_proc_mem_get(sigar, goPid[i], &pmem[i])
		C.sigar_proc_disk_io_get(sigar, goPid[i], &pdiskio[i])
		C.sigar_proc_cumulative_disk_io_get(sigar, goPid[i], &pcumdiskio[i])
		C.sigar_proc_cred_get(sigar, goPid[i], &pcred[i])
		C.sigar_proc_cred_name_get(sigar, goPid[i], &pcredname[i])
		C.sigar_proc_cpu_get(sigar, goPid[i], &pcpu[i])
		C.sigar_proc_fd_get(sigar, goPid[i], &pfd[i])
		C.sigar_proc_exe_get(sigar, goPid[i], &pexe[i])

		C.sigar_proc_args_get(sigar, goPid[i], &pargs[i])
		C.sigar_proc_args_destroy(sigar, &pargs[i])

	}

	C.sigar_proc_list_destroy(sigar, &procList)

	return pstate,
		ptime,
		pmem,
		pdiskio,
		pcumdiskio,
		pcred,
		pcredname,
		pcpu,
		pargs,
		pfd,
		pexe

}