notcurses_reset_stats() added + test #164

pull/193/head
nick black 5 years ago
parent 15ac1d0411
commit 32e9fd0a1d
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -1820,6 +1820,9 @@ typedef struct ncstats {
// Acquire a snapshot of the notcurses object's stats.
void notcurses_stats(const struct notcurses* nc, ncstats* stats);
// Reset all stats.
void notcurses_reset_stats(struct notcurses* nc);
```
Timings for renderings are across the breadth of `notcurses_render()`: they

@ -304,6 +304,9 @@ typedef struct ncstats {
// Acquire a snapshot of the notcurses object's stats.
API void notcurses_stats(const struct notcurses* nc, ncstats* stats);
// Reset all stats.
API void notcurses_reset_stats(struct notcurses* nc);
// Resize the specified ncplane. The four parameters 'keepy', 'keepx',
// 'keepleny', and 'keeplenx' define a subset of the ncplane to keep,
// unchanged. This may be a section of size 0, though none of these four

@ -653,6 +653,12 @@ make_nonblocking(FILE* fp){
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
void notcurses_reset_stats(notcurses* nc){
memset(&nc->stats, 0, sizeof(nc->stats));
nc->stats.render_min_ns = 1ul << 62u;
nc->stats.render_min_bytes = 1ul << 62u;
}
notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
const char* encoding = nl_langinfo(CODESET);
if(encoding == NULL || strcmp(encoding, "UTF-8")){
@ -669,9 +675,7 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
free(ret);
return NULL;
}
memset(&ret->stats, 0, sizeof(ret->stats));
ret->stats.render_min_ns = 1ul << 62u;
ret->stats.render_min_bytes = 1ul << 62u;
notcurses_reset_stats(ret);
ret->ttyfp = outfp;
ret->renderfp = opts->renderfp;
ret->inputescapes = NULL;

@ -138,3 +138,15 @@ TEST_F(NotcursesTest, ChannelSetBGAlpha){
EXPECT_TRUE(channels_fg_default_p(channel));
EXPECT_TRUE(channels_bg_default_p(channel));
}
TEST_F(NotcursesTest, Stats){
struct ncstats stats;
notcurses_stats(nc_, &stats);
EXPECT_EQ(0, stats.renders);
EXPECT_EQ(0, notcurses_render(nc_));
notcurses_stats(nc_, &stats);
EXPECT_EQ(1, stats.renders);
notcurses_reset_stats(nc_);
notcurses_stats(nc_, &stats);
EXPECT_EQ(0, stats.renders);
}

Loading…
Cancel
Save