int CollectorDarwin::getProcessMemoryUsage(RTPROCESS process, ULONG *used) { struct proc_taskinfo tinfo; int rc = getProcessInfo(process, &tinfo); if (RT_SUCCESS(rc)) { *used = tinfo.pti_resident_size / 1024; } return rc; }
/* JDD's code */ void debug_out(struct buffer& b) { for (size_t i=0; i<b.num_samples; i++) { struct sample& c = b.samples[i]; ProcessInfo& pi = getProcessInfo(c.pid, packet_empty()); fprintf(stderr, "%lu,%u,%lu,%u,%u,%u,%u,%u,%u,%s,%s\n", c.pid, b.core, c.cycles, c.counters[0], c.counters[1], c.counters[2], c.counters[3], c.counters[4], c.counters[5], pi.cmdline.c_str(), pi.executable.c_str()); } }
void getProcAndChildCpu(int pid, cpuVals* cpv) { int i=0; struct cpuVals tempCpu; tempCpu.userTime=0; tempCpu.sysTime=0; cpv->userTime=0; cpv->sysTime=0; for(i = 0; i < numProc; i++) { getProcessInfo(procTable[i],NULL,&tempCpu,flagTable[i]); cpv->userTime += tempCpu.userTime; cpv->sysTime += tempCpu.sysTime; } }
int CollectorDarwin::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total) { struct proc_taskinfo tinfo; int rc = getProcessInfo(process, &tinfo); if (RT_SUCCESS(rc)) { /* * Adjust user and kernel values so 100% is when ALL cores are fully * utilized (see @bugref{6345}). */ *user = tinfo.pti_total_user / nCpus; *kernel = tinfo.pti_total_system / nCpus; *total = mach_absolute_time(); } return rc; }
void searchDirs(int procChildren[], int dirNames[], int count,cpuVals *cpv,int tempPid) { int x=0,ppid=0; struct cpuVals tempCpu; for(x = 0; x < count; x++) { ppid = getProcessInfo(dirNames[x],NULL,&tempCpu,procChildren[x]); if(ppid==tempPid) { cpv->userTime += tempCpu.userTime; cpv->sysTime += tempCpu.sysTime; searchDirs(procChildren,dirNames,count,cpv,dirNames[x]); } else { tempCpu.userTime=0; tempCpu.sysTime=0; } } }
void ps(char splitInput[][20], int splitNum) { int fdout = mq_open("/tmp/mqueue/out", 0); const struct task_control_block tasks[TASK_LIMIT]; int taskCount,i; getProcessInfo(tasks,&taskCount); char str[10]; write(fdout, "Pid\tStatus\t\tPriority\n\r", 24); for(i = 0; i < taskCount; i++) { itoa(tasks[i].pid, str); write(fdout, str, strlen(str)+1); write(fdout, "\t", 2); switch(tasks[i].status) { case TASK_READY: write(fdout, "TASK READY\t", 12); break; case TASK_WAIT_READ: write(fdout, "TASK WAIT READ\t", 16); break; case TASK_WAIT_WRITE: write(fdout, "TASK WAIT WRITE\t", 17); break; case TASK_WAIT_INTR: write(fdout, "TASK WAIT INTR\t", 16); break; case TASK_WAIT_TIME: write(fdout, "TASK WAIT TIME\t", 16); break; default: break; } itoa(tasks[i].priority, str); write(fdout, str, strlen(str)+1); write(fdout, "\n\r",3); } }
int network_send(struct buffer &b, uint32_t missed, size_t *total) { size_t sent = 0; size_t sent_total = 0; size_t index = 0; void *data = NULL; assert(b.num_samples <= BUFFER_ENTRIES); if (debug) fprintf(stderr, "STARTING BATCH WITH %u SAMPLES!\n", b.num_samples); packet_start_batch(); for (index = 0; index < b.num_samples; ++index) { struct sample &s = b.samples[index]; struct ProcessInfo& pi = getProcessInfo(s.pid, packet_empty()); if (packet_should_create(b, s, pi)) { if (debug) fprintf(stderr, "PACKET MUST BE SENT BEFORE CONTINUING.\n"); if (transmit(&sent)) return -1; sent_total += sent; } /* This should never happen given the above statement */ if (packet_append(b, s, pi, missed)) return -1; } /* Anything at the end should be sent */ if (transmit(&sent)) return -1; sent_total += sent; if (total) *total = sent_total; return 0; }
Boolean Process::loadProcessInfo (int &pIndex) { int status; unsigned long maxprocount; __int64 qpid; char handle[100]; unsigned long jpictx2; /* The context for JPI calls */ item_list itmlst3[MAXITMLST]; int procCount; Boolean stat; /* If this is the first process request. Rebuild proc_table */ if (pIndex == 0) { /* Lock the mutex on proc_table */ pthread_mutex_lock(&proc_table_mutex); /* Free the old proc_table */ if (proc_table != NULL) { free(proc_table); proc_table = NULL; proc_table_count = 0; } /* Find the maximum process that could run on the system */ if ((maxprocount = getmaxprocount ()) == 0) { /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); /* Return false */ return false; } /* Allocate memory to proc_table */ proc_table = (proc_info_t) calloc (maxprocount + 1, sizeof (struct proc_info)); /* Error in allocating Memory. return false */ if (NULL == proc_table) { /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); return false; } jpictx2 = 0; procCount = 0; itmlst3[0].wlength = 0; itmlst3[0].wcode = PSCAN$_MODE; itmlst3[0].pbuffer = (void *) JPI$K_OTHER; itmlst3[0].pretlen = NULL; itmlst3[1].wlength = 0; itmlst3[1].wcode = 0; itmlst3[1].pbuffer = NULL; itmlst3[1].pretlen = NULL; status = sys$process_scan (&jpictx2, itmlst3); if (!$VMS_STATUS_SUCCESS (status)) { /* Free the proc_table */ free (proc_table); proc_table = NULL; proc_table_count = 0; /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); /* Return failure */ return false; } stat = buildProcessTable(jpictx2, procCount, itmlst3, proc_table); proc_table_count += procCount; jpictx2 = 0; procCount = 0; itmlst3[0].wlength = 0; itmlst3[0].wcode = PSCAN$_MODE; itmlst3[0].pbuffer = (void *) JPI$K_BATCH; itmlst3[0].pretlen = NULL; itmlst3[1].wlength = 0; itmlst3[1].wcode = 0; itmlst3[1].pbuffer = NULL; itmlst3[1].pretlen = NULL; status = sys$process_scan (&jpictx2, itmlst3); if (!$VMS_STATUS_SUCCESS (status)) { /* Free the proc_table */ free (proc_table); proc_table = NULL; proc_table_count = 0; /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); /* Return failure */ return false; } stat = buildProcessTable(jpictx2, procCount, itmlst3, &proc_table[proc_table_count]); proc_table_count += procCount; jpictx2 = 0; procCount = 0; itmlst3[0].wlength = 0; itmlst3[0].wcode = PSCAN$_MODE; itmlst3[0].pbuffer = (void *) JPI$K_NETWORK; itmlst3[0].pretlen = NULL; itmlst3[1].wlength = 0; itmlst3[1].wcode = 0; itmlst3[1].pbuffer = NULL; itmlst3[1].pretlen = NULL; status = sys$process_scan (&jpictx2, itmlst3); if (!$VMS_STATUS_SUCCESS (status)) { /* Free the proc_table */ free (proc_table); proc_table = NULL; proc_table_count = 0; /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); /* Return failure */ return false; } stat = buildProcessTable(jpictx2, procCount, itmlst3, &proc_table[proc_table_count]); proc_table_count += procCount; jpictx2 = 0; itmlst3[0].wlength = 0; itmlst3[0].wcode = PSCAN$_MODE; itmlst3[0].pbuffer = (void *) JPI$K_INTERACTIVE; itmlst3[0].pretlen = NULL; itmlst3[1].wlength = 0; itmlst3[1].wcode = 0; itmlst3[1].pbuffer = NULL; itmlst3[1].pretlen = NULL; status = sys$process_scan (&jpictx2, itmlst3); if (!$VMS_STATUS_SUCCESS (status)) { /* Free the proc_table */ free (proc_table); proc_table = NULL; proc_table_count = 0; /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); /* Return failure */ return false; } stat = buildProcessTable(jpictx2, procCount, itmlst3, &proc_table[proc_table_count]); proc_table_count += procCount; /* Un lock the mutex on proc_table */ pthread_mutex_unlock(&proc_table_mutex); } /* End if (pIndex == 0), rebuild of proc_table */ return getProcessInfo(pIndex); }
Process::Process(int pid) { this->mPid = pid; getProcessInfo(); }