Пример #1
0
JNIEXPORT void JNICALL
Java_com_zimbra_znative_ResourceUsage_getResourceUsage0(JNIEnv *env, jclass clz, jint who, jlongArray jdata)
{
  struct rusage ru;
  jlong data[com_zimbra_znative_ResourceUsage_RESOURCE_MAX];

  if (getrusage(who, &ru) == -1) {
    char msg[256];
    snprintf(msg, sizeof(msg), "getrusage(): %s", strerror(errno));
    ZimbraThrowOFE(env, msg);
    return;
  }
  
  data[com_zimbra_znative_ResourceUsage_RESOURCE_UTIME] = (ru.ru_utime.tv_sec * 1000) + (ru.ru_utime.tv_usec / 1000);
  data[com_zimbra_znative_ResourceUsage_RESOURCE_STIME] = (ru.ru_stime.tv_sec * 1000) + (ru.ru_stime.tv_usec / 1000);
  data[com_zimbra_znative_ResourceUsage_RESOURCE_MAXRSS] = ru.ru_maxrss;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_IXRSS] = ru.ru_ixrss;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_IDRSS] = ru.ru_idrss;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_ISRSS] = ru.ru_isrss;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_MINFLT] = ru.ru_minflt;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_MAJFLT] = ru.ru_majflt;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_NSWAP] = ru.ru_nswap;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_INBLOCK] = ru.ru_inblock;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_OUBLOCK] = ru.ru_oublock;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_MSGSND] = ru.ru_msgsnd;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_MSGRCV] = ru.ru_msgrcv;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_NSIGNALS] = ru.ru_nsignals;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_NVCSW] = ru.ru_nvcsw;
  data[com_zimbra_znative_ResourceUsage_RESOURCE_NIVCSW] = ru.ru_nivcsw;

  (*env)->SetLongArrayRegion(env, jdata, 0, com_zimbra_znative_ResourceUsage_RESOURCE_MAX, data);
}
Пример #2
0
JNIEXPORT jlong JNICALL
Java_com_zimbra_znative_Util_getTicksPerSecond0(JNIEnv *env, jclass clz)
{
  long tps = sysconf(_SC_CLK_TCK);
  if (tps == -1) {
    char msg[256];
    snprintf(msg, sizeof(msg), "times(): %s", strerror(errno));
    ZimbraThrowOFE(env, msg);
    return -1;
  }
  return tps;
} 
Пример #3
0
JNIEXPORT void JNICALL
Java_com_zimbra_znative_ProcessorUsage_getProcessorUsage0(JNIEnv *env, jclass clz, jlongArray jdata)
{
  struct tms tms;
  clock_t wall;
  jlong data[com_zimbra_znative_ProcessorUsage_OFFSET_MAX];

  if ((wall = times(&tms)) == ((clock_t)-1)) {
    char msg[256];
    snprintf(msg, sizeof(msg), "times(): %s", strerror(errno));
    ZimbraThrowOFE(env, msg);
    return;
  }
  
  data[com_zimbra_znative_ProcessorUsage_OFFSET_UTICKS] = tms.tms_utime;
  data[com_zimbra_znative_ProcessorUsage_OFFSET_STICKS] = tms.tms_stime;
  data[com_zimbra_znative_ProcessorUsage_OFFSET_CUTICKS] = tms.tms_cutime;
  data[com_zimbra_znative_ProcessorUsage_OFFSET_CSTICKS] = tms.tms_cstime;
  data[com_zimbra_znative_ProcessorUsage_OFFSET_WTICKS] = wall;

  (*env)->SetLongArrayRegion(env, jdata, 0, com_zimbra_znative_ProcessorUsage_OFFSET_MAX, data);
}