-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetconf.cc
155 lines (130 loc) · 3.84 KB
/
getconf.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <string>
#include <math.h>
#include "calcdb.h"
using namespace std;
#define ITSZ sizeof(int)
char input[300]; //input file name
char confn[300];
int use_seq = 1;
void parse_args(int argc, char **argv)
{
extern char * optarg;
int i;
char c;
if (argc < 2){
cout << "usage: getconf -i<infile> -o<outfile>\n";
}
else{
//while ((c=getopt(argc,argv,"ai:o:"))!=-1){
//Dbase_Ctrl_Blk::binary_input = false;
for (i=1; i < argc; ++i){
//cout << argv[i] << endl;
c = argv[i][1];
switch(c){
case 'a': //work on assoc
use_seq = 0;
printf("USE SEQ = 0\n");
break;
// case 'b':
// Dbase_Ctrl_Blk::binary_input = true;
// break;
// case 'z':
// Dbase_Ctrl_Blk::nooffset = true;
// break;
case 'i':
sprintf(input,"%s.data",argv[++i]);
break;
case 'o':
sprintf(confn, "%s.conf", argv[++i]);
break;
}
}
}
}
int main (int argc, char **argv)
{
parse_args(argc, argv);
int DBASE_NUM_TRANS=0;
int DBASE_MAXITEM=0;
int DBASE_NUM_CUST=0;
int DBASE_MINTRANS=0;
int DBASE_MAXTRANS=0;
float DBASE_AVG_TRANS_SZ=0;
float DBASE_AVG_CUST_SZ=0;
int i;
int custid, tid, nitem;
int *buf;
int oldcustid=-1;
int oldtcnt = 0;
int tsizesum = 0;
int tcustsum = 0;
int tsizesq = 0;
int maxnitem = 0;
Dbase_Ctrl_Blk *DCB = new Dbase_Ctrl_Blk(input);
DCB->get_first_blk();
DCB->get_next_trans(buf, nitem, tid, custid);
DBASE_MINTRANS = custid;
while (!DCB->eof()){
//printf ("%d %d %d\n", custid, tid, nitem);
DBASE_MAXTRANS = custid;
if (use_seq){
if (oldcustid != custid){
tcustsum += DBASE_NUM_TRANS - oldtcnt;
oldtcnt = DBASE_NUM_TRANS;
DBASE_NUM_CUST++;
oldcustid = custid;
}
}
DBASE_NUM_TRANS++;
tsizesum += nitem;
if (nitem > maxnitem) maxnitem = nitem;
tsizesq += (nitem*nitem);
for (i=0; i < nitem; i++)
if (buf[i] > DBASE_MAXITEM) DBASE_MAXITEM = buf[i];
DCB->get_next_trans(buf, nitem, tid, custid);
}
tcustsum += DBASE_NUM_TRANS - oldtcnt;
DBASE_MAXITEM++;
if (use_seq) DBASE_AVG_CUST_SZ = (1.0*tcustsum)/DBASE_NUM_CUST;
DBASE_AVG_TRANS_SZ = (1.0*tsizesum)/DBASE_NUM_TRANS;
double trans_sq_avg = (1.0*tsizesq)/DBASE_NUM_TRANS;
double stddev = sqrt(trans_sq_avg -
(DBASE_AVG_TRANS_SZ*DBASE_AVG_TRANS_SZ));
//write config info to new file
int conffd;
if ((conffd = open(confn, (O_WRONLY|O_CREAT), 0666)) < 0){
perror("Can't open out file");
exit (errno);
}
if (use_seq){
write(conffd,(char *)&DBASE_NUM_CUST,ITSZ);
write(conffd,(char *)&DBASE_MAXITEM,ITSZ);
write(conffd,(char *)&DBASE_AVG_CUST_SZ, sizeof(float));
write(conffd,(char *)&DBASE_AVG_TRANS_SZ, sizeof(float));
write(conffd,(char *)&DBASE_NUM_TRANS,ITSZ);
write(conffd,(char *)&DBASE_MINTRANS,ITSZ);
write(conffd,(char *)&DBASE_MAXTRANS,ITSZ);
}
else{
write(conffd,(char *)&DBASE_NUM_TRANS,ITSZ);
write(conffd,(char *)&DBASE_MAXITEM,ITSZ);
write(conffd,(char *)&DBASE_AVG_TRANS_SZ, sizeof(float));
write(conffd,(char *)&DBASE_MINTRANS,ITSZ);
write(conffd,(char *)&DBASE_MAXTRANS,ITSZ);
}
close(conffd);
printf("CONF %d %d %f %f %d %d %d %f %d\n", DBASE_NUM_CUST, DBASE_MAXITEM,
DBASE_AVG_CUST_SZ, DBASE_AVG_TRANS_SZ, DBASE_NUM_TRANS,
DBASE_MINTRANS, DBASE_MAXTRANS, stddev, maxnitem);
delete DCB;
exit(0);
}