diff --git a/src/lib/internal.h b/src/lib/internal.h index 34ef4baf7..ae4a63b4c 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -577,6 +577,11 @@ ncfputc(char c, FILE* out){ void reset_stats(ncstats* stats); void summarize_stats(notcurses* nc); +void update_raster_stats(const struct timespec* time1, const struct timespec* time0, ncstats* stats); +void update_render_stats(const struct timespec* time1, const struct timespec* time0, ncstats* stats); +void update_render_bytes(ncstats* stats, int bytes); +void update_write_stats(const struct timespec* time1, const struct timespec* time0, ncstats* stats, int bytes); + void sigwinch_handler(int signo); void init_lang(notcurses* nc); // nc may be NULL, only used for logging diff --git a/src/lib/render.c b/src/lib/render.c index 43c460a5c..9f0b7215b 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -97,80 +97,6 @@ blocking_write(int fd, const char* buf, size_t buflen){ return 0; } -// update timings for writeout. only call on success. call only under statlock. -static void -update_write_stats(const struct timespec* time1, const struct timespec* time0, - ncstats* stats, int bytes){ - if(bytes >= 0){ - const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); - if(elapsed > 0){ // don't count clearly incorrect information, egads - ++stats->writeouts; - stats->writeout_ns += elapsed; - if(elapsed > stats->writeout_max_ns){ - stats->writeout_max_ns = elapsed; - } - if(elapsed < stats->writeout_min_ns){ - stats->writeout_min_ns = elapsed; - } - } - }else{ - ++stats->failed_writeouts; - } -} - -// negative 'bytes' is recorded as a failure. call only while holding statlock. -static void -update_render_bytes(ncstats* stats, int bytes){ - if(bytes >= 0){ - stats->render_bytes += bytes; - if(bytes > stats->render_max_bytes){ - stats->render_max_bytes = bytes; - } - if(bytes < stats->render_min_bytes){ - stats->render_min_bytes = bytes; - } - }else{ - ++stats->failed_renders; - } -} - -// call only while holding statlock. -static void -update_render_stats(const struct timespec* time1, const struct timespec* time0, - ncstats* stats){ - const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); - //fprintf(stderr, "Rendering took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC, - // (elapsed % NANOSECS_IN_SEC) / 1000000); - if(elapsed > 0){ // don't count clearly incorrect information, egads - ++stats->renders; - stats->render_ns += elapsed; - if(elapsed > stats->render_max_ns){ - stats->render_max_ns = elapsed; - } - if(elapsed < stats->render_min_ns){ - stats->render_min_ns = elapsed; - } - } -} - -// call only while holding statlock. -static void -update_raster_stats(const struct timespec* time1, const struct timespec* time0, - ncstats* stats){ - const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); - //fprintf(stderr, "Rasterizing took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC, - // (elapsed % NANOSECS_IN_SEC) / 1000000); - if(elapsed > 0){ // don't count clearly incorrect information, egads - stats->raster_ns += elapsed; - if(elapsed > stats->raster_max_ns){ - stats->raster_max_ns = elapsed; - } - if(elapsed < stats->raster_min_ns){ - stats->raster_min_ns = elapsed; - } - } -} - void nccell_release(ncplane* n, nccell* c){ pool_release(&n->pool, c); } diff --git a/src/lib/stats.c b/src/lib/stats.c index f2f2d30de..b80d88fb9 100644 --- a/src/lib/stats.c +++ b/src/lib/stats.c @@ -1,5 +1,75 @@ #include "internal.h" +// update timings for writeout. only call on success. call only under statlock. +void update_write_stats(const struct timespec* time1, const struct timespec* time0, + ncstats* stats, int bytes){ + if(bytes >= 0){ + const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); + if(elapsed > 0){ // don't count clearly incorrect information, egads + ++stats->writeouts; + stats->writeout_ns += elapsed; + if(elapsed > stats->writeout_max_ns){ + stats->writeout_max_ns = elapsed; + } + if(elapsed < stats->writeout_min_ns){ + stats->writeout_min_ns = elapsed; + } + } + }else{ + ++stats->failed_writeouts; + } +} + +// negative 'bytes' is recorded as a failure. call only while holding statlock. +void update_render_bytes(ncstats* stats, int bytes){ + if(bytes >= 0){ + stats->render_bytes += bytes; + if(bytes > stats->render_max_bytes){ + stats->render_max_bytes = bytes; + } + if(bytes < stats->render_min_bytes){ + stats->render_min_bytes = bytes; + } + }else{ + ++stats->failed_renders; + } +} + +// call only while holding statlock. +void update_render_stats(const struct timespec* time1, const struct timespec* time0, + ncstats* stats){ + const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); + //fprintf(stderr, "Rendering took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC, + // (elapsed % NANOSECS_IN_SEC) / 1000000); + if(elapsed > 0){ // don't count clearly incorrect information, egads + ++stats->renders; + stats->render_ns += elapsed; + if(elapsed > stats->render_max_ns){ + stats->render_max_ns = elapsed; + } + if(elapsed < stats->render_min_ns){ + stats->render_min_ns = elapsed; + } + } +} + +// call only while holding statlock. +void update_raster_stats(const struct timespec* time1, const struct timespec* time0, + ncstats* stats){ + const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0); + //fprintf(stderr, "Rasterizing took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC, + // (elapsed % NANOSECS_IN_SEC) / 1000000); + if(elapsed > 0){ // don't count clearly incorrect information, egads + stats->raster_ns += elapsed; + if(elapsed > stats->raster_max_ns){ + stats->raster_max_ns = elapsed; + } + if(elapsed < stats->raster_min_ns){ + stats->raster_min_ns = elapsed; + } + } +} + void reset_stats(ncstats* stats){ uint64_t fbbytes = stats->fbbytes; unsigned planes = stats->planes;