2 #define RFS_ASSERT(condition) \
4 fprintf(stderr, "Assertion failed: line %d, file \"%s\"\n", \
11 #define DISK_BLOCK_SIZE 4096
16 main(int argc, char ** argv)
22 int frag_num, distance, tfrag_num=0;
24 int max_block_num = -1;
29 int block_range_start, block_range_stop;
31 int format_version = 1;
32 char * p1=NULL, *p2=NULL, *p3=NULL;
38 unsigned long long distancell = 0;
39 int avg_frag_distance;
40 int avg_block_distance;
42 #define MAX_SUB_DISTANCE_NUM 50
43 int sub_distance_index;
44 int SUB_DISTANCE_NUM = 1;
45 int SUB_DISTANCE_SIZE = 1000000;
46 unsigned long long sub_distance[MAX_SUB_DISTANCE_NUM];
47 unsigned int sub_frag_num[MAX_SUB_DISTANCE_NUM], sub_block_num[MAX_SUB_DISTANCE_NUM];
48 memset (&sub_distance, 0, sizeof(sub_distance));
49 memset (&sub_frag_num, 0, sizeof(sub_frag_num));
50 memset (&sub_block_num, 0, sizeof(sub_block_num));
53 SUB_DISTANCE_NUM = atoi(argv[2]);
54 RFS_ASSERT ((SUB_DISTANCE_NUM >=1) && (SUB_DISTANCE_NUM <= MAX_SUB_DISTANCE_NUM));
58 fp = fopen (argv[1], "r");
60 printf ("can not opern %s\n", argv[1]);
66 strcpy (name, argv[1]);
67 strcat (name, ".disk");
69 fpout = fopen(name, "w");
71 printf ("can not opern %s\n", name);
76 while (fgets(buf, sizeof(buf), fp)) {
78 if ((lineno%10000)==0) { // || (lineno >630000)) {
79 fprintf(stderr, "%d lines processed\n", lineno);
83 RFS_ASSERT (buf[strlen(buf)-1]=='\n');
85 p = strstr (buf, "Size");
88 printf ("lineno %d size %d\n", lineno, size);
90 RFS_ASSERT (size == -1);
91 sscanf(p, "Size: %d", &size);
96 /* For now we ignore symbolic links */
97 if (!strncmp(buf, "Fast_link_dest", strlen("Fast_link_dest"))) {
105 RFS_ASSERT (!strcmp(buf, "BLOCKS:\n"));
106 fgets(buf, sizeof(buf), fp);
108 if (!(buf[strlen(buf)-1]=='\n')) {
109 printf ("line[%d] %s\n", lineno, buf);
111 RFS_ASSERT (buf[strlen(buf)-1]=='\n');
112 if (!strcmp(buf, "\n"))
116 RFS_ASSERT (size >= 0);
117 RFS_ASSERT (block_num == -1);
118 RFS_ASSERT (max_block_num == -1);
119 block_num = 0; /* the block number of block_range_start of current fragment */
120 last_block_num = 0; /* the block number of block_range_start of last fragment */
125 fgets(line, sizeof(line), fp);
127 RFS_ASSERT (line[strlen(line)-1]=='\n');
128 RFS_ASSERT (strstr(line, "TOTAL: "));
129 max_block_num = atoi (line+strlen("TOTAL: "));
130 i = ((size+DISK_BLOCK_SIZE-1)/DISK_BLOCK_SIZE);
131 RFS_ASSERT ((max_block_num >= i) && ((max_block_num*9/i)<10));
133 tblock_num += max_block_num;
139 //printf ("line %d %s", lineno, buf);
140 while (p && (*p!='\n')) {
141 if (format_version == 1) {
142 p1 = strchr (p, ')');
144 p2 = strchr (p, '-');
145 p3 = strchr (p, ':');
156 /* single block range */
157 if ((p2==NULL) || p2>p1) {
160 pt2 = strchr(p3, ' ');
162 pt2 = strchr(p3, '\n');
167 RFS_ASSERT (pt2!=p3);
169 block_range_start = atoi (p3);
172 sscanf(p3, "%d", &block_range_start);
174 block_range_stop = block_range_start;
178 pt = strchr(p3, '-');
181 block_range_start = atoi (p3);
183 pt2 = strchr(pt+1, ',');
185 pt2 = strchr(pt+1, '\n');
191 block_range_stop = atoi (pt+1);
194 sscanf(p3, "%d-%d", &block_range_start, &block_range_stop);
198 RFS_ASSERT (block_range_start >0);
199 RFS_ASSERT (block_range_stop >= block_range_start);
201 block_num += (block_range_stop - block_range_start+1);
203 if (block_range_start != (last_block+1)) {
207 sub_distance_index = (block_num-1) * SUB_DISTANCE_NUM/max_block_num;
208 sub_block_num[sub_distance_index] += block_num - last_block_num;
209 last_block_num = block_num;
210 //printf ("block_num %d SUB_DISTANCE_NUM %d max_block_num %d index %d\n", block_num, SUB_DISTANCE_NUM,
211 //max_block_num, sub_distance_index);
212 RFS_ASSERT ((sub_distance_index>=0) && (sub_distance_index<SUB_DISTANCE_NUM));
215 if (block_range_start > last_block+1) {
216 distance += block_range_start - (last_block+1);
218 sub_distance[sub_distance_index] += block_range_start - (last_block+1);
221 distance += (last_block+1)-block_range_start;
223 sub_distance[sub_distance_index] += (last_block+1)-block_range_start ;
227 if (distance >= 1000000000) {
228 printf ("line[%d] %s, block_range_start %d last_block %d\n", lineno, buf, block_range_start, last_block);
231 fprintf(fpout, "%d %d\n", last_block, block_range_start);
233 //printf ("range_start %d last_block %d distance %d\n",
234 //block_range_start, last_block, distance);
236 sub_frag_num[sub_distance_index] ++;
240 last_block = block_range_stop;
241 if (last_block > max_block)
242 max_block = last_block;
244 p = strchr (p3, '(');
246 p = strchr (p3, ' ');
250 //printf ("FRAG_NUM %d DISTANCE %d\n", frag_num, distance);
251 tfrag_num += frag_num;
252 distancell += distance;
263 RFS_ASSERT (td_MB < 1000000000);
270 if (tfrag_num != file_num) {
271 RFS_ASSERT ((distancell /(tfrag_num-file_num)) < 1000000000);
272 RFS_ASSERT ((distancell /(tblock_num-file_num)) < 1000000000);
273 avg_frag_distance = distancell/(tfrag_num-file_num);
274 avg_block_distance = distancell/(tblock_num-file_num);
276 avg_frag_distance =0;
277 avg_block_distance =0;
279 RFS_ASSERT ((distancell /1000000) < 1000000000);
280 td_MB = distancell/1000000;
281 td = distancell%1000000;
284 for (i=0; i<SUB_DISTANCE_NUM; i++) {
285 printf("sub[%d] block_num %d frag_num %d distance %d\n", i, sub_block_num[i], sub_frag_num[i], sub_distance[i]/1000000);
290 distancell *=1000000;
292 distancell /= (tfrag_num-file_num);
293 if (distancell > 1000000000) {
294 printf ("error 4\n");
297 avg_frag_distance = distancell;
300 distancell *=1000000;
302 distancell /= (tblock_num-file_num);
303 if (distancell > 1000000000) {
304 printf ("error 4\n");
307 avg_block_distance = distancell;
310 printf("****total FRAG_NUM %d td_MB %d td %d tblock_num %d max_blockno %d file_num %d avg_frag_distance %d avg_block_distance %d\n", tfrag_num, td_MB, td, tblock_num, max_block, file_num, avg_frag_distance, avg_block_distance);