Skip to content

Commit

Permalink
flow_age_stats: fixed label of the last bin in histograms
Browse files Browse the repository at this point in the history
The max_age of the last bin is internally set to 0, which is confusing to user when printed out as is. Now it's labeled as "600+" (if the previous bin ends at 600).
  • Loading branch information
vaclavbartos committed Jun 12, 2024
1 parent 4c207be commit c1032d1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion flow_age_stats/flow_age_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,15 @@ int main(int argc, char **argv)
}
current = head;
while(current != NULL){
if (current->next == NULL){ // last bin - print label as "+" instead of "0"
fprintf(out, "%" PRIu64 "+\t%0.2lf%%\t%zu\n", current->max_age, ((double)(current->count_first * 100)/flow_count), current->count_first);
break;
}
fprintf(out, "%" PRIu64 "\t%0.2lf%%\t%zu\n", current->max_age, ((double)(current->count_first * 100)/flow_count), current->count_first);
if (current->next->next == NULL) {
// second-to-last bin - store the end of this bin so we can use it in the last one (to print "+" after it)
current->next->max_age = current->max_age;
}
current = current->next;
}
fclose(out);
Expand All @@ -340,7 +348,15 @@ int main(int argc, char **argv)
}
current = head;
while(current != NULL){
fprintf(out, "%" PRIu64 "\t%0.2lf\t%zu\n", current->max_age, ((double)(current->count_last * 100)/flow_count), current->count_last);
if (current->next == NULL){ // last bin - print label as "+" instead of "0"
fprintf(out, "%" PRIu64 "+\t%0.2lf%%\t%zu\n", current->max_age, ((double)(current->count_last * 100)/flow_count), current->count_last);
break;
}
fprintf(out, "%" PRIu64 "\t%0.2lf%%\t%zu\n", current->max_age, ((double)(current->count_last * 100)/flow_count), current->count_last);
if (current->next->next == NULL) {
// second-to-last bin - store the end of this bin so we can use it in the last one (to print "+" after it)
current->next->max_age = current->max_age;
}
current = current->next;
}
fclose(out);
Expand Down

0 comments on commit c1032d1

Please sign in to comment.