+static void output_csv(struct node *nodes, unsigned long nnodes)
+{
+ unsigned long i;
+
+ printf("rank, count\n");
+ for (i = 0; i < nnodes; i++)
+ printf("%lu, %lu\n", i, nodes[i].hits);
+}
+
+static void output_normal(struct node *nodes, unsigned long nnodes,
+ unsigned long nranges)
+{
+ unsigned long i, j, cur_vals, interval_step, next_interval, total_vals;
+ unsigned long blocks = percentage * nnodes / 100;
+ double hit_percent_sum = 0;
+ unsigned long long hit_sum = 0;
+ double perc, perc_i;
+ struct output_sum *output_sums;
+
+ interval_step = (nnodes - 1) / output_nranges + 1;
+ next_interval = interval_step;
+ output_sums = malloc(output_nranges * sizeof(struct output_sum));
+
+ for (i = 0; i < output_nranges; i++) {
+ output_sums[i].output = 0.0;
+ output_sums[i].nranges = 0;
+ }
+
+ j = total_vals = cur_vals = 0;
+
+ for (i = 0; i < nnodes; i++) {
+ struct output_sum *os = &output_sums[j];
+ struct node *node = &nodes[i];
+ cur_vals += node->hits;
+ total_vals += node->hits;
+ os->nranges += node->hits;
+ if (i == (next_interval) -1 || i == nnodes - 1) {
+ os->output = (double) cur_vals / (double) nranges;
+ os->output *= 100.0;
+ cur_vals = 0;
+ next_interval += interval_step;
+ j++;
+ }
+
+ if (percentage) {
+ if (total_vals >= blocks) {
+ double cs = (double) i * block_size / (1024.0 * 1024.0);
+ char p = 'M';
+
+ if (cs > 1024.0) {
+ cs /= 1024.0;
+ p = 'G';
+ }
+ if (cs > 1024.0) {
+ cs /= 1024.0;
+ p = 'T';
+ }
+
+ printf("%.2f%% of hits satisfied in %.3f%cB of cache\n", percentage, cs, p);
+ percentage = 0.0;
+ }
+ }
+ }
+
+ perc_i = 100.0 / (double)output_nranges;
+ perc = 0.0;
+
+ printf("\n Rows Hits %% Sum %% # Hits Size\n");
+ printf("-----------------------------------------------------------------------\n");
+ for (i = 0; i < output_nranges; i++) {
+ struct output_sum *os = &output_sums[i];
+ double gb = (double)os->nranges * block_size / 1024.0;
+ char p = 'K';
+
+ if (gb > 1024.0) {
+ p = 'M';
+ gb /= 1024.0;
+ }
+ if (gb > 1024.0) {
+ p = 'G';
+ gb /= 1024.0;
+ }
+
+ perc += perc_i;
+ hit_percent_sum += os->output;
+ hit_sum += os->nranges;
+ printf("%s %6.2f%%\t%6.2f%%\t\t%6.2f%%\t\t%8u\t%6.2f%c\n",
+ i ? "|->" : "Top", perc, os->output, hit_percent_sum,
+ os->nranges, gb, p);
+ }
+
+ printf("-----------------------------------------------------------------------\n");
+ printf("Total\t\t\t\t\t\t%8llu\n", hit_sum);
+ free(output_sums);
+}
+