123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- #define PROGRAM_NAME "plotJittervsFill"
- #include "common.h"
- static char LogFile[250] = "InputLogFile.log";
- static int JitterThreshold_ms = 1000;
- static int Debug = 0;
- #define TRUE 1
- #define FALSE 0
- #define MIN_JITTER_THRESHOLD 1
- static void PrintHelpInfo(void)
- {
- printf("Usage: plotJittervsFill [options] -f [--file] <input log file name> -t [--jitter_threshold] <jitter threshold in ms>\n");
- printf("[options]:\n-v [--version] Print version and exit\n");
- printf("-d Debug. Prints input file line number for each data point picked up.\n");
- printf("-h [--help] [-?] Print this help screen and exit.\n");
- }
- static void HandleCmdLineArgs(
- int argc,
- char *argv[])
- {
- int argNum;
- if (argc > (int) 1) {
- for (argNum = (int) 1; argNum < argc; argNum++) {
-
- if ((strcmp(argv[argNum],"--version") == 0) ||
- (strcmp(argv[argNum],"-v") == 0)) {
-
- common_print_version();
- exit(0);
- }
- else if ((strcmp(argv[argNum],"--help") == 0) ||
- (strcmp(argv[argNum],"-h") == 0) ||
- (strcmp(argv[argNum],"-?") == 0)) {
-
- PrintHelpInfo();
- exit(0);
- }
- else if ((strcmp(argv[argNum],"--file") == 0) ||
- (strcmp(argv[argNum],"-f") == 0)) {
-
- ++argNum;
- if (argNum < argc) {
- strncpy(LogFile, argv[argNum], sizeof(LogFile));
- }
- else {
- printf("*** Input file name not specified. ***\n");
- exit(0);
- }
- }
- else if ((strcmp(argv[argNum],"--jitter_threshold") == 0) ||
- (strcmp(argv[argNum],"-t") == 0)) {
-
- ++argNum;
- JitterThreshold_ms = atoi(argv[argNum]);
- if(JitterThreshold_ms < MIN_JITTER_THRESHOLD)
- {
- printf("A jitter threshold less than %i ms is not allowed. Bye.\n",
- MIN_JITTER_THRESHOLD);
- exit(0);
- }
- }
- else if ((strcmp(argv[argNum],"-d") == 0))
- {
-
- Debug++;
- }
- else {
-
- printf("Invalid option %s\n", argv[argNum]);
- printf("Try 'plotJittervsFill --help' for more information.\n");
- exit(0);
- }
- }
- }
- return;
- }
- int main(
- int argc,
- char *argv[])
- {
- char lineBuf[1024];
- int converted;
- int lineNo = 0;
- int cnt;
- FILE *fp;
- int junkInt1, junkInt2, junkInt3;
- float junkFloat1;
- float jitter_ms;
- #define MAX_SAVE_BUFFER 1000
- int saveJitter[MAX_SAVE_BUFFER];
- int dataLineNo[MAX_SAVE_BUFFER];
- int saveJitterCnt = 0;
- int lookFor_df = FALSE;
- int dfPercent = -1;
- char junkStr1[500], junkStr2[500];
- HandleCmdLineArgs(argc, argv);
- if((fp = fopen(LogFile, "r")) == NULL)
- {
- printf("Unable to open input log file %s for read.\b", LogFile);
- perror("Error:");
- exit(1);
- }
- while(fgets(lineBuf, sizeof(lineBuf), fp) != NULL)
- {
- lineNo++;
-
-
- if((strstr(lineBuf, "%") != NULL) && (lookFor_df))
- {
- converted = sscanf(lineBuf, "%s %i %i %i %i\n",
- junkStr1, &junkInt1, &junkInt2, &junkInt3, &dfPercent);
- if(converted < 5)
- {
- printf("Line %i contains \"%%\", but expected fields not found. Skipping.\n", lineNo);
- }else
- {
-
- for(cnt = 0; cnt < saveJitterCnt; cnt++)
- {
- if(Debug)
- {
- fprintf(stderr, "%i\t%i\t%i\n", (int)dataLineNo[cnt],
- dfPercent, (int)saveJitter[cnt]);
- }else
- {
- fprintf(stderr, "%i\t%i\n", dfPercent, (int)saveJitter[cnt]);
- }
- }
- saveJitterCnt = 0;
- lookFor_df = FALSE;
- }
- }
-
- if(strstr(lineBuf, "ms") == NULL)
- {
- continue;
- }
-
- converted = sscanf(lineBuf, "%f %s %f %s\n", &junkFloat1, junkStr1, &jitter_ms, junkStr2);
- if(converted < 4)
- {
- printf("Line %i contains \"ms\", but expected fields not found. Converted %i, Skipping.",
- lineNo, converted);
- printf("1=%i, 2=%s.\n", junkInt1, junkStr1);
- continue;
- }
-
- if(abs((int)jitter_ms) > JitterThreshold_ms)
- {
-
- if(saveJitterCnt < MAX_SAVE_BUFFER)
- {
- saveJitter[saveJitterCnt] = abs((int)jitter_ms);
- dataLineNo[saveJitterCnt] = lineNo;
- saveJitterCnt++;
- lookFor_df = TRUE;
- }
- else
- {
- printf("Oops! I've run out of buffer space before I found a %% use line. Dropping itter value. Increase MAX_SAVE_BUFFER and recompile.\n");
- }
- }
- }
-
- if(lookFor_df && (dfPercent >= 0))
- {
-
- for(cnt = 0; cnt < saveJitterCnt; cnt++)
- {
- fprintf(stderr, "%i\t%i\n", dfPercent, (int)saveJitter[cnt]);
- }
- }
- return 0;
- }
|