• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3  */
4 
5 #include <stdio.h>
6 #include <ctype.h>
7 #include <string.h>
8 
9 char time_str1[50];
10 char time_str2[50];
11 char name_str1[50];
12 char tmp_str[20][100];
13 
14 char out1[256];
15 char out2[256];
16 
17 FILE *f1;
18 FILE *f2;
19 FILE *f3;
20 FILE *f4;
21 
22 void write_html_head(FILE * fp);
23 void write_html_end(FILE * fp);
24 
25 char head_str[] = "\n \
26 <!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">\n \
27 <html>\n \
28 <head>\n \
29    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n \
30    <meta name=\"GENERATOR\" content=\"Mozilla/4.5 [en] (X11; I; Linux 2.2.7 i586) [Netscape]\">\n \
31 </head>\n \
32 <body>\n \
33 ";
34 /*
35 <tt></tt>&nbsp;\n \
36 <table BORDER NOSAVE >\n \
37 <tr BGCOLOR=\"#CCFFFF\" NOSAVE>\n \
38 <td NOSAVE> \n \
39 ";
40 */
41 
42 char end_str[] = "\n \
43 </table> \n \
44 <tt></tt> \n \
45 </body> \n \
46 </html> \n \
47 ";
48 
main(int argc,char ** argv)49 main(int argc, char **argv)
50 {
51 	float n1, n2, ratio;
52 	char *p, *p1, *p2;
53 	char line0[100];
54 	char line1[100];
55 	char line2[100];
56 	char line3[100];
57 	char out_line[100];
58 	char html_line[500];
59 	int i, k;
60 
61 	if (argc < 3) {
62 		printf("\nUsage: mongo_compare file1 file2 res_file\n\n");
63 		printf
64 		    ("\t<file1> should contain reiserfs or ext2 results of mogo benchmark\n");
65 		printf
66 		    ("\t<file2> should contain reiserfs or ext2 results of mogo benchmark\n");
67 		printf("\tMongo results   will be compared\n");
68 		printf
69 		    ("\t<res_file.txt>  will be contain results in the text form\n");
70 		printf
71 		    ("\t<res_file.html> will be contain results in the html form\n");
72 		exit(0);
73 	}
74 
75 	strcpy(out1, argv[3]);
76 	strcat(out1, ".txt");
77 
78 	strcpy(out2, argv[3]);
79 	strcat(out2, ".html");
80 
81 	if ((f1 = fopen(argv[1], "r")) == NULL) {
82 		fprintf(stderr, "%s: can't open %s\n", argv[0], argv[1]);
83 		return 1;
84 	}
85 
86 	if ((f2 = fopen(argv[2], "r")) == NULL) {
87 		fprintf(stderr, "%s: can't open %s\n", argv[0], argv[2]);
88 		return 1;
89 	}
90 
91 	if ((f3 = fopen(out1, "wr")) == NULL) {
92 		fprintf(stderr, "%s: can't open %s\n", argv[0], out1);
93 		return 1;
94 	}
95 
96 	if ((f4 = fopen(out2, "wr")) == NULL) {
97 		fprintf(stderr, "%s: can't open %s\n", argv[0], out2);
98 		return 1;
99 	}
100 
101 	write_html_head(f4);
102 	i = 0;
103 	while (fgets(line1, 100, f1)) {
104 		fgets(line2, 100, f2);
105 
106 		if (p = strstr(line1, "\n"))
107 			*(p + 1) = 0;
108 		if (p = strstr(line2, "\n"))
109 			*(p + 1) = 0;
110 
111 		strcpy(line3, line1);
112 		line3[strlen(line3) - 1] = 0;
113 
114 		while (strlen(line3) < 40) {
115 			strcat(line3, " ");
116 		}
117 
118 		if (strstr(line3, "MONGO_")) {
119 			fprintf(f4, "</table>\n<table BORDER NOSAVE >\n");
120 			fprintf(f4, "<tr BGCOLOR=\"#CCFFFF\" NOSAVE>");
121 			fprintf(f4, "<td NOSAVE>\n");
122 			i = 0;
123 		}
124 		if (i < 20)
125 			strcpy(tmp_str[i], line2);
126 
127 		if (strstr(line3, "FSYS=")) {
128 			fprintf(f4, "</td><td>\n");
129 			for (k = 0; k < i; k++) {
130 				fprintf(f4, "<tt>%s</tt><br>\n", tmp_str[k]);
131 			}
132 			fprintf(f4,
133 				"</td>\n <tr BGCOLOR=\"#CCFFFF\" NOSAVE><td COLSPAN=\"2\"><tt><B> %s %s </B></tt>\n",
134 				line3, line2);
135 			i = 20;
136 		} else if (NULL == strstr(line3, " :")) {
137 
138 			if (strstr(line3, "(time"))
139 				fprintf(f4,
140 					"<br><tt><center>%s</center></tt>\n",
141 					line3);
142 			else {
143 				k = 0;
144 				p = line3;
145 				while (*p++ != 0) {
146 					if (*p != ' ' && *p != '\n')
147 						k++;
148 				}
149 				if (k > 0) {
150 					fprintf(f4, "<tt>%s</tt><br>\n", line3);
151 					if (i < 20)
152 						i++;
153 				}
154 			}
155 		}
156 
157 		else if (strstr(line3, "Create"))
158 			fprintf(f4, "</td>\n");
159 
160 		line2[strlen(line2) - 1] = 0;
161 		while (strlen(line2) < 40) {
162 			strcat(line2, " ");
163 		}
164 
165 		strcat(line3, line2);
166 
167 		strcpy(out_line, line3);
168 		strcat(out_line, "\n");
169 		name_str1[0] = 0;
170 
171 		if (p1 = strstr(line1, " :")) {
172 			strcpy(time_str1, p1 + 2);
173 			strncpy(name_str1, line1, p1 - line1);
174 
175 			if (p2 = strstr(line2, " :")) {
176 				strcpy(time_str2, p2 + 2);
177 
178 				time_str1[strlen(time_str1) - 1] = 0;
179 				time_str2[strlen(time_str2) - 1] = 0;
180 
181 				sscanf(time_str1, "%f", &n1);
182 				sscanf(time_str2, "%f", &n2);
183 
184 				ratio = n1 / n2;
185 				sprintf(out_line, "%s : %6.2f / %6.2f = %.2f\n",
186 					name_str1, n1, n2, ratio);
187 
188 				fprintf(f4,
189 					"<tr><td><tt> %s &nbsp </tt></td> <td><div align=right><tt> %6.2f / %6.2f = %.2f &nbsp </tt></div></td></tr>\n",
190 					name_str1, n1, n2, ratio);
191 
192 			}
193 		}
194 
195 		fprintf(f3, "%s", out_line);
196 		line1[0] = 0;
197 		line2[0] = 0;
198 		line3[0] = 0;
199 		out_line[0] = 0;
200 	}
201 
202 	write_html_end(f4);
203 
204 	fclose(f1);
205 	fclose(f2);
206 
207 	fclose(f3);
208 	fclose(f4);
209 
210 	fflush(f3);
211 	fflush(f4);
212 }
213 
214 /*******************************************/
write_html_head(FILE * fp)215 void write_html_head(FILE * fp)
216 {
217 	fprintf(fp, "%s", head_str);
218 }
219 
220 /*******************************************/
write_html_end(FILE * fp)221 void write_html_end(FILE * fp)
222 {
223 	fprintf(fp, "%s", end_str);
224 }
225