| 14 | |
| 15 | namespace traceAnalyzer { |
| 16 | class SizeDistribution { |
| 17 | /** |
| 18 | * track a few things |
| 19 | * 1. obj_size request count |
| 20 | * 2. obj_size object count |
| 21 | * 3. obj_size request count over time (heatmap plot) |
| 22 | * 4. obj_size object count over time (heatmap plot) |
| 23 | */ |
| 24 | public: |
| 25 | SizeDistribution() = default; |
| 26 | explicit SizeDistribution(std::string &output_path, int time_window) |
| 27 | : time_window_(time_window) { |
| 28 | obj_size_req_cnt_.reserve(1e6); |
| 29 | obj_size_obj_cnt_.reserve(1e6); |
| 30 | |
| 31 | turn_on_stream_dump(output_path); |
| 32 | }; |
| 33 | |
| 34 | ~SizeDistribution() { |
| 35 | ofs_stream_req.close(); |
| 36 | ofs_stream_obj.close(); |
| 37 | } |
| 38 | |
| 39 | void add_req(request_t *req); |
| 40 | |
| 41 | void dump(std::string &path_base); |
| 42 | |
| 43 | private: |
| 44 | /* request/object count of certain size, size->count */ |
| 45 | std::unordered_map<obj_size_t, uint32_t> obj_size_req_cnt_; |
| 46 | std::unordered_map<obj_size_t, uint32_t> obj_size_obj_cnt_; |
| 47 | |
| 48 | /* used to plot size distribution heatmap */ |
| 49 | const double LOG_BASE = 1.5; |
| 50 | const double log_log_base = log(LOG_BASE); |
| 51 | const int time_window_ = 300; |
| 52 | int64_t next_window_ts_ = -1; |
| 53 | |
| 54 | std::vector<uint32_t> window_obj_size_req_cnt_; |
| 55 | std::vector<uint32_t> window_obj_size_obj_cnt_; |
| 56 | |
| 57 | std::ofstream ofs_stream_req; |
| 58 | std::ofstream ofs_stream_obj; |
| 59 | |
| 60 | void turn_on_stream_dump(std::string &path_base); |
| 61 | |
| 62 | void stream_dump(); |
| 63 | }; |
| 64 | |
| 65 | } // namespace traceAnalyzer |