plotJittervsFill.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. ***********************************************************************
  3. *
  4. * Copyright: Daniel Measurement and Control, Inc.
  5. * 9753 Pine Lake Drive
  6. * Houston, TX 77055
  7. *
  8. * Created by: Vipin Malik
  9. * Released under GPL by permission of Daniel Industries.
  10. *
  11. * This software is licensed under the GPL version 2. Plese see the file
  12. * COPYING for details on the license.
  13. *
  14. * NO WARRANTY: Absolutely no claims of warranty or fitness of purpose
  15. * are made in this software. Please use at your own risk.
  16. *
  17. File: plotJittervsFill.c
  18. By: Vipin Malik
  19. About: This program reads in a jitter log file as created
  20. by the JitterTest.c program and extracts all the jitters
  21. in the file that are greater than a threshold specified
  22. as a parameter on the cmd line. It also extracts the
  23. amount of disk space at (form the "df" out that should also
  24. be present in the log file) after the jitter extracted.
  25. It writes the data to the stderr (where you may redirect it).
  26. It is suitable for plotting, as the data is written as
  27. COL1=UsedSpace COL2=Jitter
  28. $Id: plotJittervsFill.c,v 1.6 2005/11/07 11:15:21 gleixner Exp $
  29. $Log: plotJittervsFill.c,v $
  30. Revision 1.6 2005/11/07 11:15:21 gleixner
  31. [MTD / JFFS2] Clean up trailing white spaces
  32. Revision 1.5 2001/08/10 19:23:11 vipin
  33. Ready to be released under GPL! Added proper headers etc.
  34. Revision 1.4 2001/07/02 22:25:40 vipin
  35. Fixed couple of minor cosmetic typos.
  36. Revision 1.3 2001/07/02 14:46:46 vipin
  37. Added a debug option where it o/p's line numbers to debug funky values.
  38. Revision 1.2 2001/06/26 19:48:57 vipin
  39. Now prints out jitter values found at end of log file, after which
  40. no new "df" disk usage values were encountered. The last "df" disk usage
  41. encountered is printed for these orphaned values.
  42. Revision 1.1 2001/06/25 19:13:55 vipin
  43. Added new file- plotJittervsFill.c- that mines the data log file
  44. outputed from the fillFlash.sh script file and JitterTest.c file
  45. and produces output suitable to be plotted.
  46. This output plot may be examined to see visually the relationship
  47. of the Jitter vs disk usage of the fs under test.
  48. */
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <unistd.h>
  53. #include <fcntl.h>
  54. #define PROGRAM_NAME "plotJittervsFill"
  55. #include "common.h"
  56. static char LogFile[250] = "InputLogFile.log";
  57. static int JitterThreshold_ms = 1000;
  58. static int Debug = 0; /* Debug level. Each "-d" on the cmd line increases the level */
  59. #define TRUE 1
  60. #define FALSE 0
  61. #define MIN_JITTER_THRESHOLD 1 /* ms minimum jitter threshold */
  62. static void PrintHelpInfo(void)
  63. {
  64. printf("Usage: plotJittervsFill [options] -f [--file] <input log file name> -t [--jitter_threshold] <jitter threshold in ms>\n");
  65. printf("[options]:\n-v [--version] Print version and exit\n");
  66. printf("-d Debug. Prints input file line number for each data point picked up.\n");
  67. printf("-h [--help] [-?] Print this help screen and exit.\n");
  68. }
  69. /***********************************************************************
  70. * HandleCmdLineArgs
  71. * This function handles the command line arguments.
  72. * output: stack size
  73. ***********************************************************************/
  74. static void HandleCmdLineArgs(
  75. int argc, /* number of command-line arguments */
  76. char *argv[]) /* ptrs to command-line arguments */
  77. {
  78. int argNum; /* argument number */
  79. if (argc > (int) 1) {
  80. for (argNum = (int) 1; argNum < argc; argNum++) {
  81. /* The command line contains an argument. */
  82. if ((strcmp(argv[argNum],"--version") == 0) ||
  83. (strcmp(argv[argNum],"-v") == 0)) {
  84. /* Print version information and exit. */
  85. common_print_version();
  86. exit(0);
  87. }
  88. else if ((strcmp(argv[argNum],"--help") == 0) ||
  89. (strcmp(argv[argNum],"-h") == 0) ||
  90. (strcmp(argv[argNum],"-?") == 0)) {
  91. /* Print help information and exit. */
  92. PrintHelpInfo();
  93. exit(0);
  94. }
  95. else if ((strcmp(argv[argNum],"--file") == 0) ||
  96. (strcmp(argv[argNum],"-f") == 0)) {
  97. /* Set the name of the output file. */
  98. ++argNum;
  99. if (argNum < argc) {
  100. strncpy(LogFile, argv[argNum], sizeof(LogFile));
  101. }
  102. else {
  103. printf("*** Input file name not specified. ***\n");
  104. exit(0);
  105. }
  106. }
  107. else if ((strcmp(argv[argNum],"--jitter_threshold") == 0) ||
  108. (strcmp(argv[argNum],"-t") == 0)) {
  109. /* Set the file to read*/
  110. ++argNum;
  111. JitterThreshold_ms = atoi(argv[argNum]);
  112. if(JitterThreshold_ms < MIN_JITTER_THRESHOLD)
  113. {
  114. printf("A jitter threshold less than %i ms is not allowed. Bye.\n",
  115. MIN_JITTER_THRESHOLD);
  116. exit(0);
  117. }
  118. }
  119. else if ((strcmp(argv[argNum],"-d") == 0))
  120. {
  121. /* Increment debug level */
  122. Debug++;
  123. }
  124. else {
  125. /* Unknown argument. Print help information and exit. */
  126. printf("Invalid option %s\n", argv[argNum]);
  127. printf("Try 'plotJittervsFill --help' for more information.\n");
  128. exit(0);
  129. }
  130. }
  131. }
  132. return;
  133. }
  134. int main(
  135. int argc,
  136. char *argv[])
  137. {
  138. char lineBuf[1024]; /* how long a single line be? */
  139. int converted;
  140. int lineNo = 0;
  141. int cnt;
  142. FILE *fp;
  143. int junkInt1, junkInt2, junkInt3;
  144. float junkFloat1;
  145. float jitter_ms;
  146. #define MAX_SAVE_BUFFER 1000 /* How many values will be picked up while searching for
  147. a % disk full line (i.e. before they can be printed out)
  148. */
  149. int saveJitter[MAX_SAVE_BUFFER]; /* lets us record multiple jitter values that exceed
  150. our threshold till we find a "df" field- which is when
  151. we can o/p all these values.
  152. */
  153. int dataLineNo[MAX_SAVE_BUFFER]; /* The saved line #'s for the above. Printed if debug specified. */
  154. int saveJitterCnt = 0;
  155. int lookFor_df = FALSE;
  156. int dfPercent = -1; /* will be >= 0 if at least one found. The init value is a flag. */
  157. char junkStr1[500], junkStr2[500];
  158. HandleCmdLineArgs(argc, argv);
  159. if((fp = fopen(LogFile, "r")) == NULL)
  160. {
  161. printf("Unable to open input log file %s for read.\b", LogFile);
  162. perror("Error:");
  163. exit(1);
  164. }
  165. while(fgets(lineBuf, sizeof(lineBuf), fp) != NULL)
  166. {
  167. lineNo++;
  168. /* Are we looking for a "df" o/p line? (to see how full
  169. the flash is?)*/
  170. /* is there a "%" in this line? */
  171. if((strstr(lineBuf, "%") != NULL) && (lookFor_df))
  172. {
  173. converted = sscanf(lineBuf, "%s %i %i %i %i\n",
  174. junkStr1, &junkInt1, &junkInt2, &junkInt3, &dfPercent);
  175. if(converted < 5)
  176. {
  177. printf("Line %i contains \"%%\", but expected fields not found. Skipping.\n", lineNo);
  178. }else
  179. {
  180. /* Now print out the saved jitter values (in col2) with this dfPercent value as the col1. */
  181. for(cnt = 0; cnt < saveJitterCnt; cnt++)
  182. {
  183. if(Debug)
  184. {
  185. fprintf(stderr, "%i\t%i\t%i\n", (int)dataLineNo[cnt],
  186. dfPercent, (int)saveJitter[cnt]);
  187. }else
  188. {
  189. fprintf(stderr, "%i\t%i\n", dfPercent, (int)saveJitter[cnt]);
  190. }
  191. }
  192. saveJitterCnt = 0; /* all flushed. Reset for next saves. */
  193. lookFor_df = FALSE;
  194. }
  195. }
  196. /* is there a "ms" in this line?*/
  197. if(strstr(lineBuf, "ms") == NULL)
  198. {
  199. continue;
  200. }
  201. /* grab the ms jitter value */
  202. converted = sscanf(lineBuf, "%f %s %f %s\n", &junkFloat1, junkStr1, &jitter_ms, junkStr2);
  203. if(converted < 4)
  204. {
  205. printf("Line %i contains \"ms\", but expected fields not found. Converted %i, Skipping.",
  206. lineNo, converted);
  207. printf("1=%i, 2=%s.\n", junkInt1, junkStr1);
  208. continue; /* not our jitter line*/
  209. }
  210. /* Is the jitter value > threshold value? */
  211. if(abs((int)jitter_ms) > JitterThreshold_ms)
  212. {
  213. /* Found a jitter line that matches our crietrion.
  214. Now set flag to be on the look out for the next
  215. "df" output so that we can see how full the flash is.
  216. */
  217. if(saveJitterCnt < MAX_SAVE_BUFFER)
  218. {
  219. saveJitter[saveJitterCnt] = abs((int)jitter_ms); /* why keep the (ms) jitter in float */
  220. dataLineNo[saveJitterCnt] = lineNo;
  221. saveJitterCnt++;
  222. lookFor_df = TRUE;
  223. }
  224. else
  225. {
  226. 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");
  227. }
  228. }
  229. }
  230. /* Now print out any saved jitter values that were not printed out because we did not find
  231. and "df" after these were picked up. Only print if a "df" disk usage was ever found.
  232. */
  233. if(lookFor_df && (dfPercent >= 0))
  234. {
  235. /* Now print out the saved jitter values (in col2) with this dfPercent value as the col1. */
  236. for(cnt = 0; cnt < saveJitterCnt; cnt++)
  237. {
  238. fprintf(stderr, "%i\t%i\n", dfPercent, (int)saveJitter[cnt]);
  239. }
  240. }
  241. return 0;
  242. }/* end main() */