aa580a1b88a6f7f08b069f7453f629eeede53b69 kent Wed Jan 15 18:00:32 2014 -0800 Making pmHubMultilineQuery return a slName list instead of a slRef list with string values. This saves about 8 freez() calls and is a bit tidier overall. diff --git src/parasol/para/para.c src/parasol/para/para.c index 5b6771d..895e281 100644 --- src/parasol/para/para.c +++ src/parasol/para/para.c @@ -688,52 +688,65 @@ { line = skipLeadingSpaces(line); if (line[0] == '#' || line[0] == 0) continue; job = jobCommaIn(&line, NULL); slAddHead(&db->jobList, job); ++db->jobCount; } lineFileClose(&lf); slReverse(&db->jobList); verbose(1, "%d jobs in batch\n", db->jobCount); verbose(2, "readBatch time: %.2f seconds\n", (clock1000() - time) / 1000.0); return db; } +char *hubSingleLineQuery(char *query) +/* Send message to hub and get single line response. + * This should be freeMem'd when done. */ +{ +return pmHubSingleLineQuery(query, "localhost"); +} + +struct slName *hubMultilineQuery(char *query) +/* Send a command with a multiline response to hub, + * and return response as a list of strings. */ +{ +return pmHubMultilineQuery(query, "localhost"); +} + boolean batchRunning(char *batchName) /* Return TRUE if a batch is running. */ { #define NUMLISTBATCHCOLUMNS 12 -struct slRef *lineList = hubMultilineQuery("listBatches"), *lineEl; +struct slName *lineList = hubMultilineQuery("listBatches"), *lineEl; boolean ret = FALSE; for (lineEl = lineList; lineEl != NULL; lineEl = lineEl->next) { int wordCount; - char *line = lineEl->val; + char *line = lineEl->name; char *row[NUMLISTBATCHCOLUMNS]; if (line[0] != '#') { char *b; wordCount = chopLine(line, row); b = row[NUMLISTBATCHCOLUMNS-1]; if (wordCount < NUMLISTBATCHCOLUMNS || b[0] != '/') errAbort("paraHub and para out of sync on listBatches"); if (sameString(b, batchName)) ret = TRUE; } - freez(&lineEl->val); } slFreeList(&lineList); return ret; } boolean thisBatchRunning() /* Return true if this batch is running */ { return batchRunning(batchDir); } struct jobDb *parseJobList(char *jobList) /* parse a job list */ { struct lineFile *lf = lineFileOpen(jobList, TRUE); @@ -743,44 +756,30 @@ AllocVar(db); while (lineFileNext(lf, &line, NULL)) { line = trimSpaces(line); if (line == NULL || line[0] == '#' || line[0] == 0) continue; ++db->jobCount; job = jobFromLine(lf, line); slAddHead(&db->jobList, job); } lineFileClose(&lf); slReverse(&db->jobList); return db; } -char *hubSingleLineQuery(char *query) -/* Send message to hub and get single line response. - * This should be freeMem'd when done. */ -{ -return pmHubSingleLineQuery(query, "localhost"); -} - -struct slRef *hubMultilineQuery(char *query) -/* Send a command with a multiline response to hub, - * and return response as a list of strings. */ -{ -return pmHubMultilineQuery(query, "localhost"); -} - void sendSetPriorityMessage(int priority) /* Tell hub to change priority on batch */ { struct dyString *dy = newDyString(1024); char *result; if ((priority < 1) || (priority > MAX_PRIORITY)) errAbort("Priority %d out of range, should be 1 to %d",priority,MAX_PRIORITY); dyStringPrintf(dy, "setPriority %s %s %d", getUser(), resultsName, priority); result = hubSingleLineQuery(dy->string); dyStringFree(&dy); if (result == NULL || sameString(result, "0")) errAbort("Couldn't set priority for %s\n", batchDir); freez(&result); verbose(1, "Told hub to set priority %d\n",priority); } @@ -956,81 +955,78 @@ struct job *job; struct submission *sub; int queueSize = 0; long killSeconds = killTime*60; long warnSeconds = warnTime*60; long duration; time_t now = time(NULL); long queryTime = clock1000(); /* Get job list from paraHub. */ struct dyString *dy = newDyString(1024); dyStringPrintf(dy, "pstat2 %s %s", getUser(), resultsName); -struct slRef *lineList = hubMultilineQuery(dy->string), *lineEl; +struct slName *lineList = hubMultilineQuery(dy->string), *lineEl; dyStringFree(&dy); now = time(NULL); /* need to refresh this after we get the info */ verbose(2, "pstat2 time: %.2f seconds\n", (clock1000() - queryTime) / 1000.0); long hashTime = clock1000(); verbose(2, "submission hash size: %d\n", hash->size); /* Make hash of submissions based on id and clear flags. */ for (job = db->jobList; job != NULL; job = job->next) { for (sub = job->submissionList; sub != NULL; sub = sub->next) { hashAdd(hash, sub->id, sub); sub->running = FALSE; sub->inQueue = FALSE; } } verbose(2, "submission hash time: %.2f seconds\n", (clock1000() - hashTime) / 1000.0); long pstatListTime = clock1000(); /* Read status output. */ for (lineEl = lineList; lineEl != NULL; lineEl = lineEl->next) { int wordCount; - char *line = lineEl->val; + char *line = lineEl->name; char *row[6]; if (startsWith("Total Jobs:", line)) { wordCount = chopLine(line, row); queueSize = sqlSigned(row[2]); verbose(1, "%d jobs (including everybody's) in Parasol queue or running.\n", queueSize); - freez(&lineEl->val); continue; } if (startsWith("Sick Batch:", line)) { sickBatch = TRUE; warn("%s", line); - freez(&lineEl->val); continue; } if (startsWith("Results Size:", line)) { wordCount = chopLine(line, row); resultsSize = sqlLongLong(row[2]); - freez(&lineEl->val); continue; } wordCount = chopLine(line, row); if (wordCount < 6 && wordCount != 2) { warn("Expecting at least 6 words in pstat2 output," " found %d. paraHub and para out of sync.", wordCount); statusOutputChanged(); } else { char *state = row[0], *jobId = row[1], *ticks = NULL, *host = NULL; time_t t = 0; if (wordCount > 2) { @@ -1057,31 +1053,30 @@ sub->slow = FALSE; sub->endTime = now; killJob(sub->id); verbose(1, "killed hung jobId: %s\n", sub->id); } else if (duration > warnSeconds) sub->slow = TRUE; } } else { sub->inQueue = TRUE; } } } - freez(&lineEl->val); } verbose(2, "pstat list time: %.2f seconds\n", (clock1000() - pstatListTime) / 1000.0); slFreeList(&lineList); freeHash(&hash); verbose(2, "markQueuedJobs time (includes pstat2, hash, list): %.2f seconds\n", (clock1000() - queryTime) / 1000.0); return queueSize; } struct hash *hashResults(char *fileName) /* Return hash of job results keyed on id as string. */ { long time = clock1000(); struct hash *hash = newHash(0); @@ -1130,41 +1125,40 @@ double subRealTime(struct submission *sub) /* Get real time in seconds for job. */ { /* note sub->*Time are unsigned, so we need to convert to double * before subtracting or time moving backwards is not detected */ return ((double)sub->endTime) - ((double)sub->startTime); } void showSickNodes(boolean showSummary) /* Tell hub to show sick nodes on batch. */ { int count = 0; struct dyString *dy = newDyString(1024); dyStringPrintf(dy, "showSickNodes %s %s", getUser(), resultsName); -struct slRef *lineList = hubMultilineQuery(dy->string), *lineEl; +struct slName *lineList = hubMultilineQuery(dy->string), *lineEl; for (lineEl = lineList; lineEl != NULL; lineEl = lineEl->next) { ++count; - char *line = lineEl->val; + char *line = lineEl->name; /* In show summary mode, only print the last line, * which contains the totals. Only print this one * if there's more than one line (the total is greater than zero). */ if (!showSummary || !(lineEl->next || count == 1)) printf("%s\n", line); - freez(&lineEl->val); } slFreeList(&lineList); dyStringFree(&dy); } void markRunJobStatus(struct jobDb *db) /* Mark jobs based on results output file. * Returns hash of results. */ { struct job *job; struct submission *sub; struct hash *checkHash = newHash(0); struct hash *resultsHash = hashResults(resultsName); long time = clock1000();