📄 disksim_iotrace.c
字号:
new->bcount = val; if (new->bcount & 0x000001FF) { fprintf(stderr, "HPL request for non-512B multiple size: %d\n", new->bcount); exit(1); } new->bcount = new->bcount >> 9; failure |= iotrace_read_int32(tracefile, &val); new->blkno = val; failure |= iotrace_read_int32(tracefile, &val); new->devno = (val >> 8) & 0xFF; failure |= iotrace_read_int32(tracefile, &val); /* drivertype */ failure |= iotrace_read_int32(tracefile, &val); /* cylno */ /* for convenience and historical reasons, this cast is being allowed */ /* (the value is certain to be less than 32 sig bits, and will not be */ /* used as a pointer). */ new->buf = (void *) val; failure |= iotrace_read_int32(tracefile, &val); new->flags = val; iotrace_hpl_srt_convert_flags(new); failure |= iotrace_read_int32(tracefile, &junkint); /* info */ size -= 13 * sizeof(int32_t); if ((id >> 16) == 4) { failure |= iotrace_read_int32(tracefile, &val); /* queuelen */ new->slotno = val; size -= sizeof(int32_t); } if ((id & 0xFFFF) == HPL_SUSPECTIO) { failure |= iotrace_read_int32(tracefile, &junkint); /* susflags */ size -= sizeof(int32_t); } if (failure) { addtoextraq((event *) new); return(NULL); } if (size) { fprintf(stderr, "Unmatched size for record - %d\n", size); exit(1); } new->cause = 0; new->opid = 0; new->busno = 0; if ((id & 0xFFFF) == HPL_SHORTIO) { return(new); } }}static int iotrace_month_convert (char *monthstr, int year){ if (strcmp(monthstr, "Jan") == 0) { return(0); } else if (strcmp(monthstr, "Feb") == 0) { return(31); } else if (strcmp(monthstr, "Mar") == 0) { return((year % 4) ? 59 : 60); } else if (strcmp(monthstr, "Apr") == 0) { return((year % 4) ? 90 : 91); } else if (strcmp(monthstr, "May") == 0) { return((year % 4) ? 120 : 121); } else if (strcmp(monthstr, "Jun") == 0) { return((year % 4) ? 151 : 152); } else if (strcmp(monthstr, "Jul") == 0) { return((year % 4) ? 181 : 182); } else if (strcmp(monthstr, "Aug") == 0) { return((year % 4) ? 212 : 213); } else if (strcmp(monthstr, "Sep") == 0) { return((year % 4) ? 243 : 244); } else if (strcmp(monthstr, "Oct") == 0) { return((year % 4) ? 273 : 274); } else if (strcmp(monthstr, "Nov") == 0) { return((year % 4) ? 304 : 305); } else if (strcmp(monthstr, "Dec") == 0) { return((year % 4) ? 334 : 335); } assert(0); return(-1);}static double iotrace_raw_get_hirestime (int bigtime, int smalltime){ unsigned int loresticks; int small, turnovers; int smallticks; if (basebigtime == -1) { basebigtime = bigtime; basesmalltime = smalltime; basesimtime = 0.0; } else { small = (basesmalltime - smalltime) & 0xFFFF; loresticks = (bigtime - basebigtime) * 11932 - small; turnovers = (int) (((double) loresticks / (double) 65536) + (double) 0.5); smallticks = turnovers * 65536 + small; basebigtime = bigtime; basesmalltime = smalltime; basesimtime += (double) smallticks * (double) 0.000838574; } return(basesimtime);}/* kept mainly as an example */static ioreq_event * iotrace_raw_get_ioreq_event (FILE *tracefile, ioreq_event *new){ int bigtime; unsigned short small; int smalltime; int failure = 0; char order, crit; double schedtime, donetime; int32_t val; failure |= iotrace_read_int32(tracefile, &val); bigtime = val; failure |= iotrace_read_short(tracefile, &small); smalltime = ((int) small) & 0xFFFF; new->time = iotrace_raw_get_hirestime(bigtime, smalltime); failure |= iotrace_read_short(tracefile, &small); failure |= iotrace_read_int32(tracefile, &val); bigtime = val; smalltime = ((int) small) & 0xFFFF; schedtime = iotrace_raw_get_hirestime(bigtime, smalltime); failure |= iotrace_read_int32(tracefile, &val); bigtime = val; failure |= iotrace_read_short(tracefile, &small); smalltime = ((int) small) & 0xFFFF; donetime = iotrace_raw_get_hirestime(bigtime, smalltime); failure |= iotrace_read_char(tracefile, &order); failure |= iotrace_read_char(tracefile, &crit); if (crit) { new->flags |= TIME_CRITICAL; } failure |= iotrace_read_int32(tracefile, &val); new->bcount = val >> 9; failure |= iotrace_read_int32(tracefile, &val); new->blkno = val; failure |= iotrace_read_int32(tracefile, &val); new->devno = val; failure |= iotrace_read_int32(tracefile, &val); new->flags = val & READ; new->cause = 0; new->buf = 0; new->opid = 0; new->busno = 0; new->tempint1 = (int)((schedtime - new->time) * (double) 1000); new->tempint2 = (int)((donetime - schedtime) * (double) 1000); if (failure) { addtoextraq((event *) new); new = NULL; } return(new);}static ioreq_event * iotrace_emcsymm_get_ioreq_event (FILE *tracefile, ioreq_event *new){ char line[201]; char operation[15]; unsigned int director; if (fgets(line, 200, tracefile) == NULL) { addtoextraq((event *) new); return(NULL); } if (sscanf(line, "%lf %s %x %x %d %d\n", &new->time, operation, &director, &new->devno, &new->blkno, &new->bcount) != 6) { fprintf(stderr, "Wrong number of arguments for I/O trace event type\n"); fprintf(stderr, "line: %s", line); ddbg_assert(0); } if (!strcasecmp(operation,"Read")) { new->flags = READ; } else if (!strcasecmp(operation,"Write")) { new->flags = WRITE; } else { fprintf(stderr, "Unknown operation: %s in iotrace event\n",operation); fprintf(stderr, "line: %s", line); exit(1); } new->buf = 0; new->opid = 0; new->busno = 0; new->cause = 0; return(new);}static ioreq_event * iotrace_ascii_get_ioreq_event (FILE *tracefile, ioreq_event *new){ char line[201]; if (fgets(line, 200, tracefile) == NULL) { addtoextraq((event *) new); return(NULL); } if (sscanf(line, "%lf %d %d %d %x\n", &new->time, &new->devno, &new->blkno, &new->bcount, &new->flags) != 5) { fprintf(stderr, "Wrong number of arguments for I/O trace event type\n"); fprintf(stderr, "line: %s", line); ddbg_assert(0); } if (new->flags & ASYNCHRONOUS) { new->flags |= (new->flags & READ) ? TIME_LIMITED : 0; } else if (new->flags & SYNCHRONOUS) { new->flags |= TIME_CRITICAL; } new->buf = 0; new->opid = 0; new->busno = 0; new->cause = 0; return(new);}ioreq_event * iotrace_get_ioreq_event (FILE *tracefile, int traceformat, ioreq_event *temp){ switch (traceformat) { case ASCII: temp = iotrace_ascii_get_ioreq_event(tracefile, temp); break; case RAW: temp = iotrace_raw_get_ioreq_event(tracefile, temp); break; case HPL: temp = iotrace_hpl_get_ioreq_event(tracefile, temp); break; case DEC: temp = iotrace_dec_get_ioreq_event(tracefile, temp); break; case VALIDATE: temp = iotrace_validate_get_ioreq_event(tracefile, temp); break; case EMCSYMM: temp = iotrace_emcsymm_get_ioreq_event(tracefile, temp); break; default: fprintf(stderr, "Unknown traceformat in iotrace_get_ioreq_event - %d\n", traceformat); exit(1); } return ((ioreq_event *)temp);}static void iotrace_hpl_srt_tracefile_start (char *tracedate){ char crap[40]; char monthstr[40]; int day; int hour; int minute; int second; int year; if (sscanf(tracedate, "%s\t= \"%s %s %d %d:%d:%d %d\";\n", crap, crap, monthstr, &day, &hour, &minute, &second, &year) != 8) { fprintf(stderr, "Format problem with 'tracedate' line in HPL trace - %s\n", tracedate); exit(1); } if (baseyear == 0) { baseyear = year; } day = day + iotrace_month_convert(monthstr, year); if (year != baseyear) { day += (baseyear % 4) ? 365 : 366; } if (baseday == 0) { baseday = day; } second = second + (60 * minute) + (3600 * hour) + (86400 * (day - baseday)); if (basesecond == 0) { basesecond = second; } second -= basesecond; tracebasetime += (double) 1000 * (double) second;}static void iotrace_hpl_initialize_file (FILE *tracefile, int print_tracefile_header){ char letter = '0'; char line[201]; char linetype[40]; if (disksim->traceheader == FALSE) { return; } while (1) { if (fgets(line, 200, tracefile) == NULL) { fprintf(stderr, "No 'tracedate' line in HPL trace\n"); exit(1); } sscanf(line, "%s", linetype); if (strcmp(linetype, "tracedate") == 0) { break; } } iotrace_hpl_srt_tracefile_start(line); while (letter != 0x0C) { if (fscanf(tracefile, "%c", &letter) != 1) { fprintf(stderr, "End of header information never found - end of file\n"); exit(1); } if ((print_tracefile_header) && (letter != 0x0C)) { printf("%c", letter); } }}void iotrace_initialize_file (FILE *tracefile, int traceformat, int print_tracefile_header){ if (traceformat == HPL) { iotrace_hpl_initialize_file(tracefile, print_tracefile_header); }}void iotrace_printstats (FILE *outfile){ if (disksim->iotrace_info == NULL) { return; } if (hpreads | hpwrites) { fprintf (outfile, "\n"); fprintf(outfile, "Total reads: \t%d\t%5.2f\n", hpreads, ((double) hpreads / (double) (hpreads + hpwrites))); fprintf(outfile, "Total writes: \t%d\t%5.2f\n", hpwrites, ((double) hpwrites / (double) (hpreads + hpwrites))); fprintf(outfile, "Sync Reads: \t%d\t%5.2f\t%5.2f\n", syncreads, ((double) syncreads / (double) (hpreads + hpwrites)), ((double) syncreads / (double) hpreads)); fprintf(outfile, "Sync Writes: \t%d\t%5.2f\t%5.2f\n", syncwrites, ((double) syncwrites / (double) (hpreads + hpwrites)), ((double) syncwrites / (double) hpwrites)); fprintf(outfile, "Async Reads: \t%d\t%5.2f\t%5.2f\n", asyncreads, ((double) asyncreads / (double) (hpreads + hpwrites)), ((double) asyncreads / (double) hpreads)); fprintf(outfile, "Async Writes:\t%d\t%5.2f\t%5.2f\n", asyncwrites, ((double) asyncwrites / (double) (hpreads + hpwrites)), ((double) asyncwrites / (double) hpwrites)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -