char *OS_initialize() { struct CuAt* odm_object; int num_fetched; /* get the number of processors online */ ncpus = sysconf(_SC_NPROCESSORS_ONLN); if( ncpus == -1 ) { /* sysconf error */ ncpus = 1; } /* get the page size in bytes */ pagesize = getpagesize(); /* get the amount of physical memory */ if( 0 != odm_initialize() ) { /* fprintf(stderr, "cannot initialize ODM in Proc::ProcessTable::OS_initialize (AIX)!\n"); */ ppt_warn("cannot initialize ODM in Proc::ProcessTable::OS_initialize (AIX)!"); } else { odm_object = (struct CuAt*)getattr("sys0", "realmem", 0, &num_fetched); memory = strtoull(odm_object->value, 0, 10); odm_terminate(); } memory = memory * 1024; return NULL; }
/* fixup_stat_values() * * Correct, calculate, covert values to user expected values. * * @param format_str String containing field index types * @param prs Data structure to peform fixups on */ static void fixup_stat_values(char *format_str, struct procstat* prs) { /* set the state pointer to the right (const) string */ switch (prs->state_c) { case 'S': prs->state = get_string(SLEEP); break; case 'W': prs->state = get_string(WAIT); break; case 'R': prs->state = get_string(RUN); break; case 'I': prs->state = get_string(IDLE); break; case 'Z': prs->state = get_string(DEFUNCT); break; case 'D': prs->state = get_string(UWAIT); break; case 'T': prs->state = get_string(STOP); break; /* unknown state, state is already set to NULL */ default: ppt_warn("Ran into unknown state (hex char: %x)", (int) prs->state_c); goto skip_state_format; } field_enable(format_str, F_STATE); skip_state_format: prs->start_time = (prs->start_time / system_hertz) + boot_time; /* fix time */ prs->stime = JIFFIES_TO_MICROSECONDS(prs->stime); prs->utime = JIFFIES_TO_MICROSECONDS(prs->utime); prs->cstime = JIFFIES_TO_MICROSECONDS(prs->cstime); prs->cutime = JIFFIES_TO_MICROSECONDS(prs->cutime); /* derived time values */ prs->time = prs->utime + prs->stime; prs->ctime = prs->cutime + prs->cstime; field_enable_range(format_str, F_TIME, F_CTIME); /* fix rss to be in bytes (returned from kernel in pages) */ prs->rss *= page_size; }
void OS_get_table() { struct procsinfo64 *procs = NULL; int index = 0; int fetched = 0; struct timeval now_tval; /* allocate memory to hold the procs */ /* procs = New(0, procs, PROCS_TO_FETCH, struct procsinfo64); */ procs = (struct procsinfo64 *)malloc(sizeof(struct procsinfo64) * PROCS_TO_FETCH); if(NULL == procs) { /* fprintf(stderr, "cannot allocate memory in Proc::ProcessTable::OS_get_table!\n"); */ ppt_warn("cannot allocate memory in Proc::ProcessTable::OS_get_table!"); return; } /* get current time of day */ gettimeofday(&now_tval, 0); now_time = TVALU_TO_SEC(now_tval); /* keep on grabbing chunks of processes until getprocs returns a smaller block than we asked for */ while( (fetched = getprocs(procs, sizeof(struct procsinfo64), NULL, 0, &index, PROCS_TO_FETCH)) >= PROCS_TO_FETCH) { bless_procs(procs, fetched); } /* bless the last block of procs */ bless_procs(procs, fetched); /* release the memory */ Safefree(procs); return; }