void setup_globals(pmOptions *opts) { pmID pmids[HOST_NMETRICS]; pmDesc descs[HOST_NMETRICS]; pmResult *result; setup_context(opts); setup_metrics(hostmetrics, &pmids[0], &descs[0], HOST_NMETRICS); fetch_metrics("host", HOST_NMETRICS, pmids, &result); if (HOST_NMETRICS != result->numpmid) { fprintf(stderr, "%s: pmFetch failed to fetch initial metric value(s)\n", pmProgname); cleanstop(1); } hertz = extract_integer(result, descs, HOST_HERTZ); pagesize = extract_integer(result, descs, HOST_PAGESIZE); extract_string(result, descs, HOST_RELEASE, sysname.release, sizeof(sysname.release)); extract_string(result, descs, HOST_VERSION, sysname.version, sizeof(sysname.version)); extract_string(result, descs, HOST_MACHINE, sysname.machine, sizeof(sysname.machine)); extract_string(result, descs, HOST_NODENAME, sysname.nodename, sizeof(sysname.nodename)); nodenamelen = strlen(sysname.nodename); pmFreeResult(result); }
int photoproc(struct tstat *tasks, int *taskslen) { static int setup; static pmID pmids[TASK_NMETRICS]; static pmDesc descs[TASK_NMETRICS]; pmResult *result; char **insts; int *pids, count, i; if (!setup) { setup_metrics(procmetrics, pmids, descs, TASK_NMETRICS); setup = 1; } fetch_metrics("task", TASK_NMETRICS, pmids, &result); /* extract external process names (insts) */ count = get_instances("task", TASK_GEN_NAME, descs, &pids, &insts); if (count > *taskslen) { size_t size; int ents = (*taskslen + PROCCHUNK); if (count > ents) ents = count; size = ents * sizeof(struct tstat); tasks = (struct tstat *)realloc(tasks, size); ptrverify(tasks, "photoproc [%ld]\n", (long)size); *taskslen = ents; } for (i=0; i < count; i++) { if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "%s: updating process %d: %s\n", pmProgname, pids[i], insts[i]); update_task(&tasks[i], pids[i], insts[i], result, descs); } if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "%s: done %d processes\n", pmProgname, count); pmFreeResult(result); free(insts); free(pids); return count; }