Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
events/equeue/tests/prof.c@0:5c4d7b2438d3, 2016-11-11 (annotated)
- Committer:
- switches
- Date:
- Fri Nov 11 20:59:50 2016 +0000
- Revision:
- 0:5c4d7b2438d3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | /* |
switches | 0:5c4d7b2438d3 | 2 | * Profiling framework for the events library |
switches | 0:5c4d7b2438d3 | 3 | * |
switches | 0:5c4d7b2438d3 | 4 | * Copyright (c) 2016 Christopher Haster |
switches | 0:5c4d7b2438d3 | 5 | * |
switches | 0:5c4d7b2438d3 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
switches | 0:5c4d7b2438d3 | 7 | * you may not use this file except in compliance with the License. |
switches | 0:5c4d7b2438d3 | 8 | * You may obtain a copy of the License at |
switches | 0:5c4d7b2438d3 | 9 | * |
switches | 0:5c4d7b2438d3 | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
switches | 0:5c4d7b2438d3 | 11 | * |
switches | 0:5c4d7b2438d3 | 12 | * Unless required by applicable law or agreed to in writing, software |
switches | 0:5c4d7b2438d3 | 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
switches | 0:5c4d7b2438d3 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
switches | 0:5c4d7b2438d3 | 15 | * See the License for the specific language governing permissions and |
switches | 0:5c4d7b2438d3 | 16 | * limitations under the License. |
switches | 0:5c4d7b2438d3 | 17 | */ |
switches | 0:5c4d7b2438d3 | 18 | #include "equeue.h" |
switches | 0:5c4d7b2438d3 | 19 | #include <unistd.h> |
switches | 0:5c4d7b2438d3 | 20 | #include <stdio.h> |
switches | 0:5c4d7b2438d3 | 21 | #include <setjmp.h> |
switches | 0:5c4d7b2438d3 | 22 | #include <stdint.h> |
switches | 0:5c4d7b2438d3 | 23 | #include <stdlib.h> |
switches | 0:5c4d7b2438d3 | 24 | #include <inttypes.h> |
switches | 0:5c4d7b2438d3 | 25 | #include <sys/time.h> |
switches | 0:5c4d7b2438d3 | 26 | |
switches | 0:5c4d7b2438d3 | 27 | |
switches | 0:5c4d7b2438d3 | 28 | // Performance measurement utils |
switches | 0:5c4d7b2438d3 | 29 | #define PROF_RUNS 5 |
switches | 0:5c4d7b2438d3 | 30 | #define PROF_INTERVAL 100000000 |
switches | 0:5c4d7b2438d3 | 31 | |
switches | 0:5c4d7b2438d3 | 32 | #define prof_volatile(t) __attribute__((unused)) volatile t |
switches | 0:5c4d7b2438d3 | 33 | |
switches | 0:5c4d7b2438d3 | 34 | typedef uint64_t prof_cycle_t; |
switches | 0:5c4d7b2438d3 | 35 | |
switches | 0:5c4d7b2438d3 | 36 | static volatile prof_cycle_t prof_start_cycle; |
switches | 0:5c4d7b2438d3 | 37 | static volatile prof_cycle_t prof_stop_cycle; |
switches | 0:5c4d7b2438d3 | 38 | static prof_cycle_t prof_accum_cycle; |
switches | 0:5c4d7b2438d3 | 39 | static prof_cycle_t prof_baseline_cycle; |
switches | 0:5c4d7b2438d3 | 40 | static prof_cycle_t prof_iterations; |
switches | 0:5c4d7b2438d3 | 41 | static const char *prof_units; |
switches | 0:5c4d7b2438d3 | 42 | |
switches | 0:5c4d7b2438d3 | 43 | #define prof_cycle() ({ \ |
switches | 0:5c4d7b2438d3 | 44 | uint32_t a, b; \ |
switches | 0:5c4d7b2438d3 | 45 | __asm__ volatile ("rdtsc" : "=a" (a), "=d" (b)); \ |
switches | 0:5c4d7b2438d3 | 46 | ((uint64_t)b << 32) | (uint64_t)a; \ |
switches | 0:5c4d7b2438d3 | 47 | }) |
switches | 0:5c4d7b2438d3 | 48 | |
switches | 0:5c4d7b2438d3 | 49 | #define prof_loop() \ |
switches | 0:5c4d7b2438d3 | 50 | for (prof_iterations = 0; \ |
switches | 0:5c4d7b2438d3 | 51 | prof_accum_cycle < PROF_INTERVAL; \ |
switches | 0:5c4d7b2438d3 | 52 | prof_iterations++) |
switches | 0:5c4d7b2438d3 | 53 | |
switches | 0:5c4d7b2438d3 | 54 | #define prof_start() ({ \ |
switches | 0:5c4d7b2438d3 | 55 | prof_start_cycle = prof_cycle(); \ |
switches | 0:5c4d7b2438d3 | 56 | }) |
switches | 0:5c4d7b2438d3 | 57 | |
switches | 0:5c4d7b2438d3 | 58 | #define prof_stop() ({ \ |
switches | 0:5c4d7b2438d3 | 59 | prof_stop_cycle = prof_cycle(); \ |
switches | 0:5c4d7b2438d3 | 60 | prof_accum_cycle += prof_stop_cycle - prof_start_cycle; \ |
switches | 0:5c4d7b2438d3 | 61 | }) |
switches | 0:5c4d7b2438d3 | 62 | |
switches | 0:5c4d7b2438d3 | 63 | #define prof_result(value, units) ({ \ |
switches | 0:5c4d7b2438d3 | 64 | prof_accum_cycle = value+prof_baseline_cycle; \ |
switches | 0:5c4d7b2438d3 | 65 | prof_iterations = 1; \ |
switches | 0:5c4d7b2438d3 | 66 | prof_units = units; \ |
switches | 0:5c4d7b2438d3 | 67 | }) |
switches | 0:5c4d7b2438d3 | 68 | |
switches | 0:5c4d7b2438d3 | 69 | #define prof_measure(func, ...) ({ \ |
switches | 0:5c4d7b2438d3 | 70 | printf("%s: ...", #func); \ |
switches | 0:5c4d7b2438d3 | 71 | fflush(stdout); \ |
switches | 0:5c4d7b2438d3 | 72 | \ |
switches | 0:5c4d7b2438d3 | 73 | prof_units = "cycles"; \ |
switches | 0:5c4d7b2438d3 | 74 | prof_cycle_t runs[PROF_RUNS]; \ |
switches | 0:5c4d7b2438d3 | 75 | for (int i = 0; i < PROF_RUNS; i++) { \ |
switches | 0:5c4d7b2438d3 | 76 | prof_accum_cycle = 0; \ |
switches | 0:5c4d7b2438d3 | 77 | prof_iterations = 0; \ |
switches | 0:5c4d7b2438d3 | 78 | func(__VA_ARGS__); \ |
switches | 0:5c4d7b2438d3 | 79 | runs[i] = prof_accum_cycle / prof_iterations; \ |
switches | 0:5c4d7b2438d3 | 80 | } \ |
switches | 0:5c4d7b2438d3 | 81 | \ |
switches | 0:5c4d7b2438d3 | 82 | prof_cycle_t res = runs[0]; \ |
switches | 0:5c4d7b2438d3 | 83 | for (int i = 0; i < PROF_RUNS; i++) { \ |
switches | 0:5c4d7b2438d3 | 84 | if (runs[i] < res) { \ |
switches | 0:5c4d7b2438d3 | 85 | res = runs[i]; \ |
switches | 0:5c4d7b2438d3 | 86 | } \ |
switches | 0:5c4d7b2438d3 | 87 | } \ |
switches | 0:5c4d7b2438d3 | 88 | res -= prof_baseline_cycle; \ |
switches | 0:5c4d7b2438d3 | 89 | printf("\r%s: %"PRIu64" %s", #func, res, prof_units); \ |
switches | 0:5c4d7b2438d3 | 90 | \ |
switches | 0:5c4d7b2438d3 | 91 | if (!isatty(0)) { \ |
switches | 0:5c4d7b2438d3 | 92 | prof_cycle_t prev; \ |
switches | 0:5c4d7b2438d3 | 93 | while (scanf("%*[^0-9]%"PRIu64, &prev) == 0); \ |
switches | 0:5c4d7b2438d3 | 94 | int64_t perc = 100*((int64_t)prev - (int64_t)res) / (int64_t)prev; \ |
switches | 0:5c4d7b2438d3 | 95 | \ |
switches | 0:5c4d7b2438d3 | 96 | if (perc > 10) { \ |
switches | 0:5c4d7b2438d3 | 97 | printf(" (\e[32m%+"PRId64"%%\e[0m)", perc); \ |
switches | 0:5c4d7b2438d3 | 98 | } else if (perc < -10) { \ |
switches | 0:5c4d7b2438d3 | 99 | printf(" (\e[31m%+"PRId64"%%\e[0m)", perc); \ |
switches | 0:5c4d7b2438d3 | 100 | } else { \ |
switches | 0:5c4d7b2438d3 | 101 | printf(" (%+"PRId64"%%)", perc); \ |
switches | 0:5c4d7b2438d3 | 102 | } \ |
switches | 0:5c4d7b2438d3 | 103 | } \ |
switches | 0:5c4d7b2438d3 | 104 | \ |
switches | 0:5c4d7b2438d3 | 105 | printf("\n"); \ |
switches | 0:5c4d7b2438d3 | 106 | res; \ |
switches | 0:5c4d7b2438d3 | 107 | }) |
switches | 0:5c4d7b2438d3 | 108 | |
switches | 0:5c4d7b2438d3 | 109 | #define prof_baseline(func, ...) ({ \ |
switches | 0:5c4d7b2438d3 | 110 | prof_baseline_cycle = 0; \ |
switches | 0:5c4d7b2438d3 | 111 | prof_baseline_cycle = prof_measure(func, __VA_ARGS__); \ |
switches | 0:5c4d7b2438d3 | 112 | }) |
switches | 0:5c4d7b2438d3 | 113 | |
switches | 0:5c4d7b2438d3 | 114 | |
switches | 0:5c4d7b2438d3 | 115 | // Various test functions |
switches | 0:5c4d7b2438d3 | 116 | void no_func(void *eh) { |
switches | 0:5c4d7b2438d3 | 117 | } |
switches | 0:5c4d7b2438d3 | 118 | |
switches | 0:5c4d7b2438d3 | 119 | |
switches | 0:5c4d7b2438d3 | 120 | // Actual performance tests |
switches | 0:5c4d7b2438d3 | 121 | void baseline_prof(void) { |
switches | 0:5c4d7b2438d3 | 122 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 123 | prof_start(); |
switches | 0:5c4d7b2438d3 | 124 | __asm__ volatile (""); |
switches | 0:5c4d7b2438d3 | 125 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 126 | } |
switches | 0:5c4d7b2438d3 | 127 | } |
switches | 0:5c4d7b2438d3 | 128 | |
switches | 0:5c4d7b2438d3 | 129 | void equeue_tick_prof(void) { |
switches | 0:5c4d7b2438d3 | 130 | prof_volatile(unsigned) res; |
switches | 0:5c4d7b2438d3 | 131 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 132 | prof_start(); |
switches | 0:5c4d7b2438d3 | 133 | res = equeue_tick(); |
switches | 0:5c4d7b2438d3 | 134 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 135 | } |
switches | 0:5c4d7b2438d3 | 136 | } |
switches | 0:5c4d7b2438d3 | 137 | |
switches | 0:5c4d7b2438d3 | 138 | void equeue_alloc_prof(void) { |
switches | 0:5c4d7b2438d3 | 139 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 140 | equeue_create(&q, 32*EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 141 | |
switches | 0:5c4d7b2438d3 | 142 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 143 | prof_start(); |
switches | 0:5c4d7b2438d3 | 144 | void *e = equeue_alloc(&q, 8 * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 145 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 146 | |
switches | 0:5c4d7b2438d3 | 147 | equeue_dealloc(&q, e); |
switches | 0:5c4d7b2438d3 | 148 | } |
switches | 0:5c4d7b2438d3 | 149 | |
switches | 0:5c4d7b2438d3 | 150 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 151 | } |
switches | 0:5c4d7b2438d3 | 152 | |
switches | 0:5c4d7b2438d3 | 153 | void equeue_alloc_many_prof(int count) { |
switches | 0:5c4d7b2438d3 | 154 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 155 | equeue_create(&q, count*EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 156 | |
switches | 0:5c4d7b2438d3 | 157 | void *es[count]; |
switches | 0:5c4d7b2438d3 | 158 | |
switches | 0:5c4d7b2438d3 | 159 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 160 | es[i] = equeue_alloc(&q, (i % 4) * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 161 | } |
switches | 0:5c4d7b2438d3 | 162 | |
switches | 0:5c4d7b2438d3 | 163 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 164 | equeue_dealloc(&q, es[i]); |
switches | 0:5c4d7b2438d3 | 165 | } |
switches | 0:5c4d7b2438d3 | 166 | |
switches | 0:5c4d7b2438d3 | 167 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 168 | prof_start(); |
switches | 0:5c4d7b2438d3 | 169 | void *e = equeue_alloc(&q, 8 * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 170 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 171 | |
switches | 0:5c4d7b2438d3 | 172 | equeue_dealloc(&q, e); |
switches | 0:5c4d7b2438d3 | 173 | } |
switches | 0:5c4d7b2438d3 | 174 | |
switches | 0:5c4d7b2438d3 | 175 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 176 | } |
switches | 0:5c4d7b2438d3 | 177 | |
switches | 0:5c4d7b2438d3 | 178 | void equeue_post_prof(void) { |
switches | 0:5c4d7b2438d3 | 179 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 180 | equeue_create(&q, EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 181 | |
switches | 0:5c4d7b2438d3 | 182 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 183 | void *e = equeue_alloc(&q, 0); |
switches | 0:5c4d7b2438d3 | 184 | |
switches | 0:5c4d7b2438d3 | 185 | prof_start(); |
switches | 0:5c4d7b2438d3 | 186 | int id = equeue_post(&q, no_func, e); |
switches | 0:5c4d7b2438d3 | 187 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 188 | |
switches | 0:5c4d7b2438d3 | 189 | equeue_cancel(&q, id); |
switches | 0:5c4d7b2438d3 | 190 | } |
switches | 0:5c4d7b2438d3 | 191 | |
switches | 0:5c4d7b2438d3 | 192 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 193 | } |
switches | 0:5c4d7b2438d3 | 194 | |
switches | 0:5c4d7b2438d3 | 195 | void equeue_post_many_prof(int count) { |
switches | 0:5c4d7b2438d3 | 196 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 197 | equeue_create(&q, count*EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 198 | |
switches | 0:5c4d7b2438d3 | 199 | for (int i = 0; i < count-1; i++) { |
switches | 0:5c4d7b2438d3 | 200 | equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 201 | } |
switches | 0:5c4d7b2438d3 | 202 | |
switches | 0:5c4d7b2438d3 | 203 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 204 | void *e = equeue_alloc(&q, 0); |
switches | 0:5c4d7b2438d3 | 205 | |
switches | 0:5c4d7b2438d3 | 206 | prof_start(); |
switches | 0:5c4d7b2438d3 | 207 | int id = equeue_post(&q, no_func, e); |
switches | 0:5c4d7b2438d3 | 208 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 209 | |
switches | 0:5c4d7b2438d3 | 210 | equeue_cancel(&q, id); |
switches | 0:5c4d7b2438d3 | 211 | } |
switches | 0:5c4d7b2438d3 | 212 | |
switches | 0:5c4d7b2438d3 | 213 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 214 | } |
switches | 0:5c4d7b2438d3 | 215 | |
switches | 0:5c4d7b2438d3 | 216 | void equeue_post_future_prof(void) { |
switches | 0:5c4d7b2438d3 | 217 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 218 | equeue_create(&q, EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 219 | |
switches | 0:5c4d7b2438d3 | 220 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 221 | void *e = equeue_alloc(&q, 0); |
switches | 0:5c4d7b2438d3 | 222 | equeue_event_delay(e, 1000); |
switches | 0:5c4d7b2438d3 | 223 | |
switches | 0:5c4d7b2438d3 | 224 | prof_start(); |
switches | 0:5c4d7b2438d3 | 225 | int id = equeue_post(&q, no_func, e); |
switches | 0:5c4d7b2438d3 | 226 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 227 | |
switches | 0:5c4d7b2438d3 | 228 | equeue_cancel(&q, id); |
switches | 0:5c4d7b2438d3 | 229 | } |
switches | 0:5c4d7b2438d3 | 230 | |
switches | 0:5c4d7b2438d3 | 231 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 232 | } |
switches | 0:5c4d7b2438d3 | 233 | |
switches | 0:5c4d7b2438d3 | 234 | void equeue_post_future_many_prof(int count) { |
switches | 0:5c4d7b2438d3 | 235 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 236 | equeue_create(&q, count*EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 237 | |
switches | 0:5c4d7b2438d3 | 238 | for (int i = 0; i < count-1; i++) { |
switches | 0:5c4d7b2438d3 | 239 | equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 240 | } |
switches | 0:5c4d7b2438d3 | 241 | |
switches | 0:5c4d7b2438d3 | 242 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 243 | void *e = equeue_alloc(&q, 0); |
switches | 0:5c4d7b2438d3 | 244 | equeue_event_delay(e, 1000); |
switches | 0:5c4d7b2438d3 | 245 | |
switches | 0:5c4d7b2438d3 | 246 | prof_start(); |
switches | 0:5c4d7b2438d3 | 247 | int id = equeue_post(&q, no_func, e); |
switches | 0:5c4d7b2438d3 | 248 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 249 | |
switches | 0:5c4d7b2438d3 | 250 | equeue_cancel(&q, id); |
switches | 0:5c4d7b2438d3 | 251 | } |
switches | 0:5c4d7b2438d3 | 252 | |
switches | 0:5c4d7b2438d3 | 253 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 254 | } |
switches | 0:5c4d7b2438d3 | 255 | |
switches | 0:5c4d7b2438d3 | 256 | void equeue_dispatch_prof(void) { |
switches | 0:5c4d7b2438d3 | 257 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 258 | equeue_create(&q, EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 259 | |
switches | 0:5c4d7b2438d3 | 260 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 261 | equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 262 | |
switches | 0:5c4d7b2438d3 | 263 | prof_start(); |
switches | 0:5c4d7b2438d3 | 264 | equeue_dispatch(&q, 0); |
switches | 0:5c4d7b2438d3 | 265 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 266 | } |
switches | 0:5c4d7b2438d3 | 267 | |
switches | 0:5c4d7b2438d3 | 268 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 269 | } |
switches | 0:5c4d7b2438d3 | 270 | |
switches | 0:5c4d7b2438d3 | 271 | void equeue_dispatch_many_prof(int count) { |
switches | 0:5c4d7b2438d3 | 272 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 273 | equeue_create(&q, count*EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 274 | |
switches | 0:5c4d7b2438d3 | 275 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 276 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 277 | equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 278 | } |
switches | 0:5c4d7b2438d3 | 279 | |
switches | 0:5c4d7b2438d3 | 280 | prof_start(); |
switches | 0:5c4d7b2438d3 | 281 | equeue_dispatch(&q, 0); |
switches | 0:5c4d7b2438d3 | 282 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 283 | } |
switches | 0:5c4d7b2438d3 | 284 | |
switches | 0:5c4d7b2438d3 | 285 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 286 | } |
switches | 0:5c4d7b2438d3 | 287 | |
switches | 0:5c4d7b2438d3 | 288 | void equeue_cancel_prof(void) { |
switches | 0:5c4d7b2438d3 | 289 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 290 | equeue_create(&q, EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 291 | |
switches | 0:5c4d7b2438d3 | 292 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 293 | int id = equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 294 | |
switches | 0:5c4d7b2438d3 | 295 | prof_start(); |
switches | 0:5c4d7b2438d3 | 296 | equeue_cancel(&q, id); |
switches | 0:5c4d7b2438d3 | 297 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 298 | } |
switches | 0:5c4d7b2438d3 | 299 | |
switches | 0:5c4d7b2438d3 | 300 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 301 | } |
switches | 0:5c4d7b2438d3 | 302 | |
switches | 0:5c4d7b2438d3 | 303 | void equeue_cancel_many_prof(int count) { |
switches | 0:5c4d7b2438d3 | 304 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 305 | equeue_create(&q, count*EQUEUE_EVENT_SIZE); |
switches | 0:5c4d7b2438d3 | 306 | |
switches | 0:5c4d7b2438d3 | 307 | for (int i = 0; i < count-1; i++) { |
switches | 0:5c4d7b2438d3 | 308 | equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 309 | } |
switches | 0:5c4d7b2438d3 | 310 | |
switches | 0:5c4d7b2438d3 | 311 | prof_loop() { |
switches | 0:5c4d7b2438d3 | 312 | int id = equeue_call(&q, no_func, 0); |
switches | 0:5c4d7b2438d3 | 313 | |
switches | 0:5c4d7b2438d3 | 314 | prof_start(); |
switches | 0:5c4d7b2438d3 | 315 | equeue_cancel(&q, id); |
switches | 0:5c4d7b2438d3 | 316 | prof_stop(); |
switches | 0:5c4d7b2438d3 | 317 | } |
switches | 0:5c4d7b2438d3 | 318 | |
switches | 0:5c4d7b2438d3 | 319 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 320 | } |
switches | 0:5c4d7b2438d3 | 321 | |
switches | 0:5c4d7b2438d3 | 322 | void equeue_alloc_size_prof(void) { |
switches | 0:5c4d7b2438d3 | 323 | size_t size = 32*EQUEUE_EVENT_SIZE; |
switches | 0:5c4d7b2438d3 | 324 | |
switches | 0:5c4d7b2438d3 | 325 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 326 | equeue_create(&q, size); |
switches | 0:5c4d7b2438d3 | 327 | equeue_alloc(&q, 0); |
switches | 0:5c4d7b2438d3 | 328 | |
switches | 0:5c4d7b2438d3 | 329 | prof_result(size - q.slab.size, "bytes"); |
switches | 0:5c4d7b2438d3 | 330 | |
switches | 0:5c4d7b2438d3 | 331 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 332 | } |
switches | 0:5c4d7b2438d3 | 333 | |
switches | 0:5c4d7b2438d3 | 334 | void equeue_alloc_many_size_prof(int count) { |
switches | 0:5c4d7b2438d3 | 335 | size_t size = count*EQUEUE_EVENT_SIZE; |
switches | 0:5c4d7b2438d3 | 336 | |
switches | 0:5c4d7b2438d3 | 337 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 338 | equeue_create(&q, size); |
switches | 0:5c4d7b2438d3 | 339 | |
switches | 0:5c4d7b2438d3 | 340 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 341 | equeue_alloc(&q, (i % 4) * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 342 | } |
switches | 0:5c4d7b2438d3 | 343 | |
switches | 0:5c4d7b2438d3 | 344 | prof_result(size - q.slab.size, "bytes"); |
switches | 0:5c4d7b2438d3 | 345 | |
switches | 0:5c4d7b2438d3 | 346 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 347 | } |
switches | 0:5c4d7b2438d3 | 348 | |
switches | 0:5c4d7b2438d3 | 349 | void equeue_alloc_fragmented_size_prof(int count) { |
switches | 0:5c4d7b2438d3 | 350 | size_t size = count*EQUEUE_EVENT_SIZE; |
switches | 0:5c4d7b2438d3 | 351 | |
switches | 0:5c4d7b2438d3 | 352 | struct equeue q; |
switches | 0:5c4d7b2438d3 | 353 | equeue_create(&q, size); |
switches | 0:5c4d7b2438d3 | 354 | |
switches | 0:5c4d7b2438d3 | 355 | void *es[count]; |
switches | 0:5c4d7b2438d3 | 356 | |
switches | 0:5c4d7b2438d3 | 357 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 358 | es[i] = equeue_alloc(&q, (i % 4) * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 359 | } |
switches | 0:5c4d7b2438d3 | 360 | |
switches | 0:5c4d7b2438d3 | 361 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 362 | equeue_dealloc(&q, es[i]); |
switches | 0:5c4d7b2438d3 | 363 | } |
switches | 0:5c4d7b2438d3 | 364 | |
switches | 0:5c4d7b2438d3 | 365 | for (int i = count-1; i >= 0; i--) { |
switches | 0:5c4d7b2438d3 | 366 | es[i] = equeue_alloc(&q, (i % 4) * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 367 | } |
switches | 0:5c4d7b2438d3 | 368 | |
switches | 0:5c4d7b2438d3 | 369 | for (int i = count-1; i >= 0; i--) { |
switches | 0:5c4d7b2438d3 | 370 | equeue_dealloc(&q, es[i]); |
switches | 0:5c4d7b2438d3 | 371 | } |
switches | 0:5c4d7b2438d3 | 372 | |
switches | 0:5c4d7b2438d3 | 373 | for (int i = 0; i < count; i++) { |
switches | 0:5c4d7b2438d3 | 374 | equeue_alloc(&q, (i % 4) * sizeof(int)); |
switches | 0:5c4d7b2438d3 | 375 | } |
switches | 0:5c4d7b2438d3 | 376 | |
switches | 0:5c4d7b2438d3 | 377 | prof_result(size - q.slab.size, "bytes"); |
switches | 0:5c4d7b2438d3 | 378 | |
switches | 0:5c4d7b2438d3 | 379 | equeue_destroy(&q); |
switches | 0:5c4d7b2438d3 | 380 | } |
switches | 0:5c4d7b2438d3 | 381 | |
switches | 0:5c4d7b2438d3 | 382 | |
switches | 0:5c4d7b2438d3 | 383 | // Entry point |
switches | 0:5c4d7b2438d3 | 384 | int main() { |
switches | 0:5c4d7b2438d3 | 385 | printf("beginning profiling...\n"); |
switches | 0:5c4d7b2438d3 | 386 | |
switches | 0:5c4d7b2438d3 | 387 | prof_baseline(baseline_prof); |
switches | 0:5c4d7b2438d3 | 388 | |
switches | 0:5c4d7b2438d3 | 389 | prof_measure(equeue_tick_prof); |
switches | 0:5c4d7b2438d3 | 390 | prof_measure(equeue_alloc_prof); |
switches | 0:5c4d7b2438d3 | 391 | prof_measure(equeue_post_prof); |
switches | 0:5c4d7b2438d3 | 392 | prof_measure(equeue_post_future_prof); |
switches | 0:5c4d7b2438d3 | 393 | prof_measure(equeue_dispatch_prof); |
switches | 0:5c4d7b2438d3 | 394 | prof_measure(equeue_cancel_prof); |
switches | 0:5c4d7b2438d3 | 395 | |
switches | 0:5c4d7b2438d3 | 396 | prof_measure(equeue_alloc_many_prof, 1000); |
switches | 0:5c4d7b2438d3 | 397 | prof_measure(equeue_post_many_prof, 1000); |
switches | 0:5c4d7b2438d3 | 398 | prof_measure(equeue_post_future_many_prof, 1000); |
switches | 0:5c4d7b2438d3 | 399 | prof_measure(equeue_dispatch_many_prof, 100); |
switches | 0:5c4d7b2438d3 | 400 | prof_measure(equeue_cancel_many_prof, 100); |
switches | 0:5c4d7b2438d3 | 401 | |
switches | 0:5c4d7b2438d3 | 402 | prof_measure(equeue_alloc_size_prof); |
switches | 0:5c4d7b2438d3 | 403 | prof_measure(equeue_alloc_many_size_prof, 1000); |
switches | 0:5c4d7b2438d3 | 404 | prof_measure(equeue_alloc_fragmented_size_prof, 1000); |
switches | 0:5c4d7b2438d3 | 405 | |
switches | 0:5c4d7b2438d3 | 406 | printf("done!\n"); |
switches | 0:5c4d7b2438d3 | 407 | } |