Beispiel #1
0
static int luv_cpu_info(lua_State* L) {
  uv_cpu_info_t* cpu_infos;
  int count, i;
  int ret = uv_cpu_info(&cpu_infos, &count);
  if (ret < 0) return luv_error(L, ret);
  lua_newtable(L);

  for (i = 0; i < count; i++) {
    lua_newtable(L);
    lua_pushstring(L, cpu_infos[i].model);
    lua_setfield(L, -2, "model");
    lua_pushnumber(L, cpu_infos[i].speed);
    lua_setfield(L, -2, "speed");
    lua_newtable(L);
    lua_pushnumber(L, cpu_infos[i].cpu_times.user);
    lua_setfield(L, -2, "user");
    lua_pushnumber(L, cpu_infos[i].cpu_times.nice);
    lua_setfield(L, -2, "nice");
    lua_pushnumber(L, cpu_infos[i].cpu_times.sys);
    lua_setfield(L, -2, "sys");
    lua_pushnumber(L, cpu_infos[i].cpu_times.idle);
    lua_setfield(L, -2, "idle");
    lua_pushnumber(L, cpu_infos[i].cpu_times.irq);
    lua_setfield(L, -2, "irq");
    lua_setfield(L, -2, "times");
    lua_rawseti(L, -2, i + 1);
  }

  uv_free_cpu_info(cpu_infos, count);
  return 1;
}
Beispiel #2
0
int get_cpu_count() {
  int r;
  uv_cpu_info_t *info;
  int cpu_count;
  r = uv_cpu_info(&info, &cpu_count);
  if (r) ERROR("obtaining cpu info", r);

  uv_free_cpu_info(info, cpu_count);
  return cpu_count;
}
Beispiel #3
0
MVMuint32 MVM_platform_cpu_count(void) {
    int count;
    uv_cpu_info_t *info;
    int e;

    e = uv_cpu_info(&info, &count);
    if (e == 0) uv_free_cpu_info(info, count);

    return count;
}
Beispiel #4
0
Datei: luv.c Projekt: Strongc/luv
static int luv_cpu_info(lua_State* L) {
  int size, i;
  uv_cpu_info_t* info;
  uv_err_t err = uv_cpu_info(&info, &size);

  lua_settop(L, 0);

  if (err.code) {
    lua_pushboolean(L, 0);
    luaL_error(L, uv_strerror(err));
    return 2;
  }

  lua_newtable(L);

  for (i = 0; i < size; i++) {
    lua_newtable(L);

    lua_pushstring(L, info[i].model);
    lua_setfield(L, -2, "model");

    lua_pushinteger(L, (lua_Integer)info[i].speed);
    lua_setfield(L, -2, "speed");

    lua_newtable(L); /* times */

    lua_pushinteger(L, (lua_Integer)info[i].cpu_times.user);
    lua_setfield(L, -2, "user");

    lua_pushinteger(L, (lua_Integer)info[i].cpu_times.nice);
    lua_setfield(L, -2, "nice");

    lua_pushinteger(L, (lua_Integer)info[i].cpu_times.sys);
    lua_setfield(L, -2, "sys");

    lua_pushinteger(L, (lua_Integer)info[i].cpu_times.idle);
    lua_setfield(L, -2, "idle");

    lua_pushinteger(L, (lua_Integer)info[i].cpu_times.irq);
    lua_setfield(L, -2, "irq");

    lua_setfield(L, -2, "times");

    lua_rawseti(L, 1, i + 1);
  }

  uv_free_cpu_info(info, size);
  return 1;
}
Beispiel #5
0
static PyObject *
Util_func_cpu_info(PyObject *obj)
{
    int i, count;
    uv_cpu_info_t* cpus;
    int err;
    PyObject *result, *item, *times, *exc_data;

    UNUSED_ARG(obj);

    err = uv_cpu_info(&cpus, &count);
    if (err == 0) {
        result = PyList_New(count);
        if (!result) {
            uv_free_cpu_info(cpus, count);
            return NULL;
        }
        for (i = 0; i < count; i++) {
            item = PyStructSequence_New(&CPUInfoResultType);
            times = PyStructSequence_New(&CPUInfoTimesResultType);
            if (!item || !times) {
                Py_XDECREF(item);
                Py_XDECREF(times);
                Py_DECREF(result);
                uv_free_cpu_info(cpus, count);
                return NULL;
            }
            PyStructSequence_SET_ITEM(item, 0, Py_BuildValue("s", cpus[i].model));
            PyStructSequence_SET_ITEM(item, 1, PyInt_FromLong((long)cpus[i].speed));
            PyStructSequence_SET_ITEM(item, 2, times);
            PyList_SET_ITEM(result, i, item);
            PyStructSequence_SET_ITEM(times, 0, PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.sys));
            PyStructSequence_SET_ITEM(times, 1, PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.user));
            PyStructSequence_SET_ITEM(times, 2, PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.idle));
            PyStructSequence_SET_ITEM(times, 3, PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.irq));
            PyStructSequence_SET_ITEM(times, 4, PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.nice));
        }
        uv_free_cpu_info(cpus, count);
        return result;
    } else {
        exc_data = Py_BuildValue("(is)", err, uv_strerror(err));
        if (exc_data != NULL) {
            PyErr_SetObject(PyExc_UVError, exc_data);
            Py_DECREF(exc_data);
        }
        return NULL;
    }
}
Beispiel #6
0
void Settings::SetDefaultNumWorkers() {
	MS_TRACE();

	int err;
	uv_cpu_info_t* cpus;
	int num_cpus;

	err = uv_cpu_info(&cpus, &num_cpus);
	if (err)
		MS_ABORT("uv_cpu_info() failed: %s", uv_strerror(err));

	uv_free_cpu_info(cpus, num_cpus);

	MS_DEBUG("auto-detected value for numWorkers: %d", num_cpus);
	Settings::configuration.numWorkers = num_cpus;
}
Beispiel #7
0
void node_lua_t::init_once()
{
	if (m_inited) return;
	uv_cpu_info_t* cpus;
	uv_err_t err = uv_cpu_info(&cpus, &m_cpu_count);
	assert(UV_OK == err.code);
	uv_free_cpu_info(cpus, m_cpu_count);
#ifndef RELEASE
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);
#endif
#ifndef CC_MSVC
	signal(SIGPIPE, SIG_IGN); /* close SIGPIPE signal */
#endif
	m_inited = true;
}
Beispiel #8
0
static PyObject *
Util_func_cpu_info(PyObject *obj)
{
    int i, count;
    uv_cpu_info_t* cpus;
    uv_err_t err;
    PyObject *result, *item, *times, *exc_data;

    UNUSED_ARG(obj);

    err = uv_cpu_info(&cpus, &count);
    if (err.code == UV_OK) {
        result = PyList_New(0);
        if (!result) {
            uv_free_cpu_info(cpus, count);
            PyErr_NoMemory();
            return NULL;
        }
        for (i = 0; i < count; i++) {
            item = PyDict_New();
            times = PyDict_New();
            if (!item || !times)
                continue;
            PyDict_SetItemString(item, "model", PyString_FromString(cpus[i].model));
            PyDict_SetItemString(item, "speed", PyInt_FromLong((long)cpus[i].speed));
            PyDict_SetItemString(item, "times", times);
            if (PyList_Append(result, item))
                continue;
            Py_DECREF(item);
            PyDict_SetItemString(times, "sys", PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.sys));
            PyDict_SetItemString(times, "user", PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.user));
            PyDict_SetItemString(times, "idle", PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.idle));
            PyDict_SetItemString(times, "irq", PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.irq));
            PyDict_SetItemString(times, "nice", PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)cpus[i].cpu_times.nice));
        }
        uv_free_cpu_info(cpus, count);
        return result;
    } else {
        exc_data = Py_BuildValue("(is)", err.code, uv_strerror(err));
        if (exc_data != NULL) {
            PyErr_SetObject(PyExc_UVError, exc_data);
            Py_DECREF(exc_data);
        }
        return NULL;
    }
}
Beispiel #9
0
void setup_workers() {
    size_t path_size = 500;
    uv_exepath(worker_path, &path_size);
    strcpy(worker_path + (strlen(worker_path) - strlen("multi-echo-server")), "worker");
    fprintf(stderr, "Worker path: %s\n", worker_path);

    char* args[2];
    args[0] = worker_path;
    args[1] = NULL;

    round_robin_counter = 0;

    // ...

    // launch same number of workers as number of CPUs
    uv_cpu_info_t *info;
    int cpu_count;
    uv_cpu_info(&info, &cpu_count);
    uv_free_cpu_info(info, cpu_count);

    child_worker_count = cpu_count;

    workers = calloc(sizeof(struct child_worker), cpu_count);
    while (cpu_count--) {
        struct child_worker *worker = &workers[cpu_count];
        uv_pipe_init(loop, &worker->pipe, 1);

        uv_stdio_container_t child_stdio[3];
        child_stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
        child_stdio[0].data.stream = (uv_stream_t*) &worker->pipe;
        child_stdio[1].flags = UV_IGNORE;
        child_stdio[2].flags = UV_INHERIT_FD;
        child_stdio[2].data.fd = 2;

        worker->options.stdio = child_stdio;
        worker->options.stdio_count = 3;

        worker->options.exit_cb = close_process_handle;
        worker->options.file = args[0];
        worker->options.args = args;

        uv_spawn(loop, &worker->req, worker->options); 
        fprintf(stderr, "Started worker %d\n", worker->req.pid);
    }
}
Beispiel #10
0
/*
 * Class:     com_oracle_libuv_LibUV
 * Method:    _getCPUs
 * Signature: ()[Ljava/lang/Object;
 */
JNIEXPORT jobjectArray JNICALL Java_com_oracle_libuv_LibUV__1getCPUs
  (JNIEnv *env, jclass cls) {

  uv_cpu_info_t* cpu_infos;
  int count;

  uv_err_t err = uv_cpu_info(&cpu_infos, &count);
  if (err.code != UV_OK) {
    return NULL;
  }

  jclass objectClassID = env->FindClass("java/lang/Object");
  assert(objectClassID);
  jclass integerClassID = env->FindClass("java/lang/Integer");
  assert(integerClassID);
  jmethodID integerConstructorMID = env->GetMethodID(integerClassID, "<init>", "(I)V");
  assert(integerConstructorMID);

  jobjectArray array = env->NewObjectArray(count * 7, objectClassID, NULL);
  OOMN(env, array);

  int j = 0;
  for (int i = 0; i < count; i++) {
      jstring model = env->NewStringUTF(cpu_infos[i].model);
      OOMN(env, model);
      env->SetObjectArrayElement(array, j++, model);
      env->DeleteLocalRef(model);

      jobject speed = env->NewObject(integerClassID, integerConstructorMID, cpu_infos[i].speed);
      OOMN(env, speed);
      env->SetObjectArrayElement(array, j++, speed);
      env->DeleteLocalRef(speed);

      jobject user = env->NewObject(integerClassID, integerConstructorMID, cpu_infos[i].cpu_times.user);
      OOMN(env, user);
      env->SetObjectArrayElement(array, j++, user);
      env->DeleteLocalRef(user);

      jobject nice = env->NewObject(integerClassID, integerConstructorMID, cpu_infos[i].cpu_times.nice);
      OOMN(env, nice);
      env->SetObjectArrayElement(array, j++, nice);
      env->DeleteLocalRef(nice);

      jobject sys = env->NewObject(integerClassID, integerConstructorMID, cpu_infos[i].cpu_times.sys);
      OOMN(env, sys);
      env->SetObjectArrayElement(array, j++, sys);
      env->DeleteLocalRef(sys);

      jobject idle = env->NewObject(integerClassID, integerConstructorMID, cpu_infos[i].cpu_times.idle);
      OOMN(env, idle);
      env->SetObjectArrayElement(array, j++, idle);
      env->DeleteLocalRef(idle);

      jobject irq = env->NewObject(integerClassID, integerConstructorMID, cpu_infos[i].cpu_times.irq);
      OOMN(env, irq);
      env->SetObjectArrayElement(array, j++, irq);
      env->DeleteLocalRef(irq);
  }
  uv_free_cpu_info(cpu_infos, count);

  return array;
}