Loading storaged/include/storaged_info.h +1 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ using namespace storaged_proto; class storage_info_t { protected: FRIEND_TEST(storaged_test, storage_info_t); FRIEND_TEST(storaged_test, storage_info_t_proto); // emmc lifetime uint16_t eol; // pre-eol (end of life) information uint16_t lifetime_a; // device life time estimation (type A) Loading storaged/storaged_info.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -157,11 +157,14 @@ void storage_info_t::update_perf_history(uint32_t bw, return; } recent_perf.erase(recent_perf.begin() + nr_samples, recent_perf.end()); if (nr_samples < recent_perf.size()) { recent_perf.erase(recent_perf.begin() + nr_samples, recent_perf.end()); } uint32_t daily_avg_bw = accumulate(recent_perf.begin(), recent_perf.begin() + nr_samples, 0) / nr_samples; uint32_t daily_avg_bw = 0; if (!recent_perf.empty()) { daily_avg_bw = accumulate(recent_perf.begin(), recent_perf.end(), 0) / recent_perf.size(); } day_start_tp = tp - chrono::seconds(duration_cast<chrono::seconds>( tp.time_since_epoch()).count() % DAY_TO_SEC); Loading @@ -176,6 +179,7 @@ void storage_info_t::update_perf_history(uint32_t bw, return; } DCHECK(nr_days > 0); uint32_t week_avg_bw = accumulate(daily_perf.begin(), daily_perf.begin() + nr_days, 0) / nr_days; Loading storaged/tests/storaged_test.cpp +25 −0 Original line number Diff line number Diff line Loading @@ -416,6 +416,31 @@ TEST(storaged_test, storage_info_t) { } } TEST(storaged_test, storage_info_t_proto) { storage_info_t si; si.day_start_tp = {}; IOPerfHistory proto; proto.set_nr_samples(10); proto.set_day_start_sec(0); si.load_perf_history_proto(proto); // Skip ahead > 1 day, with no data points in the previous day. time_point<system_clock> stp; stp += hours(36); si.update_perf_history(100, stp); vector<int> history = si.get_perf_history(); EXPECT_EQ(history.size(), 63UL); EXPECT_EQ(history[0], 1); EXPECT_EQ(history[1], 7); EXPECT_EQ(history[2], 52); EXPECT_EQ(history[3], 100); for (size_t i = 4; i < history.size(); i++) { EXPECT_EQ(history[i], 0); } } TEST(storaged_test, uid_monitor) { uid_monitor uidm; Loading Loading
storaged/include/storaged_info.h +1 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ using namespace storaged_proto; class storage_info_t { protected: FRIEND_TEST(storaged_test, storage_info_t); FRIEND_TEST(storaged_test, storage_info_t_proto); // emmc lifetime uint16_t eol; // pre-eol (end of life) information uint16_t lifetime_a; // device life time estimation (type A) Loading
storaged/storaged_info.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -157,11 +157,14 @@ void storage_info_t::update_perf_history(uint32_t bw, return; } recent_perf.erase(recent_perf.begin() + nr_samples, recent_perf.end()); if (nr_samples < recent_perf.size()) { recent_perf.erase(recent_perf.begin() + nr_samples, recent_perf.end()); } uint32_t daily_avg_bw = accumulate(recent_perf.begin(), recent_perf.begin() + nr_samples, 0) / nr_samples; uint32_t daily_avg_bw = 0; if (!recent_perf.empty()) { daily_avg_bw = accumulate(recent_perf.begin(), recent_perf.end(), 0) / recent_perf.size(); } day_start_tp = tp - chrono::seconds(duration_cast<chrono::seconds>( tp.time_since_epoch()).count() % DAY_TO_SEC); Loading @@ -176,6 +179,7 @@ void storage_info_t::update_perf_history(uint32_t bw, return; } DCHECK(nr_days > 0); uint32_t week_avg_bw = accumulate(daily_perf.begin(), daily_perf.begin() + nr_days, 0) / nr_days; Loading
storaged/tests/storaged_test.cpp +25 −0 Original line number Diff line number Diff line Loading @@ -416,6 +416,31 @@ TEST(storaged_test, storage_info_t) { } } TEST(storaged_test, storage_info_t_proto) { storage_info_t si; si.day_start_tp = {}; IOPerfHistory proto; proto.set_nr_samples(10); proto.set_day_start_sec(0); si.load_perf_history_proto(proto); // Skip ahead > 1 day, with no data points in the previous day. time_point<system_clock> stp; stp += hours(36); si.update_perf_history(100, stp); vector<int> history = si.get_perf_history(); EXPECT_EQ(history.size(), 63UL); EXPECT_EQ(history[0], 1); EXPECT_EQ(history[1], 7); EXPECT_EQ(history[2], 52); EXPECT_EQ(history[3], 100); for (size_t i = 4; i < history.size(); i++) { EXPECT_EQ(history[i], 0); } } TEST(storaged_test, uid_monitor) { uid_monitor uidm; Loading