Alien-uv
view release on metacpan or search on metacpan
libuv/src/unix/aix.c view on Meta::CPAN
}
}
uint64_t uv_get_free_memory(void) {
perfstat_memory_total_t mem_total;
int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1);
if (result == -1) {
return 0;
}
return mem_total.real_free * 4096;
}
uint64_t uv_get_total_memory(void) {
perfstat_memory_total_t mem_total;
int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1);
if (result == -1) {
return 0;
}
return mem_total.real_total * 4096;
}
void uv_loadavg(double avg[3]) {
perfstat_cpu_total_t ps_total;
int result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
if (result == -1) {
avg[0] = 0.; avg[1] = 0.; avg[2] = 0.;
return;
}
avg[0] = ps_total.loadavg[0] / (double)(1 << SBITS);
avg[1] = ps_total.loadavg[1] / (double)(1 << SBITS);
avg[2] = ps_total.loadavg[2] / (double)(1 << SBITS);
}
#ifdef HAVE_SYS_AHAFS_EVPRODS_H
static char* uv__rawname(const char* cp, char (*dst)[FILENAME_MAX+1]) {
char* dp;
dp = rindex(cp, '/');
if (dp == 0)
return 0;
snprintf(*dst, sizeof(*dst), "%.*s/r%s", (int) (dp - cp), cp, dp + 1);
return *dst;
}
/*
* Determine whether given pathname is a directory
* Returns 0 if the path is a directory, -1 if not
*
* Note: Opportunity here for more detailed error information but
* that requires changing callers of this function as well
*/
static int uv__path_is_a_directory(char* filename) {
struct stat statbuf;
if (stat(filename, &statbuf) < 0)
return -1; /* failed: not a directory, assume it is a file */
if (statbuf.st_type == VDIR)
return 0;
return -1;
}
/*
* Check whether AHAFS is mounted.
* Returns 0 if AHAFS is mounted, or an error code < 0 on failure
*/
static int uv__is_ahafs_mounted(void){
char rawbuf[FILENAME_MAX+1];
int rv, i = 2;
struct vmount *p;
int size_multiplier = 10;
size_t siz = sizeof(struct vmount)*size_multiplier;
struct vmount *vmt;
const char *dev = "/aha";
char *obj, *stub;
p = uv__malloc(siz);
if (p == NULL)
return UV__ERR(errno);
/* Retrieve all mounted filesystems */
rv = mntctl(MCTL_QUERY, siz, (char*)p);
if (rv < 0)
return UV__ERR(errno);
if (rv == 0) {
/* buffer was not large enough, reallocate to correct size */
siz = *(int*)p;
uv__free(p);
p = uv__malloc(siz);
if (p == NULL)
return UV__ERR(errno);
rv = mntctl(MCTL_QUERY, siz, (char*)p);
if (rv < 0)
return UV__ERR(errno);
}
/* Look for dev in filesystems mount info */
for(vmt = p, i = 0; i < rv; i++) {
obj = vmt2dataptr(vmt, VMT_OBJECT); /* device */
stub = vmt2dataptr(vmt, VMT_STUB); /* mount point */
if (EQ(obj, dev) || EQ(uv__rawname(obj, &rawbuf), dev) || EQ(stub, dev)) {
uv__free(p); /* Found a match */
return 0;
}
vmt = (struct vmount *) ((char *) vmt + vmt->vmt_length);
}
/* /aha is required for monitoring filesystem changes */
return -1;
}
/*
( run in 1.017 second using v1.01-cache-2.11-cpan-e1769b4cff6 )