Skip to content

Commit 55cefed

Browse files
committed
Refine dudect function
Add the prepare_percentiles functions into dudect function.The function set different thresholds for cropping measurements. Change-Id: I89fd43605430fd843bd27d2832afd2fb7f356061
1 parent ae22678 commit 55cefed

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

dudect/fixture.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ static void __attribute__((noreturn)) die(void)
5656
exit(111);
5757
}
5858

59+
static int cmp(const int64_t *a, const int64_t *b)
60+
{
61+
return (int) (*a - *b);
62+
}
63+
64+
static int64_t percentile(int64_t *a_sorted, double which, size_t size)
65+
{
66+
size_t array_position = (size_t) ((double) size * (double) which);
67+
assert(array_position < size);
68+
return a_sorted[array_position];
69+
}
70+
71+
static void prepare_percentiles(int64_t *ctx)
72+
{
73+
qsort(ctx, N_MEASURES, sizeof(int64_t),
74+
(int (*)(const void *, const void *)) cmp);
75+
for (size_t i = 0; i < N_MEASURES; i++) {
76+
ctx[i] =
77+
percentile(ctx, 1 - (pow(0.5, 10 * (double) (i + 1) / N_MEASURES)),
78+
N_MEASURES);
79+
}
80+
}
81+
5982
static void differentiate(int64_t *exec_times,
6083
const int64_t *before_ticks,
6184
const int64_t *after_ticks)
@@ -66,7 +89,7 @@ static void differentiate(int64_t *exec_times,
6689

6790
static void update_statistics(const int64_t *exec_times, uint8_t *classes)
6891
{
69-
for (size_t i = 0; i < N_MEASURES; i++) {
92+
for (size_t i = 5; i < N_MEASURES; i++) {
7093
int64_t difference = exec_times[i];
7194
/* CPU cycle counter overflowed or dropped measurement */
7295
if (difference <= 0)
@@ -133,6 +156,7 @@ static bool doit(int mode)
133156

134157
bool ret = measure(before_ticks, after_ticks, input_data, mode);
135158
differentiate(exec_times, before_ticks, after_ticks);
159+
prepare_percentiles(exec_times);
136160
update_statistics(exec_times, classes);
137161
ret &= report();
138162

0 commit comments

Comments
 (0)