Skip to content

Commit 4e050e5

Browse files
committed
refactor: Optimize popularity tracking in traceAnalyzer
* Updated the post_processing method to use std::min for safer indexing of sorted frequency. * Removed unused variables from the Popularity class to clean up the code.
1 parent dbf8423 commit 4e050e5

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

libCacheSim/traceAnalyzer/analyzer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "analyzer.h"
66

7-
#include <algorithm> // std::make_heap, std::pop_heap, std::push_heap, std::sort_heap
7+
#include <algorithm> // std::make_heap, std::min, std::pop_heap, std::push_heap, std::sort_heap
88
#include <vector> // std::vector
99

1010
#include "utils/include/utils.h"
@@ -355,8 +355,9 @@ void traceAnalyzer::TraceAnalyzer::post_processing() {
355355

356356
if (option_.popularity) {
357357
popularity_stat_ = new Popularity(obj_map_);
358-
auto sorted_freq = popularity_stat_->get_sorted_freq();
359-
for (int i = 0; i < track_n_popular_; i++) {
358+
auto &sorted_freq = popularity_stat_->get_sorted_freq();
359+
int n = std::min(track_n_popular_, (int)sorted_freq.size());
360+
for (int i = 0; i < n; i++) {
360361
popular_cnt_[i] = sorted_freq[i];
361362
}
362363
}

libCacheSim/traceAnalyzer/popularity.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,4 @@ void Popularity::run(obj_info_map_type &obj_map) {
8585
has_run = true;
8686
}
8787

88-
vector<uint32_t> freq_vec_{};
89-
double slope_, intercept_, r2_;
90-
bool has_run = false;
9188
}; // namespace traceAnalyzer

0 commit comments

Comments
 (0)