| 1 | #include <stdint.h>
|
|---|
| 2 | #include <stdlib.hfa>
|
|---|
| 3 |
|
|---|
| 4 | #include <unistd.h> // STDERR_FILENO
|
|---|
| 5 | #include "bits/debug.hfa"
|
|---|
| 6 | #include "stats.hfa"
|
|---|
| 7 |
|
|---|
| 8 | #if !defined(__CFA_NO_STATISTICS__)
|
|---|
| 9 | void __init_stats( struct __stats_t * stats ) {
|
|---|
| 10 | stats->ready.pick.push.attempt = 0;
|
|---|
| 11 | stats->ready.pick.push.success = 0;
|
|---|
| 12 | stats->ready.pick.pop .probe = 0;
|
|---|
| 13 | stats->ready.pick.pop .attempt = 0;
|
|---|
| 14 | stats->ready.pick.pop .success = 0;
|
|---|
| 15 |
|
|---|
| 16 | #if defined(HAVE_LINUX_IO_URING_H)
|
|---|
| 17 | stats->io.submit_q.submit_avg.rdy = 0;
|
|---|
| 18 | stats->io.submit_q.submit_avg.csm = 0;
|
|---|
| 19 | stats->io.submit_q.submit_avg.avl = 0;
|
|---|
| 20 | stats->io.submit_q.submit_avg.cnt = 0;
|
|---|
| 21 | stats->io.submit_q.look_avg.val = 0;
|
|---|
| 22 | stats->io.submit_q.look_avg.cnt = 0;
|
|---|
| 23 | stats->io.submit_q.look_avg.block = 0;
|
|---|
| 24 | stats->io.submit_q.alloc_avg.val = 0;
|
|---|
| 25 | stats->io.submit_q.alloc_avg.cnt = 0;
|
|---|
| 26 | stats->io.submit_q.alloc_avg.block = 0;
|
|---|
| 27 | stats->io.complete_q.completed_avg.val = 0;
|
|---|
| 28 | stats->io.complete_q.completed_avg.slow_cnt = 0;
|
|---|
| 29 | stats->io.complete_q.completed_avg.fast_cnt = 0;
|
|---|
| 30 | #endif
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | void __tally_stats( struct __stats_t * cltr, struct __stats_t * proc ) {
|
|---|
| 34 | __atomic_fetch_add( &cltr->ready.pick.push.attempt, proc->ready.pick.push.attempt, __ATOMIC_SEQ_CST );
|
|---|
| 35 | __atomic_fetch_add( &cltr->ready.pick.push.success, proc->ready.pick.push.success, __ATOMIC_SEQ_CST );
|
|---|
| 36 | __atomic_fetch_add( &cltr->ready.pick.pop .probe , proc->ready.pick.pop .probe , __ATOMIC_SEQ_CST );
|
|---|
| 37 | __atomic_fetch_add( &cltr->ready.pick.pop .attempt, proc->ready.pick.pop .attempt, __ATOMIC_SEQ_CST );
|
|---|
| 38 | __atomic_fetch_add( &cltr->ready.pick.pop .success, proc->ready.pick.pop .success, __ATOMIC_SEQ_CST );
|
|---|
| 39 |
|
|---|
| 40 | #if defined(HAVE_LINUX_IO_URING_H)
|
|---|
| 41 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy , proc->io.submit_q.submit_avg.rdy , __ATOMIC_SEQ_CST );
|
|---|
| 42 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm , proc->io.submit_q.submit_avg.csm , __ATOMIC_SEQ_CST );
|
|---|
| 43 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl , proc->io.submit_q.submit_avg.avl , __ATOMIC_SEQ_CST );
|
|---|
| 44 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt , proc->io.submit_q.submit_avg.cnt , __ATOMIC_SEQ_CST );
|
|---|
| 45 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.val , proc->io.submit_q.look_avg.val , __ATOMIC_SEQ_CST );
|
|---|
| 46 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt , proc->io.submit_q.look_avg.cnt , __ATOMIC_SEQ_CST );
|
|---|
| 47 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.block , proc->io.submit_q.look_avg.block , __ATOMIC_SEQ_CST );
|
|---|
| 48 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val , proc->io.submit_q.alloc_avg.val , __ATOMIC_SEQ_CST );
|
|---|
| 49 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt , proc->io.submit_q.alloc_avg.cnt , __ATOMIC_SEQ_CST );
|
|---|
| 50 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block , proc->io.submit_q.alloc_avg.block , __ATOMIC_SEQ_CST );
|
|---|
| 51 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val , proc->io.complete_q.completed_avg.val , __ATOMIC_SEQ_CST );
|
|---|
| 52 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.slow_cnt, proc->io.complete_q.completed_avg.slow_cnt, __ATOMIC_SEQ_CST );
|
|---|
| 53 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.fast_cnt, proc->io.complete_q.completed_avg.fast_cnt, __ATOMIC_SEQ_CST );
|
|---|
| 54 | #endif
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | void __print_stats( struct __stats_t * stats ) {
|
|---|
| 58 |
|
|---|
| 59 | double push_sur = (100.0 * ((double)stats->ready.pick.push.success) / stats->ready.pick.push.attempt);
|
|---|
| 60 | double pop_sur = (100.0 * ((double)stats->ready.pick.pop .success) / stats->ready.pick.pop .attempt);
|
|---|
| 61 |
|
|---|
| 62 | double push_len = ((double)stats->ready.pick.push.attempt) / stats->ready.pick.push.success;
|
|---|
| 63 | double pop_len = ((double)stats->ready.pick.pop .attempt) / stats->ready.pick.pop .success;
|
|---|
| 64 |
|
|---|
| 65 | #if defined(HAVE_LINUX_IO_URING_H)
|
|---|
| 66 | double avgrdy = ((double)submit_avg.rdy) / submit_avg.cnt;
|
|---|
| 67 | double avgcsm = ((double)submit_avg.csm) / submit_avg.cnt;
|
|---|
| 68 | double avgavl = ((double)submit_avg.avl) / submit_avg.cnt;
|
|---|
| 69 |
|
|---|
| 70 | double lavgv = 0;
|
|---|
| 71 | double lavgb = 0;
|
|---|
| 72 | if(look_avg.cnt != 0) {
|
|---|
| 73 | lavgv = ((double)look_avg.val ) / look_avg.cnt;
|
|---|
| 74 | lavgb = ((double)look_avg.block) / look_avg.cnt;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | double aavgv = 0;
|
|---|
| 78 | double aavgb = 0;
|
|---|
| 79 | if(alloc_avg.cnt != 0) {
|
|---|
| 80 | aavgv = ((double)alloc_avg.val ) / alloc_avg.cnt;
|
|---|
| 81 | aavgb = ((double)alloc_avg.block) / alloc_avg.cnt;
|
|---|
| 82 | }
|
|---|
| 83 | #endif
|
|---|
| 84 |
|
|---|
| 85 | __cfaabi_bits_print_safe( STDOUT_FILENO,
|
|---|
| 86 | "----- Ready Q Stats -----\n"
|
|---|
| 87 | "- total threads run : %'15lu\n"
|
|---|
| 88 | "- total threads scheduled: %'15lu\n"
|
|---|
| 89 | "- push average probe len : %'18.2lf, %'18.2lf%% (%'15lu attempts)\n"
|
|---|
| 90 | "- pop average probe len : %'18.2lf, %'18.2lf%% (%'15lu attempts)\n"
|
|---|
| 91 | #if defined(HAVE_LINUX_IO_URING_H)
|
|---|
| 92 | "\n"
|
|---|
| 93 | "----- I/O Stats -----\n"
|
|---|
| 94 | "- total submit calls : %'15llu\n"
|
|---|
| 95 | "- avg ready entries : %'18.2lf\n"
|
|---|
| 96 | "- avg submitted entries : %'18.2lf\n"
|
|---|
| 97 | "- avg available entries : %'18.2lf\n"
|
|---|
| 98 | "- total ready search : %'15llu\n"
|
|---|
| 99 | "- avg ready search len : %'18.2lf\n"
|
|---|
| 100 | "- avg ready search block : %'18.2lf\n"
|
|---|
| 101 | "- total alloc search : %'15llu\n"
|
|---|
| 102 | "- avg alloc search len : %'18.2lf\n"
|
|---|
| 103 | "- avg alloc search block : %'18.2lf\n"
|
|---|
| 104 | "- total wait calls : %'15llu (%'llu slow, %'llu fast)\n"
|
|---|
| 105 | "- avg completion/wait : %'18.2lf\n"
|
|---|
| 106 | #endif
|
|---|
| 107 | , stats->ready.pick.pop.success
|
|---|
| 108 | , stats->ready.pick.push.success
|
|---|
| 109 | , push_len, push_sur, stats->ready.pick.push.attempt
|
|---|
| 110 | , pop_len , pop_sur , stats->ready.pick.pop .attempt
|
|---|
| 111 | #if defined(HAVE_LINUX_IO_URING_H)
|
|---|
| 112 | , submit_avg.cnt
|
|---|
| 113 | , avgrdy
|
|---|
| 114 | , avgcsm
|
|---|
| 115 | , avgavl
|
|---|
| 116 | , look_avg.cnt
|
|---|
| 117 | , lavgv
|
|---|
| 118 | , lavgb
|
|---|
| 119 | , alloc_avg.cnt
|
|---|
| 120 | , aavgv
|
|---|
| 121 | , aavgb
|
|---|
| 122 | , completed_avg.slow_cnt + completed_avg.fast_cnt
|
|---|
| 123 | , completed_avg.slow_cnt, completed_avg.fast_cnt
|
|---|
| 124 | , ((double)completed_avg.val) / (completed_avg.slow_cnt + completed_avg.fast_cnt)
|
|---|
| 125 | #endif
|
|---|
| 126 | );
|
|---|
| 127 | }
|
|---|
| 128 | #endif
|
|---|