📄 trpr.cpp
字号:
} // Create & init new "preset" flow from description Flow* theFlow = new Flow(true); if (!theFlow) { perror("trpr: Error allocating memory for flow"); exit(-1); } if (!theFlow->InitFromDescription(argv[i++])) { fprintf(stderr, "trpr: Error parsing \"flow\" description!\n"); usage(); exit(1); } flowList.Append(theFlow); fprintf(stderr, "trpr: Adding flow: "); theFlow->PrintDescription(stderr); fprintf(stderr, "\n"); } else if (!strcmp("replay", argv[i])) { replay = true; realTime = true; i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"replay\" arguments!\n"); usage(); exit(-1); } replayFactor = atof(argv[i]); i++; } else if (!strcmp("absolute", argv[i])) { normalize = false; i++; } else if (!strcmp("range", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"range\" arguments!\n"); usage(); exit(-1); } char *ptr = strchr(argv[i], ':'); if (ptr) { *ptr++ = '\0'; startTime = atof(argv[i]); stopTime = atof(ptr); } else { startTime = atof(argv[i]); stopTime = -1.0; // startTime only } i++; } else if (!strncmp("multi", argv[i], 5)) { i++; multiplot = true; } else if (!strncmp("ramp", argv[i], 5)) { i++; stairStep = false; } else if (!strcmp("drec", argv[i])) { i++; traceFormat = DREC; } else if (!strcmp("mgen", argv[i])) { i++; traceFormat = DREC; } else if (!strcmp("ns", argv[i])) { i++; traceFormat = NS; //domain = NUM; } else if (!strncmp("real", argv[i], 4)) { i++; realTime = true; } else if (!strcmp("rate", argv[i])) { i++; plotMode = RATE; } else if (!strcmp("latency", argv[i])) { i++; plotMode = LATENCY; } else if (!strncmp("inter", argv[i], 5)) { i++; plotMode = INTERARRIVAL; } else if (!strncmp("drops", argv[i], 4)) { i++; plotMode = DROPS; } else if (!strncmp("loss", argv[i], 5)) { i++; plotMode = LOSS2; // we're using LOSS2 as our default loss tracking algorithm } else if (!strncmp("loss2", argv[i], 5)) { i++; plotMode = LOSS; } else if (!strncmp("velocity", argv[i], 5)) { i++; plotMode = VELOCITY; } else if (!strcmp("raw", argv[i])) { i++; use_gnuplot = false; } else if (!strcmp("key", argv[i])) { i++; print_key = true; } else if (!strcmp("png", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"png\" arguments!\n"); usage(); exit(-1); } png_file = argv[i++]; } else if (!strcmp("post", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"post\" arguments!\n"); usage(); exit(-1); } post_file = argv[i++]; } else if (!strcmp("input", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"input\" arguments!\n"); usage(); exit(-1); } input_file = argv[i++]; } else if (!strcmp("output", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"output\" arguments!\n"); usage(); exit(-1); } output_file = argv[i++]; } else if (!strcmp("auto", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"auto\" arguments!\n"); usage(); exit(-1); } // Create & init new automatcher flow from description Flow* theFlow = new Flow(true); if (!theFlow) { perror("trpr: Error allocating memory for flow"); exit(-1); } if (!theFlow->InitFromDescription(argv[i++])) { fprintf(stderr, "trpr: Error parsing \"auto\" flow description!\n"); usage(); exit(1); } autoList.Append(theFlow); fprintf(stderr, "trpr: Adding autoMatcher: "); theFlow->PrintDescription(stderr); fprintf(stderr, "\n"); } else if (!strncmp("ex", argv[i], 2)) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"exclude\" arguments!\n"); usage(); exit(-1); } // Create & init new automatcher flow from description Flow* theFlow = new Flow(true); if (!theFlow) { perror("trpr: Error allocating memory for flow"); exit(-1); } if (!theFlow->InitFromDescription(argv[i++])) { fprintf(stderr, "trpr: Error parsing \"exclude\" flow description!\n"); usage(); exit(1); } excludeList.Append(theFlow); fprintf(stderr, "trpr: Adding exclusion filter: "); theFlow->PrintDescription(stderr); fprintf(stderr, "\n"); } else if (!strcmp("link", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"link\" arguments!\n"); usage(); exit(-1); } char *ptr = strchr(argv[i], ','); if (ptr == argv[i]) { *ptr++ = '\0'; linkSrc = NULL; linkDst = ptr; // dst tracepoint only } else if (ptr) { *ptr++ = '\0'; linkSrc = argv[i]; linkDst = ptr; } else { linkSrc = argv[i]; // src tracepoint only linkDst = NULL; } i++; } else if (!strcmp("send", argv[i])) { i++; eventMask = SEND; } else if (!strcmp("recv", argv[i])) { i++; eventMask = RECV; } else if (!strcmp("offset", argv[i])) { i++; if (i >= argc) { fprintf(stderr, "trpr: Insufficient \"exclude\" arguments!\n"); usage(); exit(-1); } int hour, min; float sec; if (3 != sscanf(argv[i], "%d:%d:%f", &hour, &min, &sec)) { fprintf(stderr, "trpr: Error parsing \"exclude\" flow description!\n"); usage(); exit(1); } offsetTime = (double)(hour*3600 + 60*min) + sec; i++; } else if (!strncmp("sum", argv[i], 3)) { summarize = true; i++; } else if (!strncmp("histogram", argv[i], 3)) { make_histogram = true; i++; } else if (!strcmp("version", argv[i])) { exit(0); } else { fprintf(stderr, "trpr: Invalid command: %s\n", argv[i]); usage(); exit(-1); } } // Validate command combinations switch(plotMode) { case LOSS: case LOSS2: if ((windowSize == 0.0)) { fprintf(stderr, "trpr: LOSS plots require non-zero window size!\n"); exit(-1); } if (DREC != traceFormat) { fprintf(stderr, "trpr: LOSS and LATENCY plots currently " "available for \"drec\" only.\n"); exit(-1); } break; case LATENCY: case VELOCITY: if (DREC != traceFormat) { fprintf(stderr, "trpr: LATENCY and VELOCITY plots currently " "available for \"drec\" only.\n"); exit(-1); } case INTERARRIVAL: if (use_default_window) windowSize = 0.0; break; default: break; } if (linkSrc || linkDst) { if (!strcmp(linkSrc, "X")) linkSrc = NULL; if (!strcmp(linkDst, "X")) linkDst = NULL; if (DREC == traceFormat) { fprintf(stderr, "trpr: \"link\" tracepoint command not applicable to \"drec\"!\n"); exit(-1); } else if (TCPDUMP == traceFormat) { fprintf(stderr, "trpr: \"link\" tracepoint command not yet supported for \"tcpdump\"!\n"); exit(-1); } else { // NS link or node tracepoint defined by node ids if (linkSrc) link.SetSrc(linkSrc); if (linkDst) link.SetDst(linkDst); } } // Init flows in lists as needed Flow* f = flowList.Head(); while(f) { if (LOSS2 == plotMode) f->InitLossTracker2(windowSize); f = f->Next(); } f = autoList.Head(); while(f) { if (LOSS2 == plotMode) f->InitLossTracker2(windowSize); f = f->Next(); } // Open input trace file FILE* infile; if (input_file) { if(!(infile = fopen(input_file, "r"))) { perror("trpr: Error opening input file"); usage(); exit(-1); } } else { fprintf(stderr, "trpr: Using stdin for input ...\n"); infile = stdin; } // Open output file FILE* outfile = NULL; char temp_file[PATH_MAX]; if (output_file) { strcpy(temp_file, output_file); if (use_gnuplot) strcat(temp_file, ".tmp"); if(!(outfile = fopen(temp_file, "w+"))) { perror("trpr: Error opening output file"); usage(); exit(-1); } } // Print comment line with key to data columns if (outfile && print_key) { fprintf(outfile, "#Time"); Flow* next = flowList.Head(); while (next) { fprintf(outfile, ", "); next->PrintDescription(outfile); next = next->Next(); } fprintf(outfile, "\n"); } double updateWindow = 1.0; if (windowSize > 0.0) updateWindow = windowSize; double theTime = updateWindow; double windowStart = -1.0; double windowEnd = -1.0; double minTime = 0.0; double maxTime = historyDepth; double refTime = 0.0; double lastTime = 0.0; bool firstTime = true; DrecEventParser
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -