Пример #1
0
static VALUE rb_sigar_proc_list(int argc, VALUE *argv, VALUE obj)
{
    SIGAR_GET;

    int status;
    sigar_proc_list_t list;
    VALUE RETVAL;
    VALUE vptql;

    rb_scan_args(argc, argv, "01", &vptql);
    if (NIL_P(vptql)) {
        status = sigar_proc_list_get(sigar, &list);

        if (status != SIGAR_OK) {
            RB_SIGAR_CROAK;
        }
    }
    else {
        sigar_ptql_query_t *query;
        sigar_ptql_error_t error;
        char *ptql = StringValuePtr(vptql);

        status = sigar_ptql_query_create(&query, ptql, &error);

        if (status != SIGAR_OK) {
            RB_SIGAR_RAISE(error.message);
        }
        sigar_ptql_re_impl_set(sigar, NULL, rbsigar_ptql_re_impl);
        status = sigar_ptql_query_find(sigar, query, &list);
        sigar_ptql_re_impl_set(sigar, NULL, NULL);
        sigar_ptql_query_destroy(query);
        if (status != SIGAR_OK) {
            RB_SIGAR_RAISE(sigar_strerror(sigar, status));
        }
    }

    RETVAL = rb_sigar_new_intlist(&list.data[0],
                                  list.number);

    sigar_proc_list_destroy(sigar, &list);

    return RETVAL;
}
Пример #2
0
//-------------------------------------------------------------------------------------
bool SystemInfo::_autocreate()
{
	if(_g_sigarproclist == NULL)
	{
		sigar_open(&_g_sigarproclist);

		int status = sigar_proc_list_get(_g_sigarproclist, &_g_proclist);
		if (status != SIGAR_OK) 
		{
			DEBUG_MSG(fmt::format("SystemInfo::autocreate:error: {} ({}) sigar_proc_list_get\n",
					   status, sigar_strerror(_g_sigarproclist, status)));

			sigar_close(_g_sigarproclist);
			_g_sigarproclist = NULL;
			return false;
		}
	}

	return true;
}
JNIEXPORT jlongArray SIGAR_JNIx(getProcList)
(JNIEnv *env, jobject sigar_obj)
{
    int status;
    jlongArray procarray;
    sigar_proc_list_t proclist;
    jlong *pids = NULL;
    dSIGAR(NULL);

    if ((status = sigar_proc_list_get(sigar, &proclist)) != SIGAR_OK) {
        sigar_throw_error(env, jsigar, status);
        return NULL;
    }

    procarray = JENV->NewLongArray(env, proclist.number);
    SIGAR_CHEX;

    if (sizeof(jlong) == sizeof(sigar_pid_t)) {
        pids = (jlong *)proclist.data;
    }
    else {
        unsigned int i;
        pids = (jlong *)malloc(sizeof(jlong) * proclist.number);

        for (i=0; i<proclist.number; i++) {
            pids[i] = proclist.data[i];
        }
    }

    JENV->SetLongArrayRegion(env, procarray, 0,
                             proclist.number, pids);

    if (pids != (jlong *)proclist.data) {
        free(pids);
    }

    sigar_proc_list_destroy(sigar, &proclist);

    return procarray;
}
Пример #4
0
ProcList::ProcList()
{
    int status;
    sigar_t *sigar;
    sigar_proc_list_t proclist;
    unsigned long i;

    sigar_open(&sigar);
    status = sigar_proc_list_get(sigar, &proclist);

    if (status != SIGAR_OK) {
        printf("get proc list error: %d (%s)\n",
               status, sigar_strerror(sigar, status));
        exit(1);
    }

    for (i=0; i<proclist.number; i++) {
        sigar_pid_t pid = proclist.data[i];        
        sigar_proc_mem_t proc_mem;
        sigar_proc_time_t proc_time;
        sigar_proc_state_t proc_state;


        status = sigar_proc_mem_get(sigar, pid, &proc_mem);
        if (status != SIGAR_OK) {
#ifdef DEBUG
            printf("error: %d (%s) proc_mem(%d)\n",
                   status, sigar_strerror(sigar, status), pid);
#endif
            continue;
        }

        status = sigar_proc_state_get(sigar, pid, &proc_state);
        if (status != SIGAR_OK) {
#ifdef DEBUG
            printf("error: %d (%s) proc_state(%d)\n",
                   status, sigar_strerror(sigar, status), pid);
#endif
            continue;
        }

        status = sigar_proc_time_get(sigar, pid, &proc_time);
        if (status != SIGAR_OK) {
#ifdef DEBUG
            printf("error: %d (%s) proc_time(%d)\n",
                   status, sigar_strerror(sigar, status), pid);
#endif
            continue;
        }

//        printf("%d %s\n", (long)pid, pstate.name);
        //qDebug() << "name " << pstate.name << " processor " << pstate.processor;

        //qDebug()  << lpid.setNum((long)pid);
         // datas << QString("PID : %1 , %2").arg(lpid.setNum((long)pid), pstate.name);

        Process proc;

        //proc = new(Process);

        proc.pid.setNum((long)pid);
        proc.state_name = proc_state.name;
        proc.state_state = proc_state.state;
        proc.state_ppid.setNum(proc_state.ppid);
        //proc.state_tty = proc_state.tty;
        proc.state_priority.setNum(proc_state.priority);
        proc.state_nice.setNum(proc_state.nice);
        proc.state_processor.setNum(proc_state.processor);
        proc.state_threads.setNum(proc_state.threads);
        proc.mem_size.setNum(proc_mem.size);
        proc.mem_resident.setNum(proc_mem.resident);
        proc.mem_share.setNum(proc_mem.share);
        proc.mem_minor_faults.setNum(proc_mem.minor_faults);
        proc.mem_major_faults.setNum(proc_mem.major_faults);
        proc.mem_page_faults.setNum(proc_mem.page_faults);
        proc.time_start_time.setNum(proc_time.start_time);

        qDebug() << "proc_state.name : " << proc_state.name << " : proc_time.start_time : " << proc_time.start_time;

        proc.time_user.setNum(proc_time.user);
        proc.time_sys.setNum(proc_time.sys);
        proc.time_total.setNum(proc_time.total);

        stack.push(proc);
        //delete(proc);

    }
/* TEST OK
    while (!stack.isEmpty())
    {
        qDebug() << "stack length : " << stack.count();
        ok = .pop();
        qDebug() << "name : " << ok->state_name << " " << " pid : " << ok->pid;
        delete(ok);
    }
*/

    sigar_proc_list_destroy(sigar, &proclist);
    sigar_close(sigar);
}