void fifo_stats_foreach (struct fifo_stats *fifo, void (*fp) (Stats *)) { int i = 0; while (i < fifo->size) { fp (fifo_stats_get (fifo, i++)); } }
void fifo_stats_sum (struct fifo_stats *fifo, Stats * sum, int length) { memset (sum, (int) 0, sizeof (Stats)); int i = 0; while (i < fifo->size) { if (i >= length) break; Stats *tmp = fifo_stats_get (fifo, i++); sum->cpu += tmp->cpu; sum->read += tmp->read; sum->write += tmp->write; } }
void calc_acc_stats(gpointer key, Account * ac, gpointer data) { int i = 1; User_stats *us = (User_stats *) g_ptr_array_index (ac->users, 0); send_to_glib_info *internal_info = (send_to_glib_info *)data; Stats *ptr = fifo_stats_get(us->stats, 0); ac->current = *fifo_stats_get(us->stats, 0); ac->short_average = us->short_average; ac->mid_average = us->mid_average; ac->long_average = us->long_average; while (i < ac->users->len) { us = (User_stats *) g_ptr_array_index (ac->users, i++); if(ac->need_dbg){ char output_buffer[_DBGOVERNOR_BUFFER_2048]; WRITE_LOG( NULL, 1, output_buffer, _DBGOVERNOR_BUFFER_2048, " step 2-%d: proceed user stats %s, c %f, r %llu, w %llu", internal_info->log_mode, i, us->id?us->id:"Unk", fifo_stats_get(us->stats, 0)->cpu, fifo_stats_get(us->stats, 0)->read, fifo_stats_get(us->stats, 0)->write ); } sum_stats(&ac->current, fifo_stats_get(us->stats, 0)); sum_stats(&ac->short_average, &us->short_average); sum_stats(&ac->mid_average, &us->mid_average); sum_stats(&ac->long_average, &us->long_average); ptr = fifo_stats_get(us->stats, 0); } if(ac->need_dbg){ char output_buffer[_DBGOVERNOR_BUFFER_2048]; WRITE_LOG( NULL, 1, output_buffer, _DBGOVERNOR_BUFFER_2048, " step 3: summary, c %f, r %llu, w %llu", internal_info->log_mode, ac->current.cpu, ac->current.read, ac->current.write ); } }
void fifo_stats_avg (struct fifo_stats *fifo, Stats * sum, int length) { memset (sum, (int) 0, sizeof (Stats)); int i = 0; while (i < fifo->size) { if (i >= length) break; Stats *tmp = fifo_stats_get (fifo, i++); sum->cpu += tmp->cpu; sum->read += tmp->read; sum->write += tmp->write; } if (length > fifo->size) length = fifo->size; sum->cpu = sum->cpu / length; sum->read = sum->read / length; sum->write = sum->write / length; }