Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
stats.c File Reference
#include <inttypes.h>
#include "internal.h"
Include dependency graph for stats.c:

Go to the source code of this file.

Functions

void update_write_stats (const struct timespec *time1, const struct timespec *time0, ncstats *stats, int bytes)
 
void update_raster_bytes (ncstats *stats, int bytes)
 
void update_render_stats (const struct timespec *time1, const struct timespec *time0, ncstats *stats)
 
void update_raster_stats (const struct timespec *time1, const struct timespec *time0, ncstats *stats)
 
void reset_stats (ncstats *stats)
 
void notcurses_stats (notcurses *nc, ncstats *stats)
 
ncstatsnotcurses_stats_alloc (const notcurses *nc __attribute__((unused)))
 
void notcurses_stats_reset (notcurses *nc, ncstats *stats)
 
void summarize_stats (notcurses *nc)
 

Function Documentation

◆ notcurses_stats()

void notcurses_stats ( notcurses nc,
ncstats stats 
)

Definition at line 86 of file stats.c.

86 {
87 pthread_mutex_lock(&nc->stats.lock);
88 memcpy(stats, &nc->stats.s, sizeof(*stats));
89 pthread_mutex_unlock(&nc->stats.lock);
90}
ncstats s
Definition internal.h:247
pthread_mutex_t lock
Definition internal.h:246
ncsharedstats stats
Definition internal.h:356
Here is the caller graph for this function:

◆ notcurses_stats_alloc()

ncstats * notcurses_stats_alloc ( const notcurses *nc   __attribute__(unused))

Definition at line 92 of file stats.c.

92 {
93 ncstats* ret = malloc(sizeof(ncstats));
94 if(ret == NULL){
95 return NULL;
96 }
97 return ret;
98}
return NULL
Definition termdesc.h:229
Here is the caller graph for this function:

◆ notcurses_stats_reset()

void notcurses_stats_reset ( notcurses nc,
ncstats stats 
)

Definition at line 100 of file stats.c.

100 {
101 pthread_mutex_lock(&nc->stats.lock);
102 if(stats){
103 memcpy(stats, &nc->stats.s, sizeof(*stats));
104 }
105 // add the stats to the stashed stats, so that we can show true totals on
106 // shutdown in the closing banner
107 ncstats* stash = &nc->stashed_stats;
108 if(nc->stats.s.render_min_ns < stash->render_min_ns){
109 stash->render_min_ns = nc->stats.s.render_min_ns;
110 }
111 if(nc->stats.s.raster_min_bytes < stash->raster_min_bytes){
113 }
114 if(nc->stats.s.raster_min_ns < stash->raster_min_ns){
115 stash->raster_min_ns = nc->stats.s.raster_min_ns;
116 }
117 if(nc->stats.s.writeout_min_ns < stash->writeout_min_ns){
119 }
120 if(nc->stats.s.render_max_ns > stash->render_max_ns){
121 stash->render_max_ns = nc->stats.s.render_max_ns;
122 }
123 if(nc->stats.s.raster_max_bytes > stash->raster_max_bytes){
125 }
126 if(nc->stats.s.raster_max_ns > stash->raster_max_ns){
127 stash->raster_max_ns = nc->stats.s.raster_max_ns;
128 }
129 if(nc->stats.s.writeout_max_ns > stash->writeout_max_ns){
131 }
132 stash->writeout_ns += nc->stats.s.writeout_ns;
133 stash->raster_ns += nc->stats.s.raster_ns;
134 stash->render_ns += nc->stats.s.render_ns;
135 stash->raster_bytes += nc->stats.s.raster_bytes;
136 stash->failed_renders += nc->stats.s.failed_renders;
138 stash->renders += nc->stats.s.renders;
139 stash->writeouts += nc->stats.s.writeouts;
140 stash->cellelisions += nc->stats.s.cellelisions;
141 stash->cellemissions += nc->stats.s.cellemissions;
142 stash->fgelisions += nc->stats.s.fgelisions;
143 stash->fgemissions += nc->stats.s.fgemissions;
144 stash->bgelisions += nc->stats.s.bgelisions;
145 stash->bgemissions += nc->stats.s.bgemissions;
148 stash->refreshes += nc->stats.s.refreshes;
151 stash->sprixelbytes += nc->stats.s.sprixelbytes;
153 stash->input_errors += nc->stats.s.input_errors;
154 stash->input_events += nc->stats.s.input_events;
155 stash->hpa_gratuitous += nc->stats.s.hpa_gratuitous;
158
159 stash->fbbytes = nc->stats.s.fbbytes;
160 stash->planes = nc->stats.s.planes;
161 reset_stats(&nc->stats.s);
162 pthread_mutex_unlock(&nc->stats.lock);
163}
void reset_stats(ncstats *stats)
Definition stats.c:74
uint64_t failed_writeouts
Definition notcurses.h:1786
uint64_t raster_ns
Definition notcurses.h:1793
uint64_t cellemissions
Definition notcurses.h:1800
int64_t render_min_ns
Definition notcurses.h:1792
uint64_t failed_renders
Definition notcurses.h:1785
uint64_t refreshes
Definition notcurses.h:1807
uint64_t defaultelisions
Definition notcurses.h:1805
uint64_t appsync_updates
Definition notcurses.h:1811
uint64_t cell_geo_changes
Definition notcurses.h:1815
uint64_t cellelisions
Definition notcurses.h:1799
uint64_t bgemissions
Definition notcurses.h:1804
uint64_t fgemissions
Definition notcurses.h:1802
uint64_t hpa_gratuitous
Definition notcurses.h:1814
int64_t writeout_min_ns
Definition notcurses.h:1798
uint64_t defaultemissions
Definition notcurses.h:1806
uint64_t sprixelemissions
Definition notcurses.h:1808
uint64_t writeout_ns
Definition notcurses.h:1796
uint64_t sprixelelisions
Definition notcurses.h:1809
uint64_t render_ns
Definition notcurses.h:1790
uint64_t renders
Definition notcurses.h:1783
uint64_t input_errors
Definition notcurses.h:1812
uint64_t raster_bytes
Definition notcurses.h:1787
int64_t raster_min_ns
Definition notcurses.h:1795
uint64_t pixel_geo_changes
Definition notcurses.h:1816
int64_t raster_max_bytes
Definition notcurses.h:1788
uint64_t fgelisions
Definition notcurses.h:1801
int64_t render_max_ns
Definition notcurses.h:1791
uint64_t input_events
Definition notcurses.h:1813
uint64_t bgelisions
Definition notcurses.h:1803
uint64_t sprixelbytes
Definition notcurses.h:1810
unsigned planes
Definition notcurses.h:1820
int64_t writeout_max_ns
Definition notcurses.h:1797
uint64_t writeouts
Definition notcurses.h:1784
uint64_t fbbytes
Definition notcurses.h:1819
int64_t raster_max_ns
Definition notcurses.h:1794
int64_t raster_min_bytes
Definition notcurses.h:1789
ncstats stashed_stats
Definition internal.h:357
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_stats()

void reset_stats ( ncstats stats)

Definition at line 74 of file stats.c.

74 {
75 uint64_t fbbytes = stats->fbbytes;
76 unsigned planes = stats->planes;
77 memset(stats, 0, sizeof(*stats));
78 stats->render_min_ns = 1ull << 62u;
79 stats->raster_min_bytes = 1ull << 62u;
80 stats->raster_min_ns = 1ull << 62u;
81 stats->writeout_min_ns = 1ull << 62u;
82 stats->fbbytes = fbbytes;
83 stats->planes = planes;
84}
Here is the caller graph for this function:

◆ summarize_stats()

void summarize_stats ( notcurses nc)

Definition at line 166 of file stats.c.

166 {
167 const ncstats *stats = &nc->stashed_stats;
168 char totalbuf[NCBPREFIXSTRLEN + 1];
169 char minbuf[NCBPREFIXSTRLEN + 1];
170 char maxbuf[NCBPREFIXSTRLEN + 1];
171 char avgbuf[NCBPREFIXSTRLEN + 1];
172 if(stats->renders){
173 ncqprefix(stats->render_ns, NANOSECS_IN_SEC, totalbuf, 0);
174 ncqprefix(stats->render_min_ns, NANOSECS_IN_SEC, minbuf, 0);
175 ncqprefix(stats->render_max_ns, NANOSECS_IN_SEC, maxbuf, 0);
176 ncqprefix(stats->render_ns / stats->renders, NANOSECS_IN_SEC, avgbuf, 0);
177 fprintf(stderr, "%"PRIu64" render%s, %ss (%ss min, %ss avg, %ss max)" NL,
178 stats->renders, stats->renders == 1 ? "" : "s",
179 totalbuf, minbuf, avgbuf, maxbuf);
180 }
181 if(stats->writeouts || stats->failed_writeouts){
182 ncqprefix(stats->raster_ns, NANOSECS_IN_SEC, totalbuf, 0);
183 ncqprefix(stats->raster_min_ns, NANOSECS_IN_SEC, minbuf, 0);
184 ncqprefix(stats->raster_max_ns, NANOSECS_IN_SEC, maxbuf, 0);
185 ncqprefix(stats->raster_ns / (stats->writeouts + stats->failed_writeouts),
186 NANOSECS_IN_SEC, avgbuf, 0);
187 fprintf(stderr, "%"PRIu64" raster%s, %ss (%ss min, %ss avg, %ss max)" NL,
188 stats->writeouts, stats->writeouts == 1 ? "" : "s",
189 totalbuf, minbuf, avgbuf, maxbuf);
190 ncqprefix(stats->writeout_ns, NANOSECS_IN_SEC, totalbuf, 0);
191 ncqprefix(stats->writeout_ns ? stats->writeout_min_ns : 0,
192 NANOSECS_IN_SEC, minbuf, 0);
193 ncqprefix(stats->writeout_max_ns, NANOSECS_IN_SEC, maxbuf, 0);
194 ncqprefix(stats->writeouts ? stats->writeout_ns / stats->writeouts : 0,
195 NANOSECS_IN_SEC, avgbuf, 0);
196 fprintf(stderr, "%"PRIu64" write%s, %ss (%ss min, %ss avg, %ss max)" NL,
197 stats->writeouts, stats->writeouts == 1 ? "" : "s",
198 totalbuf, minbuf, avgbuf, maxbuf);
199 }
200 if(stats->renders || stats->input_events){
201 ncbprefix(stats->raster_bytes, 1, totalbuf, 1),
202 ncbprefix(stats->raster_bytes ? stats->raster_min_bytes : 0,
203 1, minbuf, 1),
204 ncbprefix(stats->renders ? stats->raster_bytes / stats->renders : 0, 1, avgbuf, 1);
205 ncbprefix(stats->raster_max_bytes, 1, maxbuf, 1),
206 fprintf(stderr, "%sB (%sB min, %sB avg, %sB max) %"PRIu64" input%s Ghpa: %"PRIu64 NL,
207 totalbuf, minbuf, avgbuf, maxbuf,
208 stats->input_events,
209 stats->input_events == 1 ? "" : "s",
210 stats->hpa_gratuitous);
211 }
212 fprintf(stderr, "%"PRIu64" failed render%s, %"PRIu64" failed raster%s, %"
213 PRIu64" refresh%s, %"PRIu64" input error%s" NL,
214 stats->failed_renders, stats->failed_renders == 1 ? "" : "s",
215 stats->failed_writeouts, stats->failed_writeouts == 1 ? "" : "s",
216 stats->refreshes, stats->refreshes == 1 ? "" : "es",
217 stats->input_errors, stats->input_errors == 1 ? "" : "s");
218 fprintf(stderr, "RGB emits:elides: def %"PRIu64":%"PRIu64" fg %"PRIu64":%"
219 PRIu64" bg %"PRIu64":%"PRIu64 NL,
220 stats->defaultemissions,
221 stats->defaultelisions,
222 stats->fgemissions,
223 stats->fgelisions,
224 stats->bgemissions,
225 stats->bgelisions);
226 fprintf(stderr, "Cell emits:elides: %"PRIu64":%"PRIu64" (%.2f%%) %.2f%% %.2f%% %.2f%%" NL,
227 stats->cellemissions, stats->cellelisions,
228 (stats->cellemissions + stats->cellelisions) == 0 ? 0 :
229 (stats->cellelisions * 100.0) / (stats->cellemissions + stats->cellelisions),
230 (stats->defaultemissions + stats->defaultelisions) == 0 ? 0 :
231 (stats->defaultelisions * 100.0) / (stats->defaultemissions + stats->defaultelisions),
232 (stats->fgemissions + stats->fgelisions) == 0 ? 0 :
233 (stats->fgelisions * 100.0) / (stats->fgemissions + stats->fgelisions),
234 (stats->bgemissions + stats->bgelisions) == 0 ? 0 :
235 (stats->bgelisions * 100.0) / (stats->bgemissions + stats->bgelisions));
236 ncbprefix(stats->sprixelbytes, 1, totalbuf, 1);
237 fprintf(stderr, "Bmap emits:elides: %"PRIu64":%"PRIu64" (%.2f%%) %sB (%.2f%%) SuM: %"PRIu64" (%.2f%%)" NL,
238 stats->sprixelemissions, stats->sprixelelisions,
239 (stats->sprixelemissions + stats->sprixelelisions) == 0 ? 0 :
240 (stats->sprixelelisions * 100.0) / (stats->sprixelemissions + stats->sprixelelisions),
241 totalbuf,
242 stats->raster_bytes ? (stats->sprixelbytes * 100.0) / stats->raster_bytes : 0,
243 stats->appsync_updates,
244 stats->writeouts ? stats->appsync_updates * 100.0 / stats->writeouts : 0);
245 if(stats->cell_geo_changes || stats->pixel_geo_changes){
246 fprintf(stderr,"Screen/cell geometry changes: %"PRIu64"/%"PRIu64 NL,
247 stats->cell_geo_changes, stats->pixel_geo_changes);
248 }
249}
#define NCBPREFIXSTRLEN
Definition notcurses.h:3830
Here is the caller graph for this function:

◆ update_raster_bytes()

void update_raster_bytes ( ncstats stats,
int  bytes 
)

Definition at line 27 of file stats.c.

27 {
28 if(bytes >= 0){
29 stats->raster_bytes += bytes;
30 if(bytes > stats->raster_max_bytes){
31 stats->raster_max_bytes = bytes;
32 }
33 if(bytes < stats->raster_min_bytes){
34 stats->raster_min_bytes = bytes;
35 }
36 }
37}
Here is the caller graph for this function:

◆ update_raster_stats()

void update_raster_stats ( const struct timespec *  time1,
const struct timespec *  time0,
ncstats stats 
)

Definition at line 58 of file stats.c.

59 {
60 const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0);
61 //fprintf(stderr, "Rasterizing took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC,
62 // (elapsed % NANOSECS_IN_SEC) / 1000000);
63 if(elapsed > 0){ // don't count clearly incorrect information, egads
64 stats->raster_ns += elapsed;
65 if(elapsed > stats->raster_max_ns){
66 stats->raster_max_ns = elapsed;
67 }
68 if(elapsed < stats->raster_min_ns){
69 stats->raster_min_ns = elapsed;
70 }
71 }
72}
Here is the caller graph for this function:

◆ update_render_stats()

void update_render_stats ( const struct timespec *  time1,
const struct timespec *  time0,
ncstats stats 
)

Definition at line 40 of file stats.c.

41 {
42 const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0);
43 //fprintf(stderr, "Rendering took %ld.%03lds\n", elapsed / NANOSECS_IN_SEC,
44 // (elapsed % NANOSECS_IN_SEC) / 1000000);
45 if(elapsed > 0){ // don't count clearly incorrect information, egads
46 ++stats->renders;
47 stats->render_ns += elapsed;
48 if(elapsed > stats->render_max_ns){
49 stats->render_max_ns = elapsed;
50 }
51 if(elapsed < stats->render_min_ns){
52 stats->render_min_ns = elapsed;
53 }
54 }
55}
Here is the caller graph for this function:

◆ update_write_stats()

void update_write_stats ( const struct timespec *  time1,
const struct timespec *  time0,
ncstats stats,
int  bytes 
)

Definition at line 5 of file stats.c.

6 {
7 if(bytes >= 0){
8 const int64_t elapsed = timespec_to_ns(time1) - timespec_to_ns(time0);
9 if(elapsed > 0){ // don't count clearly incorrect information, egads
10 ++stats->writeouts;
11 stats->writeout_ns += elapsed;
12 if(elapsed > stats->writeout_max_ns){
13 stats->writeout_max_ns = elapsed;
14 }
15 if(elapsed < stats->writeout_min_ns){
16 stats->writeout_min_ns = elapsed;
17 }
18 }
19 }else{
20 ++stats->failed_writeouts;
21 }
22}
Here is the caller graph for this function: