8 self
.total_time_to_add_req
= 0;
9 self
.total_time_to_complete_req
= 0;
12 def set_name(self
, config
, heap_type
):
14 self
.heap_type
= heap_type
18 return re
.split(r
"/|\.", self
.config
)[1]
21 return "s:%d, c:%d,h:%d,config:%s"%(self
.nserver
, self
.nclient
, self
.heap_type
, self
.config
);
34 def parse_config_params(fname
):
37 # read config file property
38 with
open(fname
, 'r') as f
:
40 line
= line
.strip('\n \t')
41 if not line
: continue;
42 if line
.startswith("client_count"):
43 nclient
+= int(line
.split('=')[-1]);
44 if line
.startswith("server_count"):
45 nserver
+= int(line
.split('=')[-1]);
47 return [nserver
, nclient
];
50 def make_aggregate_data_point(dps
, config
, heap_type
):
51 # create new aggregate point
53 # set set and k_way_heap property
54 dp
.set_name(config
, heap_type
);
58 if _dp
.config
== config
and _dp
.heap_type
== heap_type
:
59 # print _dp, config, heap_type
60 dp
.nserver
=_dp
.nserver
61 dp
.nclient
= _dp
.nclient
63 dp
.total_time_to_add_req
+= _dp
.total_time_to_add_req
64 dp
.total_time_to_complete_req
+= _dp
.total_time_to_complete_req
67 dp
.total_time_to_add_req
/= num_run
;
68 dp
.total_time_to_complete_req
/= num_run
72 def parse_data_points(filename
):
73 dps
= []; #data-points
79 with
open(filename
, 'r') as f
:
81 line
= line
.strip('\n \t')
82 if not line
: continue;
84 # file_name:1:configs/dmc_sim_8_6.conf
85 if line
.startswith("file_name"):
92 parts
= line
.split(':')
94 dp
.heap_type
= int(parts
[1]);
95 if dp
.heap_type
not in k_ways
:
96 k_ways
[dp
.heap_type
] = 1;
98 # add to the dictionary
102 params
= parse_config_params(fname
)
103 dp
.nserver
= params
[0];
104 dp
.nclient
= params
[-1];
106 elif line
.startswith("average"): # take last 2 averages
107 r
= [float(s
) for s
in line
.split(' ') if isFloat(s
)]
109 #print r, dp #if isFloat(s)
111 dp
.total_time_to_add_req
= r
[0]
113 dp
.total_time_to_complete_req
= r
[0]
121 # compute average of multiple runs
123 for config
in configs
:
126 aggr_dp
= make_aggregate_data_point(dps
, config
, k
);
127 data_per_config
.append(aggr_dp
);
128 dps_avg
.append(data_per_config
);
131 # end parse_data_points
134 def create_header(num_cols
):
135 fields
= ['nserver_nclient(config_file)','add_req', 'complete_req'];
137 #write add_req_{1, ...}
138 for i
in range(num_cols
):
139 header
= '%s %s_%i'%(header
, fields
[1], i
+2)
140 #write complete_req_{1, ...}
141 for i
in range(num_cols
):
142 header
= '%s %s_%i'%(header
, fields
[2], i
+2)
144 header
= '%s\n'%(header)
149 def create_data_line(aggr_dp
):
152 data_line
= "s:%d_c:%d "%(dp
.nserver
, dp
.nclient
);
153 # get the point-count
154 num_cols
= len(aggr_dp
);
155 # write add_req_{1, ...}
156 for i
in range(num_cols
):
157 data_line
= '%s %f'%(data_line
, aggr_dp
[i
].total_time_to_add_req
)
158 # write complete_req_{1, ...}
159 for i
in range(num_cols
):
160 data_line
= '%s %f'%(data_line
, aggr_dp
[i
].total_time_to_complete_req
)
162 data_line
= '%s\n'%(data_line)
164 # end create_data_line
167 def make_data(filename
):
168 # write the aggregated point in space separated file
169 dps
= parse_data_points(filename
);
170 if not len(dps
) : return
171 print "total points: ", len(dps
)
173 with
open('%s.dat'%(filename), 'w+') as f
:
175 f
.write(create_header(len(dps
[0])));
178 f
.write(create_data_line(aggr_dp
));
181 def main(output_file
):
183 make_data(output_file
);
186 if __name__
== "__main__":
188 if len(sys
.argv
) > 1:
189 file_name
=sys
.argv
[1].strip()