Ignore:
Timestamp:
Apr 24, 2021, 2:33:02 PM (6 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
c1c95b1
Parents:
50f6afb
Message:

Rewrote the stats to use stringstream rather than fprintf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/stats.cfa

    r50f6afb r986cb99  
    77#include "bits/locks.hfa"
    88#include "stats.hfa"
     9#include "strstream.hfa"
    910
    1011#if !defined(__CFA_NO_STATISTICS__)
     
    118119        }
    119120
     121        #define eng3(X) (ws(3, 3, unit(eng( X ))))
     122
    120123        void __print_stats( struct __stats_t * stats, int flags, const char * type, const char * name, void * id ) with( *stats ) {
    121124
     125                char buf[1024];
     126                strstream sstr = { buf, 1024 };
     127
    122128                if( flags & CFA_STATS_READY_Q ) {
    123                         double push_len = ((double)ready.push.local.attempt + ready.push.share.attempt + ready.push.extrn.attempt) / (ready.push.local.success + ready.push.share.success + ready.push.extrn.success);
     129
     130                        sstr | "----- " | type | "\"" | name | "\" (" | "" | id | "" | ") - Ready Q Stats -----";
     131
     132                        uint64_t totalR = ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success;
     133                        uint64_t totalS = ready.push.local.success + ready.push.share.success + ready.push.extrn.success;
     134                        sstr | "- totals   : " | eng3(totalR) | "run," | eng3(totalS) | "schd (" | eng3(ready.push.extrn.success) | "ext," | eng3(ready.threads.migration) | "mig)";
     135
     136                        double push_len = ((double)ready.push.local.attempt + ready.push.share.attempt + ready.push.extrn.attempt) / totalS;
    124137                        double sLcl_len = ready.push.local.success ? ((double)ready.push.local.attempt) / ready.push.local.success : 0;
    125138                        double sOth_len = ready.push.share.success ? ((double)ready.push.share.attempt) / ready.push.share.success : 0;
    126139                        double sExt_len = ready.push.extrn.success ? ((double)ready.push.extrn.attempt) / ready.push.extrn.success : 0;
    127 
    128                         uint64_t total = ready.pop.local.success + ready.pop.help.success + ready.pop.steal.success + ready.pop.search.success;
    129                         double rLcl_pc = (100.0 * (double)ready.pop.local .success) / total;
    130                         double rHlp_pc = (100.0 * (double)ready.pop.help  .success) / total;
    131                         double rStl_pc = (100.0 * (double)ready.pop.steal .success) / total;
    132                         double rSch_pc = (100.0 * (double)ready.pop.search.success) / total;
    133 
    134                         __cfaabi_bits_print_safe( STDOUT_FILENO,
    135                                 "----- %s \"%s\" (%p) - Ready Q Stats -----\n"
    136                                 "- totals   : %'3" PRIu64 " run, %'3" PRIu64 " schd (%'" PRIu64 "ext, %'" PRIu64 "mig, %'" PRId64 " )\n"
    137                                 "- push avg : %'3.0lf (l: %'3.2lf/%'" PRIu64 ", s: %'3.2lf/%'" PRIu64 ", e: %'3.2lf : %'" PRIu64 "e)\n"
    138                                 "- local    : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    139                                 "- help     : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    140                                 "- steal    : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    141                                 "- search   : %'3.0lf%%: %'3" PRIu64 " (%'3" PRIu64 " try, %'3" PRIu64 " spc, %'3" PRIu64 " lck, %'3" PRIu64 " ept)\n"
    142                                 "- Idle Slp : %'3" PRIu64 "h, %'3" PRIu64 "c, %'3" PRIu64 "w, %'3" PRIu64 "e\n"
    143                                 "\n"
    144                                 , type, name, id
    145                                 , total
    146                                 , ready.push.local.success + ready.push.share.success + ready.push.extrn.success
    147                                 , ready.push.extrn.success, ready.threads.migration, ready.threads.threads
    148                                 , push_len, sLcl_len, ready.push.local.attempt, sOth_len, ready.push.share.attempt, sExt_len, ready.push.extrn.attempt
    149                                 , rLcl_pc, ready.pop.local .success, ready.pop.local .attempt, ready.pop.local .espec, ready.pop.local .elock, ready.pop.local .eempty
    150                                 , rHlp_pc, ready.pop.help  .success, ready.pop.help  .attempt, ready.pop.help  .espec, ready.pop.help  .elock, ready.pop.help  .eempty
    151                                 , rStl_pc, ready.pop.steal .success, ready.pop.steal .attempt, ready.pop.steal .espec, ready.pop.steal .elock, ready.pop.steal .eempty
    152                                 , rSch_pc, ready.pop.search.success, ready.pop.search.attempt, ready.pop.search.espec, ready.pop.search.elock, ready.pop.search.eempty
    153                                 , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits
    154                         );
     140                        sstr | "- push avg : " | ws(3, 3, push_len)
     141                             | "- l: " | eng3(ready.push.local.attempt) | " (" | ws(3, 3, sLcl_len) | ")"
     142                             | ", s: " | eng3(ready.push.share.attempt) | " (" | ws(3, 3, sOth_len) | ")"
     143                             | ", e: " | eng3(ready.push.extrn.attempt) | " (" | ws(3, 3, sExt_len) | ")";
     144
     145                        double rLcl_pc = (100.0 * (double)ready.pop.local .success) / totalR;
     146                        sstr | "- local    : " | eng3(ready.pop.local .success) | "-"| ws(3, 3, rLcl_pc) | '%'
     147                             | " (" | eng3(ready.pop.local .attempt) | " try," | eng3(ready.pop.local .espec) | " spc," | eng3(ready.pop.local .elock) | " lck," | eng3(ready.pop.local .eempty) | " ept)";
     148                        double rHlp_pc = (100.0 * (double)ready.pop.help  .success) / totalR;
     149                        sstr | "- help     : " | eng3(ready.pop.help  .success) | "-"| ws(3, 3, rHlp_pc) | '%'
     150                             | " (" | eng3(ready.pop.help  .attempt) | " try," | eng3(ready.pop.help  .espec) | " spc," | eng3(ready.pop.help  .elock) | " lck," | eng3(ready.pop.help  .eempty) | " ept)";
     151                        double rStl_pc = (100.0 * (double)ready.pop.steal .success) / totalR;
     152                        sstr | "- steal    : " | eng3(ready.pop.steal .success) | "-"| ws(3, 3, rStl_pc) | '%'
     153                             | " (" | eng3(ready.pop.steal .attempt) | " try," | eng3(ready.pop.steal .espec) | " spc," | eng3(ready.pop.steal .elock) | " lck," | eng3(ready.pop.steal .eempty) | " ept)";
     154                        double rSch_pc = (100.0 * (double)ready.pop.search.success) / totalR;
     155                        sstr | "- search   : " | eng3(ready.pop.search.success) | "-"| ws(3, 3, rSch_pc) | '%'
     156                             | " (" | eng3(ready.pop.search.attempt) | " try," | eng3(ready.pop.search.espec) | " spc," | eng3(ready.pop.search.elock) | " lck," | eng3(ready.pop.search.eempty) | " ept)";
     157
     158                        sstr | "- Idle Slp : " | eng3(ready.sleep.halts) | "halt," | eng3(ready.sleep.cancels) | "cancel," | eng3(ready.sleep.wakes) | "wake," | eng3(ready.sleep.exits) | "exit";
     159                        sstr | nl;
    155160                }
    156161
    157162                #if defined(CFA_HAVE_LINUX_IO_URING_H)
    158163                        if( flags & CFA_STATS_IO ) {
     164                                sstr | "----- " | type | "\"" | name | "\" (" | "" | id | "" | ") - I/O Stats -----";
     165
    159166                                uint64_t total_allocs = io.alloc.fast + io.alloc.slow;
    160                                 double avgfasta = ((double)io.alloc.fast) / total_allocs;
     167                                double avgfasta = (100.0 * (double)io.alloc.fast) / total_allocs;
     168                                sstr | "- total allocations : " | eng3(io.alloc.fast) | "fast," | eng3(io.alloc.slow) | "slow (" | ws(3, 3, avgfasta) | "%)";
     169                                sstr | "-     failures      : " | eng3(io.alloc.fail) | "oom, " | eng3(io.alloc.revoke) | "rvk, " | eng3(io.alloc.block) | "blk";
    161170
    162171                                uint64_t total_submits = io.submit.fast + io.submit.slow;
    163                                 double avgfasts = ((double)io.submit.fast) / total_submits;
     172                                double avgfasts = (100.0 * (double)io.submit.fast) / total_submits;
     173                                sstr | "- total submits     : " | eng3(io.submit.fast) | "fast," | eng3(io.submit.slow) | "slow (" | ws(3, 3, avgfasts) | "%)";
     174                                sstr | "- flush external    : " | eng3(io.flush.external);
     175
     176                                sstr | "- io_uring_enter    : " | eng3(io.calls.flush) | " (" | eng3(io.calls.drain) | ", " | eng3(io.calls.errors.busy) | " EBUSY)";
    164177
    165178                                double avgsubs = ((double)io.calls.submitted) / io.calls.flush;
    166179                                double avgcomp = ((double)io.calls.completed) / io.calls.drain;
    167 
    168                                 __cfaabi_bits_print_safe( STDOUT_FILENO,
    169                                         "----- %s \"%s\" (%p) - I/O Stats -----\n"
    170                                         "- total allocations : %'" PRIu64 "f, %'" PRIu64 "s (%'2.2lff) \n"
    171                                         "-     failures      : %'" PRIu64 "oom, %'" PRIu64 "rvk, %'" PRIu64 "blk\n"
    172                                         "- total submits     : %'" PRIu64 "f, %'" PRIu64 "s (%'2.2lf) \n"
    173                                         "- flush external    : %'" PRIu64 "\n"
    174                                         "- io_uring_enter    : %'" PRIu64 " (%'" PRIu64 ", %'" PRIu64 " EBUSY)\n"
    175                                         "-     submits       : %'" PRIu64 " (%'.2lf) \n"
    176                                         "-     completes     : %'" PRIu64 " (%'.2lf) \n"
    177                                         "- poller sleeping   : %'" PRIu64 "\n"
    178                                         "\n"
    179                                         , type,  name, id
    180                                         , io.alloc.fast, io.alloc.slow, avgfasta
    181                                         , io.alloc.fail, io.alloc.revoke, io.alloc.block
    182                                         , io.submit.fast, io.submit.slow, avgfasts
    183                                         , io.flush.external
    184                                         , io.calls.flush, io.calls.drain, io.calls.errors.busy
    185                                         , io.calls.submitted, avgsubs
    186                                         , io.calls.completed, avgcomp
    187                                         , io.poller.sleeps
    188                                 );
     180                                sstr | "-     submits       : " | eng3(io.calls.submitted) | "(" | ws(3, 3, avgsubs) | "/flush)";
     181                                sstr | "-     completes     : " | eng3(io.calls.completed) | "(" | ws(3, 3, avgcomp) | "/drain)";
     182
     183                                sstr | "- poller sleeping   : " | eng3(io.poller.sleeps);
     184                                sstr | nl;
    189185                        }
    190186                #endif
     187
     188                if(flags) write( sstr, stdout );
    191189        }
    192190
Note: See TracChangeset for help on using the changeset viewer.