StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
blastSFS.C
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <time.h>
6 
7 #include <SUNRT/clock.h>
8 #include "sfs_lib.h"
9 
10 #define BUFFSZ 100*1024*1024
11 
12 
13 int main(int argc, char *argv[])
14 {
15  record_time();
16 
17  if(argc < 2) {
18  printf("%s filename\n",argv[0]);
19  return 0;
20  }
21 
22  // 100 mb...
23  printf("Buffer size %d bytes\n",BUFFSZ);
24 
25  char head[256];
26  SFS_File *file = (SFS_File *)head;
27 
28  char *buff = (char *)malloc(BUFFSZ + 8*1024);
29  if(!buff) {
30  printf("Error in malloc\n");
31  }
32 
33  unsigned int buffx = (unsigned int) buff;
34 
35  buffx /= 8*1024;
36  buffx *= 8*1024;
37  if(buffx != (unsigned int)buff) {
38  buffx += 8*1024;
39  printf("new 0x%x / old 0x%x\n",buffx,(unsigned int)buff);
40  buff = (char *)buffx;
41  }
42 
43  for(int i=0;i<BUFFSZ;i++) {
44  buff[i] = i % 256;
45  }
46 
47  double t = record_time();
48  printf("setup: %10.8f secs\n", t);
49 
50  double ltime = 0;
51  double etime = 0;
52  double sent = 0;
53  double eventsz = 0;
54  char fn[255];
55  int filen=0;
56 
57  char *fp;
58  srand(time(NULL));
59 
60  int fd=-1;
61 
62  char mntname[256];
63  for(int ii=0;ii>=0;ii++) {
64  filen++;
65 
66  if(ii % 1000 == 0) {
67  if(ii > 0) close(fd);
68 
69  sprintf(mntname, "%s_%d",argv[1], ii/1000);
70  fd = open(mntname, O_WRONLY | O_CREAT, 0666);
71 
72  char seedbuff[1000];
73  SFS_desc desc;
74  sfs_create_mimage(&desc, seedbuff, 1000);
75 
76  write(fd, seedbuff, desc.sz);
77  }
78 
79  //sprintf(fn, "/event_%d",filen);
80  // mkdir(fn,0777);
81 
82  eventsz = 0;
83  fp = buff;
84 
85  for(int detn=0;detn<10;detn++) {
86  //sprintf(fn,"/event_%d/det_%d",filen,detn);
87  //mkdir(fn,0777);
88 
89  for(int subn=0;subn<10;subn++) {
90  if(subn == 0)
91  sprintf(fn, "/event_%d/det_%d/sub_%d",filen,detn,subn);
92  else
93  sprintf(fn, "sub_%d",subn);
94 
95  float rnd = ((float)rand()/(float)RAND_MAX) * 5000.0;
96  int fsz = 5*1024/2;
97  fsz = (int)rnd + fsz;
98  fsz /= 4;
99  fsz *= 4; // round to integer size...
100 
101  // fsz = 4;
102 
103  sfs_genfilerec(fn, fsz, file);
104 
105 
106  if(fd <0) perror("Bad file?: ");
107 
108  int ret = write(fd, (char *)file, file->head_sz);
109  if(ret != file->head_sz) perror("Bad write?: ");
110 
111  ret = write(fd, (char *)fp, seeksize(file->sz));
112  if(ret != seeksize(file->sz)) perror("Bad write?: ");
113 
114  fp += fsz;
115 
116  eventsz += fsz;
117  }
118  }
119 
120  t = record_time();
121  etime += t;
122  sent += eventsz;
123 
124  if(etime - ltime > 10) {
125  ltime = etime;
126 
127  double rate = (sent / (1e6*etime));
128  double lrate = ((double)eventsz) / (1e6 * t);
129 
130  printf("%6.2f %6.2f\n",lrate, rate);
131  }
132  }
133 
134  printf("sent = %d\n",(int)sent);
135 }