| 78 | } |
| 79 | |
| 80 | char *likely_stats(unsigned int min_hits, unsigned int percent) |
| 81 | { |
| 82 | struct trace *worst; |
| 83 | double worst_ratio; |
| 84 | struct thash_iter i; |
| 85 | char *ret; |
| 86 | struct trace *t; |
| 87 | |
| 88 | worst = NULL; |
| 89 | worst_ratio = 2; |
| 90 | |
| 91 | /* This is O(n), but it's not likely called that often. */ |
| 92 | for (t = thash_first(&htable, &i); t; t = thash_next(&htable, &i)) { |
| 93 | if (t->count >= min_hits) { |
| 94 | if (right_ratio(t) < worst_ratio) { |
| 95 | worst = t; |
| 96 | worst_ratio = right_ratio(t); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (worst_ratio * 100 > percent) |
| 102 | return NULL; |
| 103 | |
| 104 | ret = malloc(strlen(worst->condstr) + |
| 105 | strlen(worst->file) + |
| 106 | sizeof(long int) * 8 + |
| 107 | sizeof("%s:%u:%slikely(%s) correct %u%% (%lu/%lu)")); |
| 108 | sprintf(ret, "%s:%u:%slikely(%s) correct %u%% (%lu/%lu)", |
| 109 | worst->file, worst->line, |
| 110 | worst->expect ? "" : "un", worst->condstr, |
| 111 | (unsigned)(worst_ratio * 100), |
| 112 | worst->right, worst->count); |
| 113 | |
| 114 | thash_del(&htable, worst); |
| 115 | free(worst); |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | void likely_stats_reset(void) |
| 121 | { |