TRACE_EXPORT int TRACE_Open( const char filespec[], TRACE_file *fp ) { int i, j; RLOG_IOStruct *pInput; if (filespec == NULL || fp == NULL) return TRACEINPUT_FAIL; if (strcmp(filespec, "-h") == 0) { *fp = NULL; return TRACEINPUT_SUCCESS; } *fp = (_trace_file*)MPL_malloc(sizeof(_trace_file)); if (*fp == NULL) return TRACEINPUT_FAIL; (*fp)->pInput = pInput = RLOG_CreateInputStruct(filespec); if (pInput == NULL) { MPL_free(*fp); *fp = NULL; return TRACEINPUT_FAIL; } (*fp)->bArrowAvail = (RLOG_GetNextArrow(pInput, &(*fp)->arrow) == 0); if (pInput->nNumRanks > 0) { (*fp)->ppEvent = (RLOG_EVENT**)MPL_malloc(sizeof(RLOG_EVENT*) * pInput->nNumRanks); (*fp)->ppEventAvail = (int**)MPL_malloc(sizeof(int*) * pInput->nNumRanks); for (i=0; i<pInput->nNumRanks; i++) { if (pInput->pNumEventRecursions[i] > 0) { (*fp)->ppEvent[i] = (RLOG_EVENT*)MPL_malloc(sizeof(RLOG_EVENT) * pInput->pNumEventRecursions[i]); (*fp)->ppEventAvail[i] = (int*)MPL_malloc(sizeof(int) * pInput->pNumEventRecursions[i]); } else { (*fp)->ppEvent[i] = NULL; (*fp)->ppEventAvail[i] = NULL; } } } else { (*fp)->ppEvent = NULL; (*fp)->ppEventAvail = NULL; } for (j=0; j<pInput->nNumRanks; j++) { for (i=0; i<pInput->pNumEventRecursions[j]; i++) { (*fp)->ppEventAvail[j][i] = (RLOG_GetNextEvent(pInput, j+pInput->header.nMinRank, i, &(*fp)->ppEvent[j][i]) == 0); } } return TRACEINPUT_SUCCESS; }
int main(int argc, char *argv[]) { RLOG_IOStruct *pInput; int num_arrows; int total_num_events = 0; int i, j, range; int bSummary = 1; RLOG_ARROW arrow, lastarrow; int bInvalidArrowFound = 0; double *pOffset = NULL; int nNumStates = 0; int nNumLevels = 0; int nTotalNumEvents = 0; if (argc < 2) { printf("minalignrlog rlogfile\n"); return -1; } pInput = RLOG_CreateInputStruct(argv[1]); if (pInput == NULL) { printf("Error opening '%s'\n", argv[1]); return -1; } range = pInput->header.nMaxRank - pInput->header.nMinRank + 1; /*if (bValidateArrows)*/ { num_arrows = RLOG_GetNumArrows(pInput); if (num_arrows) { printf("num arrows: %d\n", num_arrows); RLOG_GetNextArrow(pInput, &lastarrow); if (lastarrow.start_time > lastarrow.end_time) { printf("start > end: %g > %g\n", lastarrow.start_time, lastarrow.end_time); bInvalidArrowFound = 1; } while (RLOG_GetNextArrow(pInput, &arrow) == 0) { if (arrow.start_time > arrow.end_time) { printf("start > end: %g > %g\n", arrow.start_time, arrow.end_time); bInvalidArrowFound = 1; } if (arrow.end_time < lastarrow.end_time) { printf("arrows out of order: %g < %g\n", arrow.end_time, lastarrow.end_time); bInvalidArrowFound = 1; } lastarrow = arrow; } } RLOG_ResetArrowIter(pInput); if (bInvalidArrowFound) { printf("Invalid arrows found in the rlog file\n"); RLOG_CloseInputStruct(&pInput); return -1; } } pOffset = (double*)MPIU_Malloc(range * sizeof(double)); if (pOffset == NULL) { printf("malloc failed\n"); return -1; } for (i=0; i<range; i++) pOffset[i] = 0.0; num_arrows = RLOG_GetNumArrows(pInput); if (num_arrows) { /*printf("num arrows: %d\n", num_arrows);*/ while (RLOG_GetNextArrow(pInput, &arrow) == 0) { if (arrow.leftright == RLOG_ARROW_LEFT) { arrow.start_time += pOffset[arrow.dest]; arrow.end_time += pOffset[arrow.src]; if (arrow.start_time < arrow.end_time) { pOffset[arrow.dest] += arrow.end_time - arrow.start_time; } } else { arrow.start_time += pOffset[arrow.src]; arrow.end_time += pOffset[arrow.dest]; if (arrow.start_time > arrow.end_time) { pOffset[arrow.dest] += arrow.start_time - arrow.end_time; } } } for (j=0; j<range; j++) { printf("[%d] -> %g\n", j, pOffset[j]); } RLOG_CloseInputStruct(&pInput); /* modify all the events */ RLOG_ModifyEvents(argv[1], pOffset, range); } else { RLOG_CloseInputStruct(&pInput); } return 0; }
/* FIXME: Add a structured comment for the man page generate to * create the basic documentation on this routine, particularly * since this routine only prints a subset of information by default */ int main(int argc, char *argv[]) { RLOG_IOStruct *pInput; RLOG_FILE_HEADER header; int num_levels; int num_states; int num_arrows; int num_events; int total_num_events = 0; int i, j, k; unsigned int nMask = 0; int bSummary = 1; RLOG_STATE state; RLOG_EVENT event, lastevent; RLOG_ARROW arrow, lastarrow; int bFindEvent = 0; double dFindTime = 0.0; int bValidate = 0; int bValidateArrows = 0; int bOrder = 0; int bJumpCheck = 0; double dJump = 0.0; /* FIXME: This should also check for the GNU-standard --help, --usage, * and -h options. */ if (argc < 2) { /* FIXME: What is the default behavior with just an rlogfile? */ printf("printrlog rlogfile [EVENTS | STATES | ARROWS | HEADER | COMM | ALL | SUMMARY ]\n"); printf("printrlog rlogfile find endtime\n"); printf("printrlog rlogfile validate\n"); printf("printrlog rlogfile order\n"); printf("printrlog rlogfile arroworder\n"); return -1; } if (argc > 2) { nMask = 0; bSummary = 0; for (i=2; i<argc; i++) { if (strcmp(argv[i], "EVENTS") == 0) nMask |= EVENT_BIT; if (strcmp(argv[i], "STATES") == 0) nMask |= STATE_BIT; if (strcmp(argv[i], "ARROWS") == 0) nMask |= ARROW_BIT; if (strcmp(argv[i], "HEADER") == 0) nMask |= HEADER_BIT; if (strcmp(argv[i], "COMM") == 0) nMask |= COMM_BIT; if (strcmp(argv[i], "ALL") == 0) nMask = HEADER_BIT | STATE_BIT | COMM_BIT | ARROW_BIT | EVENT_BIT; if (strcmp(argv[i], "SUMMARY") == 0) { bSummary = 1; nMask = 0; } if (strcmp(argv[i], "find") == 0) { bFindEvent = 1; dFindTime = atof(argv[i+1]); } if (strcmp(argv[i], "validate") == 0) { bValidate = 1; } if (strcmp(argv[i], "order") == 0) { bOrder = 1; } if (strcmp(argv[i], "arroworder") == 0) { bValidateArrows = 1; } if (strcmp(argv[i], "jump") == 0) { bJumpCheck = 1; if (argv[i+1]) dJump = atof(argv[i+1]); } } } pInput = RLOG_CreateInputStruct(argv[1]); if (pInput == NULL) { printf("Error opening '%s'\n", argv[1]); return -1; } if (bValidateArrows) { num_arrows = RLOG_GetNumArrows(pInput); if (num_arrows) { printf("num arrows: %d\n", num_arrows); RLOG_GetNextArrow(pInput, &lastarrow); if (lastarrow.start_time > lastarrow.end_time) printf("start > end: %g > %g\n", lastarrow.start_time, lastarrow.end_time); while (RLOG_GetNextArrow(pInput, &arrow) == 0) { if (arrow.start_time > arrow.end_time) printf("start > end: %g > %g\n", arrow.start_time, arrow.end_time); if (arrow.end_time < lastarrow.end_time) printf("arrows out of order: %d < %d\n", arrow.end_time, lastarrow.end_time); lastarrow = arrow; } } RLOG_CloseInputStruct(&pInput); return 0; } if (bValidate) { num_arrows = RLOG_GetNumArrows(pInput); if (num_arrows) { printf("num arrows: %d\n", num_arrows); RLOG_GetNextArrow(pInput, &lastarrow); if (lastarrow.start_time > lastarrow.end_time) { printf("Error, arrows endtime before starttime: %g < %g\n", lastarrow.end_time, lastarrow.start_time); PrintArrow(&arrow); } while (RLOG_GetNextArrow(pInput, &arrow) == 0) { if (lastarrow.end_time > arrow.end_time) { printf("Error, arrows out of order: %g > %g\n", lastarrow.end_time, arrow.end_time); PrintArrow(&lastarrow); PrintArrow(&arrow); } if (arrow.start_time > arrow.end_time) { printf("Error, arrows endtime before starttime: %g < %g\n", arrow.end_time, arrow.start_time); PrintArrow(&arrow); } lastarrow = arrow; } } for (j=pInput->header.nMinRank; j<=pInput->header.nMaxRank; j++) { num_levels = RLOG_GetNumEventRecursions(pInput, j); for (i=0; i<num_levels; i++) { printf("Validating events in level %d:%d\n", j, i); if (RLOG_GetNextEvent(pInput, j, i, &event) == 0) { if (event.end_time < event.start_time) { printf("Error, event endtime before starttime: %g < %g\n", event.end_time, event.start_time); } lastevent = event; while (RLOG_GetNextEvent(pInput, j, i, &event) == 0) { if (lastevent.start_time > event.start_time) { printf("Error, events out of order: %g > %g\n", lastevent.start_time, event.start_time); PrintEvent(&lastevent); PrintEvent(&event); } else if (lastevent.end_time > event.start_time) { printf("Error, starttime before previous endtime: %g > %g\n", lastevent.end_time, event.start_time); PrintEvent(&lastevent); PrintEvent(&event); } if (event.end_time < event.start_time) { printf("Error, event endtime before starttime: %g < %g\n", event.end_time, event.start_time); PrintEvent(&event); } lastevent = event; } } } } RLOG_CloseInputStruct(&pInput); return 0; } if (bOrder) { int count = 0; if (RLOG_GetNextGlobalEvent(pInput, &event) != 0) { RLOG_CloseInputStruct(&pInput); return 0; } count++; lastevent = event; PrintEvent(&event); while (RLOG_GetNextGlobalEvent(pInput, &event) == 0) { if (lastevent.start_time > event.start_time) { printf("Error, events out of order: %g > %g\n", lastevent.start_time, event.start_time); PrintEvent(&lastevent); PrintEvent(&event); } if (event.end_time < event.start_time) { printf("Error, event endtime before starttime: %g < %g\n", event.end_time, event.start_time); PrintEvent(&event); } lastevent = event; PrintEvent(&event); count++; } RLOG_CloseInputStruct(&pInput); printf("%d events traversed\n", count); return 0; } if (bFindEvent) { for (j=pInput->header.nMinRank; j<=pInput->header.nMaxRank; j++) { printf("rank %d\n", j); num_levels = RLOG_GetNumEventRecursions(pInput, j); for (i=0; i<num_levels; i++) { RLOG_FindEventBeforeTimestamp(pInput, j, i, dFindTime, &event, &k); PrintEventAndIndex(&event, k); } } RLOG_CloseInputStruct(&pInput); return 0; } if (bJumpCheck) { printf("Start:\n"); RLOG_FindGlobalEventBeforeTimestamp(pInput, dJump, &event); PrintEvent(&event); /*RLOG_PrintGlobalState(pInput);*/ printf("Previous 10:\n"); for (i=0; i<10; i++) { RLOG_GetPreviousGlobalEvent(pInput, &event); PrintEvent(&event); } printf("Start:\n"); RLOG_FindGlobalEventBeforeTimestamp(pInput, dJump, &event); PrintEvent(&event); printf("Next 10:\n"); for (i=0; i<10; i++) { RLOG_GetNextGlobalEvent(pInput, &event); PrintEvent(&event); } return 0; } if (RLOG_GetFileHeader(pInput, &header)) { printf("unable to read the file header\n"); RLOG_CloseInputStruct(&pInput); return -1; } if (nMask & HEADER_BIT || bSummary) { printf("min rank: %d\n", header.nMinRank); printf("max rank: %d\n", header.nMaxRank); } if (nMask & STATE_BIT || bSummary) { num_states = RLOG_GetNumStates(pInput); if (num_states) { printf("num states: %d\n", num_states); if (nMask & STATE_BIT) { for (i=0; i<num_states; i++) { RLOG_GetNextState(pInput, &state); PrintState(&state); } } } } if (nMask & ARROW_BIT || bSummary) { num_arrows = RLOG_GetNumArrows(pInput); if (num_arrows) { printf("num arrows: %d\n", num_arrows); if (nMask & ARROW_BIT) { for (i=0; i<num_arrows; i++) { RLOG_GetNextArrow(pInput, &arrow); PrintArrow(&arrow); } } } } if (nMask & EVENT_BIT || bSummary) { for (k=pInput->header.nMinRank; k<=pInput->header.nMaxRank; k++) { total_num_events = 0; num_levels = RLOG_GetNumEventRecursions(pInput, k); if (num_levels > 0) { printf("rank %d\n", k); printf("num event recursions: %d\n", num_levels); for (i=0; i<num_levels; i++) { num_events = RLOG_GetNumEvents(pInput, k, i); total_num_events += num_events; printf(" level %d, num events: %d\n", i, num_events); if (nMask & EVENT_BIT) { for (j=0; j<num_events; j++) { RLOG_GetNextEvent(pInput, k, i, &event); PrintEvent(&event); } } } printf("num events total: %d\n", total_num_events); } } } RLOG_CloseInputStruct(&pInput); return 0; }