int main() { NativeProcess(); VPNum numbVPs, vp; SysStatus rc; numbVPs = DREFGOBJ(TheProcessRef)->ppCount(); // create vps for (vp = 1; vp < numbVPs; vp++) { rc = ProgExec::CreateVP(vp); passert(_SUCCESS(rc), err_printf("ProgExec::CreateVP failed (0x%lx)\n", rc)); } // I'm vp 0 childMain(0); // start vps for (vp = 1; vp < numbVPs; vp++) { MPMsgMgr::MsgSpace msgSpace; LaunchChildMsg *const msg = new(Scheduler::GetEnabledMsgMgr(), msgSpace) LaunchChildMsg; msg->vp = vp; rc = msg->send(SysTypes::DSPID(0, vp)); tassert(_SUCCESS(rc), err_printf("traced: send failed\n")); } err_printf("done...\n"); return 0; }
int main(int argc, char *argv[]) { NativeProcess(); VPNum numbVPs, vp; SysStatus rc; char *str; uval turnTraceOn = 2; // Default do nothing to the trace Mask numbVPs = DREFGOBJ(TheProcessRef)->ppCount(); passert((numbVPs < MAX_CPUS), err_printf("too many vps\n")); BlockBarrier bar(numbVPs); if (argc < 2) { str = "User-level DEFAULT event [0|1]"; } else { str = argv[1]; } if (argc == 3) { if (argv[2][0] == '0') turnTraceOn = 0; if (argv[2][0] == '1') turnTraceOn = 1; } err_printf("Inserting event [%s] on all VPs...\n", str); // create vps for (vp = 1; vp < numbVPs; vp++) { rc = ProgExec::CreateVP(vp); passert(_SUCCESS(rc), err_printf("ProgExec::CreateVP failed (0x%lx)\n", rc)); } PFStat pfStats[numbVPs]; // start vps for (vp = 1; vp < numbVPs; vp++) { LaunchChildMsg *const msg = new(Scheduler::GetEnabledMsgMgr()) LaunchChildMsg; msg->vp = vp; msg->bar = &bar; msg->eventStr = str; msg->turnTraceOn = turnTraceOn; msg->stat = pfStats; rc = msg->send(SysTypes::DSPID(0, vp)); tassert(_SUCCESS(rc), err_printf("send failed\n")); } // I'm vp 0 childMain(0, str, &bar, turnTraceOn, pfStats); if (turnTraceOn == 0) { for (vp = 0; vp < numbVPs; vp++) { DO_PRINTF("VP%ld:\n-----------------\n", vp); pfStats[vp].Dump(); } } }
virtual void handle() { uval const myVP = vp; char *myStr = eventStr; Barrier *myBar = bar; uval myturnTraceOn = turnTraceOn; PFStat *myStat = stat; free(); childMain(myVP, myStr, myBar, myturnTraceOn, myStat); }
//private void setupMonitoring(bool isRetry, char* processName, unsigned long int duration, RegisterEntry* tail) { int num = 0; Process** runningProcesses = searchRunningProcesses(&num, processName, false, saveLogReport); if (runningProcesses == NULL) { // Nothing to be done if (num == 0) { if (!isRetry) { LogReport report; report.message = stringJoin("No process found with name: ", processName); report.type = INFO; saveLogReport(report, false); free(report.message); } return; } exit(-1); } int i; for(i = 0; i < num; ++i) { Process* p = runningProcesses[i]; if (p -> pid == getpid()) { // If procnannys were killed in the beginning, but a new one was started in between and the user expects to track that. // Should never happen/be done. LogReport report; report.message = "Config file had procnanny as one of the entries. It will be ignored if no other procnanny is found."; report.type = WARNING; saveLogReport(report, false); continue; } if (isProcessAlreadyBeingMonitored(p->pid)) { continue; } logProcessMonitoringInit(processName, p->pid); RegisterEntry* freeChild = getFirstFreeChild(); if (freeChild == NULL) { // fork a new child int writeToChildFD[2]; int readFromChildFD[2]; if (pipe(writeToChildFD) < 0) { destroyProcessArray(runningProcesses, num); LogReport report; report.message = "Pipe creation error when trying to monitor new process."; report.type = ERROR; saveLogReport(report, true); // TODO: Kill all children // TODO: Log all final kill count exit(-1); } if (pipe(readFromChildFD) < 0) { destroyProcessArray(runningProcesses, num); LogReport report; report.message = "Pipe creation error when trying to monitor new process."; report.type = ERROR; saveLogReport(report, true); // TODO: Kill all children // TODO: Log all final kill count exit(-1); } pid_t forkPid = fork(); switch (forkPid) { case -1: destroyProcessArray(runningProcesses, num); exit(-1); case CHILD: close(writeToChildFD[1]); close(readFromChildFD[0]); writingToParent = readFromChildFD[1]; readingFromParent = writeToChildFD[0]; pid_t targetPid = p->pid; destroyProcessArray(runningProcesses, num); cleanupGlobals(); while (true) { ProcessStatusCode childStatus = childMain(targetPid, duration); write(writingToParent, &childStatus, 1); MonitorMessage message; assert(read(readingFromParent, &message, sizeof(MonitorMessage)) == sizeof(MonitorMessage)); targetPid = message.targetPid; duration = message.monitorDuration; } break; default: // parent close(writeToChildFD[0]); close(readFromChildFD[1]); tail->monitoringProcess = forkPid; tail->monitoredProcess = p->pid; tail->monitorDuration = duration; tail->monitoredName = copyString(p->command); tail->startingTime = time(NULL); tail->isAvailable = false; tail->writeToChildFD = writeToChildFD[1]; tail->readFromChildFD = readFromChildFD[0]; FD_SET(tail->readFromChildFD, &activeFds); tail->next = constuctorRegisterEntry((pid_t)0, NULL, NULL); tail = tail->next; break; } } else { // use freeChild freeChild->isAvailable = false; freeChild->monitoredProcess = p->pid; free(freeChild->monitoredName); freeChild->monitoredName = copyString(p->command); freeChild->monitorDuration = duration; freeChild->startingTime = time(NULL); MonitorMessage message; message.targetPid = p->pid; message.monitorDuration = duration; write(freeChild->writeToChildFD, &message, sizeof(MonitorMessage)); } } destroyProcessArray(runningProcesses, num); }
virtual void handle() { childMain(vp); reply(); }