mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
add stat for ASUs and send them #1582
This commit is contained in:
parent
1f19ee3bb1
commit
041f97371f
1
NEWS.md
1
NEWS.md
@ -32,6 +32,7 @@ rearrangements of Notcurses.
|
||||
`ncpile_render_to_file()`. Rewrote `notcurses_render_to_buffer()` and
|
||||
`notcurses_render_to_file()` as trivial wrappers around these functions,
|
||||
and deprecated the latter. They will be removed in ABI3.
|
||||
* Added support for application-synchronized updates, and a new stat.
|
||||
|
||||
* 2.3.4 (2021-06-12)
|
||||
* Added the flag `NCVISUAL_OPTION_NOINTERPOLATE` to use non-interpolative
|
||||
|
1
USAGE.md
1
USAGE.md
@ -3399,6 +3399,7 @@ typedef struct ncstats {
|
||||
uint64_t sprixelemissions; // sprixel draw count
|
||||
uint64_t sprixelelisions; // sprixel elision count
|
||||
uint64_t sprixelbytes; // sprixel bytes emitted
|
||||
uint64_t appsync_updates; // application-synchronized updates
|
||||
|
||||
// current state -- these can decrease
|
||||
uint64_t fbbytes; // total bytes devoted to all active framebuffers
|
||||
|
@ -41,6 +41,7 @@ typedef struct ncstats {
|
||||
uint64_t sprixelemissions; // sprixel draw count
|
||||
uint64_t sprixelelisions; // sprixel elision count
|
||||
uint64_t sprixelbytes; // sprixel bytes emitted
|
||||
uint64_t appsync_updates; // application-synchronized updates
|
||||
|
||||
// current state -- these can decrease
|
||||
uint64_t fbbytes; // bytes devoted to framebuffers
|
||||
|
@ -1393,6 +1393,7 @@ typedef struct ncstats {
|
||||
uint64_t defaultelisions; // default color was emitted
|
||||
uint64_t defaultemissions; // default color was elided
|
||||
uint64_t refreshes; // refresh requests (non-optimized redraw)
|
||||
uint64_t appsync_updates; // how many application-synchronized updates?
|
||||
|
||||
// current state -- these can decrease
|
||||
uint64_t fbbytes; // total bytes devoted to all active framebuffers
|
||||
|
@ -819,7 +819,7 @@ stash_string(query_state* inits){
|
||||
// ought be fed to the machine, and -1 on an invalid state transition.
|
||||
static int
|
||||
pump_control_read(query_state* inits, unsigned char c){
|
||||
fprintf(stderr, "state: %2d char: %1c %3d %02x\n", inits->state, isprint(c) ? c : ' ', c, c);
|
||||
//fprintf(stderr, "state: %2d char: %1c %3d %02x\n", inits->state, isprint(c) ? c : ' ', c, c);
|
||||
if(c == NCKEY_ESC){
|
||||
inits->state = STATE_ESC;
|
||||
return 0;
|
||||
|
@ -1096,8 +1096,12 @@ rasterize_core(notcurses* nc, const ncpile* p, FILE* out, unsigned phase){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 'asu' on input is non-0 if application-synchronized updates are permitted
|
||||
// (they are not, for instance, when rendering to a non-tty). on output,
|
||||
// assuming success, it is non-0 if application-synchronized updates are
|
||||
// desired; in this case, an ASU footer is present at the end of the buffer.
|
||||
static int
|
||||
notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out){
|
||||
notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out, unsigned* asu){
|
||||
fseeko(out, 0, SEEK_SET);
|
||||
// we only need to emit a coordinate if it was damaged. the damagemap is a
|
||||
// bit per coordinate, one per struct crender.
|
||||
@ -1130,19 +1134,44 @@ notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out){
|
||||
if(fflush(out)){
|
||||
return -1;
|
||||
}
|
||||
#define MIN_ASU_SIZE 4096 // FIXME
|
||||
if(*asu){
|
||||
if(nc->rstate.mstrsize >= MIN_ASU_SIZE){
|
||||
const char* endasu = get_escape(&nc->tcache, ESCAPE_ESU);
|
||||
if(endasu){
|
||||
if(fprintf(out, endasu) < 0 || fflush(out)){
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
*asu = 0;
|
||||
}
|
||||
}else{
|
||||
*asu = 0;
|
||||
}
|
||||
}
|
||||
#undef MIN_ASU_SIZE
|
||||
return nc->rstate.mstrsize;
|
||||
}
|
||||
|
||||
// rasterize the rendered frame, and blockingly write it out to the terminal.
|
||||
static int
|
||||
raster_and_write(notcurses* nc, ncpile* p, FILE* out){
|
||||
if(notcurses_rasterize_inner(nc, p, out) < 0){
|
||||
// will we be using application-synchronized updates? if this comes back as
|
||||
// non-zero, we are, and must emit the header. no ASU without a tty.
|
||||
unsigned useasu = nc->ttyfd >= 0 ? true : false;
|
||||
if(notcurses_rasterize_inner(nc, p, out, &useasu) < 0){
|
||||
return -1;
|
||||
}
|
||||
int ret = 0;
|
||||
//fflush(nc->ttyfp);
|
||||
sigset_t oldmask;
|
||||
block_signals(&oldmask);
|
||||
if(useasu){
|
||||
const char* basu = get_escape(&nc->tcache, ESCAPE_BSU);
|
||||
if(tty_emit(basu, nc->ttyfd)){
|
||||
ret = -1;
|
||||
}
|
||||
++nc->stats.appsync_updates;
|
||||
}
|
||||
if(blocking_write(fileno(nc->ttyfp), nc->rstate.mstream, nc->rstate.mstrsize)){
|
||||
ret = -1;
|
||||
}
|
||||
@ -1384,7 +1413,8 @@ int ncpile_render_to_buffer(ncplane* p, char** buf, size_t* buflen){
|
||||
return -1;
|
||||
}
|
||||
notcurses* nc = ncplane_notcurses(p);
|
||||
int bytes = notcurses_rasterize_inner(nc, ncplane_pile(p), nc->rstate.mstreamfp);
|
||||
unsigned useacu = false; // no ACU to file
|
||||
int bytes = notcurses_rasterize_inner(nc, ncplane_pile(p), nc->rstate.mstreamfp, &useacu);
|
||||
pthread_mutex_lock(&nc->statlock);
|
||||
update_render_bytes(&nc->stats, bytes);
|
||||
pthread_mutex_unlock(&nc->statlock);
|
||||
|
@ -144,6 +144,7 @@ void notcurses_stats_reset(notcurses* nc, ncstats* stats){
|
||||
stash->sprixelemissions += nc->stats.sprixelemissions;
|
||||
stash->sprixelelisions += nc->stats.sprixelelisions;
|
||||
stash->sprixelbytes += nc->stats.sprixelbytes;
|
||||
stash->appsync_updates += nc->stats.appsync_updates;
|
||||
|
||||
stash->fbbytes = nc->stats.fbbytes;
|
||||
stash->planes = nc->stats.planes;
|
||||
@ -214,10 +215,10 @@ void summarize_stats(notcurses* nc){
|
||||
(stats->bgelisions * 100.0) / (stats->bgemissions + stats->bgelisions));
|
||||
char totalbuf[BPREFIXSTRLEN + 1];
|
||||
qprefix(stats->sprixelbytes, 1, totalbuf, 1);
|
||||
fprintf(stderr, "Sprixel emits:elides: %ju:%ju (%.2f%%) %sB\n",
|
||||
fprintf(stderr, "Sprixel emits:elides: %ju:%ju (%.2f%%) %sB ASUs: %ju\n",
|
||||
stats->sprixelemissions, stats->sprixelelisions,
|
||||
(stats->sprixelemissions + stats->sprixelelisions) == 0 ? 0 :
|
||||
(stats->sprixelelisions * 100.0) / (stats->sprixelemissions + stats->sprixelelisions),
|
||||
totalbuf);
|
||||
totalbuf, stats->appsync_updates);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user