@@ -89,8 +89,76 @@ void traceAnalyzer::TraceAnalyzer::cleanup() {
8989void traceAnalyzer::TraceAnalyzer::run () {
9090 if (has_run_) return ;
9191
92+ auto dump_outputs = [&]() {
93+ ofstream ofs (output_path_ + " .stat" , ios::out | ios::app);
94+ ofs << gen_stat_str () << endl;
95+ ofs.close ();
96+
97+ if (ttl_stat_ != nullptr ) {
98+ ttl_stat_->dump (output_path_);
99+ }
100+
101+ if (req_rate_stat_ != nullptr ) {
102+ req_rate_stat_->dump (output_path_);
103+ }
104+
105+ if (reuse_stat_ != nullptr ) {
106+ reuse_stat_->dump (output_path_);
107+ }
108+
109+ if (size_stat_ != nullptr ) {
110+ size_stat_->dump (output_path_);
111+ }
112+
113+ if (access_stat_ != nullptr ) {
114+ access_stat_->dump (output_path_);
115+ }
116+
117+ if (popularity_stat_ != nullptr ) {
118+ popularity_stat_->dump (output_path_);
119+ }
120+
121+ if (popularity_decay_stat_ != nullptr ) {
122+ popularity_decay_stat_->dump (output_path_);
123+ }
124+
125+ if (prob_at_age_ != nullptr ) {
126+ prob_at_age_->dump (output_path_);
127+ }
128+
129+ if (lifetime_stat_ != nullptr ) {
130+ lifetime_stat_->dump (output_path_);
131+ }
132+
133+ if (create_future_reuse_ != nullptr ) {
134+ create_future_reuse_->dump (output_path_);
135+ }
136+
137+ // if (write_reuse_stat_ != nullptr) {
138+ // write_reuse_stat_->dump(output_path_);
139+ // }
140+
141+ // if (write_future_reuse_stat_ != nullptr) {
142+ // write_future_reuse_stat_->dump(output_path_);
143+ // }
144+
145+ if (scan_detector_ != nullptr ) {
146+ scan_detector_->dump (output_path_);
147+ }
148+
149+ has_run_ = true ;
150+ };
151+
92152 request_t *req = new_request ();
93153 read_one_req (reader_, req);
154+ if (!req->valid ) {
155+ start_ts_ = 0 ;
156+ end_ts_ = 0 ;
157+ post_processing ();
158+ free_request (req);
159+ dump_outputs ();
160+ return ;
161+ }
94162 start_ts_ = req->clock_time ;
95163 int32_t curr_time_window_idx = 0 ;
96164 int next_time_window_ts = time_window_;
@@ -226,67 +294,35 @@ void traceAnalyzer::TraceAnalyzer::run() {
226294
227295 free_request (req);
228296
229- ofstream ofs (" stat" , ios::out | ios::app);
230- ofs << gen_stat_str () << endl;
231- ofs.close ();
232-
233- if (ttl_stat_ != nullptr ) {
234- ttl_stat_->dump (output_path_);
235- }
236-
237- if (req_rate_stat_ != nullptr ) {
238- req_rate_stat_->dump (output_path_);
239- }
240-
241- if (reuse_stat_ != nullptr ) {
242- reuse_stat_->dump (output_path_);
243- }
244-
245- if (size_stat_ != nullptr ) {
246- size_stat_->dump (output_path_);
247- }
248-
249- if (access_stat_ != nullptr ) {
250- access_stat_->dump (output_path_);
251- }
252-
253- if (popularity_stat_ != nullptr ) {
254- popularity_stat_->dump (output_path_);
255- }
256-
257- if (popularity_decay_stat_ != nullptr ) {
258- popularity_decay_stat_->dump (output_path_);
259- }
260-
261- if (prob_at_age_ != nullptr ) {
262- prob_at_age_->dump (output_path_);
263- }
264-
265- if (lifetime_stat_ != nullptr ) {
266- lifetime_stat_->dump (output_path_);
267- }
268-
269- if (create_future_reuse_ != nullptr ) {
270- create_future_reuse_->dump (output_path_);
271- }
272-
273- // if (write_reuse_stat_ != nullptr) {
274- // write_reuse_stat_->dump(output_path_);
275- // }
276-
277- // if (write_future_reuse_stat_ != nullptr) {
278- // write_future_reuse_stat_->dump(output_path_);
279- // }
280-
281- if (scan_detector_ != nullptr ) {
282- scan_detector_->dump (output_path_);
283- }
284-
285- has_run_ = true ;
297+ dump_outputs ();
286298}
287299
288300string traceAnalyzer::TraceAnalyzer::gen_stat_str () {
289301 stat_ss_.clear ();
302+ if (n_req_ == 0 ) {
303+ stat_ss_ << setprecision (4 ) << fixed << " dat: " << reader_->trace_path
304+ << " \n "
305+ << " number of requests: 0, number of objects: 0\n "
306+ << " number of req GiB: 0.0000, number of obj GiB: 0.0000\n "
307+ << " compulsory miss ratio (req/byte): 0.0000/0.0000\n "
308+ << " object size weighted by req/obj: 0/0\n "
309+ << " frequency mean: 0.0000\n "
310+ << " time span: 0(0.0000 day)\n "
311+ << " write: 0(0.0000), overwrite: 0(0.0000), del:0(0.0000)\n "
312+ << " X-hit (number of obj accessed X times): " ;
313+ for (int i = 0 ; i < track_n_hit_; i++) {
314+ stat_ss_ << " 0(0.0000), " ;
315+ }
316+ stat_ss_ << " \n " ;
317+
318+ stat_ss_ << " freq (fraction) of the most popular obj: " ;
319+ for (int i = 0 ; i < track_n_popular_; i++) {
320+ stat_ss_ << " 0(0.0000), " ;
321+ }
322+ stat_ss_ << " \n " ;
323+ return stat_ss_.str ();
324+ }
325+
290326 double cold_miss_ratio = (double )obj_map_.size () / (double )n_req_;
291327 double byte_cold_miss_ratio =
292328 (double )sum_obj_size_obj / (double )sum_obj_size_req;
@@ -354,7 +390,7 @@ void traceAnalyzer::TraceAnalyzer::post_processing() {
354390 }
355391 }
356392
357- if (option_.popularity ) {
393+ if (option_.popularity && !obj_map_. empty () ) {
358394 popularity_stat_ = new Popularity (obj_map_);
359395 auto &sorted_freq = popularity_stat_->get_sorted_freq ();
360396 int n = std::min (track_n_popular_, (int )sorted_freq.size ());
0 commit comments