Skip to content

Commit 820605c

Browse files
authored
Fix dropouts due to vector resize during long benchmarks (#160)
1 parent de3a5ff commit 820605c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

run_stats.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void run_stats::save_csv_one_sec(FILE *f,
282282
total_get_ops = 0;
283283
total_set_ops = 0;
284284
total_wait_ops = 0;
285-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
285+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
286286
i != m_stats.end(); i++) {
287287

288288
fprintf(f, "%u,%lu,%u.%06u,%lu,%lu,%u.%06u,%lu,%u,%u,%lu,%u.%06u\n",
@@ -308,7 +308,7 @@ void run_stats::save_csv_one_sec(FILE *f,
308308
std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_get() {
309309
std::vector<one_sec_cmd_stats> result;
310310
result.reserve(m_stats.size());
311-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
311+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
312312
i != m_stats.end(); i++) {
313313
result.push_back(i->m_get_cmd);
314314
}
@@ -318,7 +318,7 @@ std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_get() {
318318
std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_set() {
319319
std::vector<one_sec_cmd_stats> result;
320320
result.reserve(m_stats.size());
321-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
321+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
322322
i != m_stats.end(); i++) {
323323
result.push_back(i->m_set_cmd);
324324
}
@@ -328,7 +328,7 @@ std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_set() {
328328
std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_wait() {
329329
std::vector<one_sec_cmd_stats> result;
330330
result.reserve(m_stats.size());
331-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
331+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
332332
i != m_stats.end(); i++) {
333333
result.push_back(i->m_wait_cmd);
334334
}
@@ -338,9 +338,9 @@ std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_wait() {
338338
std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_totals() {
339339
std::vector<one_sec_cmd_stats> result;
340340
result.reserve(m_stats.size());
341-
for (size_t i = 0; i < m_stats.size(); i++)
341+
for (std::list<one_second_stats>::iterator i = m_stats.begin(); i != m_stats.end(); ++i)
342342
{
343-
one_second_stats current_second_stats = m_stats.at(i);
343+
one_second_stats current_second_stats = *i;
344344
one_sec_cmd_stats total_stat = one_sec_cmd_stats(current_second_stats.m_get_cmd);
345345
total_stat.merge(current_second_stats.m_set_cmd);
346346
total_stat.merge(current_second_stats.m_wait_cmd);
@@ -357,7 +357,7 @@ std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_totals() {
357357
std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_arbitrary_command( unsigned int pos ){
358358
std::vector<one_sec_cmd_stats> result;
359359
result.reserve(m_stats.size());
360-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
360+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
361361
i != m_stats.end(); i++) {
362362
result.push_back(i->m_ar_commands.at(pos));
363363
}
@@ -367,7 +367,7 @@ std::vector<one_sec_cmd_stats> run_stats::get_one_sec_cmd_stats_arbitrary_comman
367367
std::vector<unsigned int> run_stats::get_one_sec_cmd_stats_timestamp() {
368368
std::vector<unsigned int> result;
369369
result.reserve(m_stats.size());
370-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
370+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
371371
i != m_stats.end(); i++) {
372372
result.push_back(i->m_second);
373373
}
@@ -379,7 +379,7 @@ void run_stats::save_csv_one_sec_cluster(FILE *f) {
379379
fprintf(f, "\nPer-Second Benchmark Cluster Data\n");
380380
fprintf(f, "Second,SET Moved,SET Ask,GET Moved,GET Ask\n");
381381

382-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
382+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
383383
i != m_stats.end(); i++) {
384384

385385
fprintf(f, "%u,%u,%u,%u,%u\n",
@@ -453,7 +453,7 @@ void run_stats::save_csv_arbitrary_commands_one_sec(FILE *f,
453453
fprintf(f, "\n");
454454

455455
// print data
456-
for (std::vector<one_second_stats>::iterator stat = m_stats.begin();
456+
for (std::list<one_second_stats>::iterator stat = m_stats.begin();
457457
stat != m_stats.end(); stat++) {
458458

459459
fprintf(f, "%u,", stat->m_second);
@@ -644,7 +644,7 @@ void run_stats::debug_dump(void)
644644
m_start_time.tv_sec, m_start_time.tv_usec,
645645
m_end_time.tv_sec, m_end_time.tv_usec);
646646

647-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
647+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
648648
i != m_stats.end(); i++) {
649649

650650
benchmark_debug_log(" %u: get latency=%u.%ums, set latency=%u.%ums, wait latency=%u.%ums"
@@ -711,12 +711,12 @@ void run_stats::merge(const run_stats& other, int iteration)
711711

712712
// aggregate the one_second_stats vectors. this is not efficient
713713
// but it's not really important (small numbers, not realtime)
714-
for (std::vector<one_second_stats>::const_iterator other_i = other.m_stats.begin();
714+
for (std::list<one_second_stats>::const_iterator other_i = other.m_stats.begin();
715715
other_i != other.m_stats.end(); other_i++) {
716716

717717
// find ours
718718
bool merged = false;
719-
for (std::vector<one_second_stats>::iterator i = m_stats.begin();
719+
for (std::list<one_second_stats>::iterator i = m_stats.begin();
720720
i != m_stats.end(); i++) {
721721
if (i->m_second == other_i->m_second) {
722722
i->merge(*other_i);
@@ -732,7 +732,7 @@ void run_stats::merge(const run_stats& other, int iteration)
732732
}
733733

734734
if (new_stats) {
735-
sort(m_stats.begin(), m_stats.end(), one_second_stats_predicate);
735+
m_stats.sort(one_second_stats_predicate);
736736
}
737737

738738
// aggregate totals
@@ -755,7 +755,7 @@ void run_stats::summarize(totals& result) const
755755
one_second_stats totals(0);
756756
totals.setup_arbitrary_commands(m_cur_stats.m_ar_commands.size());
757757

758-
for (std::vector<one_second_stats>::const_iterator i = m_stats.begin();
758+
for (std::list<one_second_stats>::const_iterator i = m_stats.begin();
759759
i != m_stats.end(); i++) {
760760
totals.merge(*i);
761761
}

run_stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class run_stats {
9696

9797
totals m_totals;
9898

99-
std::vector<one_second_stats> m_stats;
99+
std::list<one_second_stats> m_stats;
100100

101101
// current second stats ( appended to m_stats and reset every second )
102102
one_second_stats m_cur_stats;

0 commit comments

Comments
 (0)