Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
epgdb: improve statistics logs
  • Loading branch information
perexg committed Sep 27, 2016
1 parent 59d93dd commit 0c79a1d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
18 changes: 10 additions & 8 deletions src/epgdb.c
Expand Up @@ -344,13 +344,15 @@ void epg_init ( void )
#if ENABLE_ZLIB
if (remain > 12 && memcmp(rp, "\xff\xffGZIP00", 8) == 0) {
uint32_t orig = (rp[8] << 24) | (rp[9] << 16) | (rp[10] << 8) | rp[11];
tvhinfo(LS_EPGDB, "gzip format detected, inflating (ratio %.1f%%)",
(float)((remain * 100.0) / orig));
tvhinfo(LS_EPGDB, "gzip format detected, inflating (ratio %.1f%% deflated size %zd)",
(float)((remain * 100.0) / orig), remain);
rp = zlib_mem = tvh_gzip_inflate(rp + 12, remain - 12, orig);
remain = rp ? orig : 0;
}
#endif

tvhinfo(LS_EPGDB, "parsing %zd bytes", remain);

/* Process */
memset(&stats, 0, sizeof(stats));
while ( remain > 4 ) {
Expand Down Expand Up @@ -402,7 +404,7 @@ void epg_init ( void )
/* Stats */
tvhinfo(LS_EPGDB, "loaded v%d", ver);
tvhinfo(LS_EPGDB, " config %d", stats.config.total);
tvhinfo(LS_EPGDB, " channels %d", stats.channels.total);
//tvhinfo(LS_EPGDB, " channels %d", stats.channels.total);
tvhinfo(LS_EPGDB, " brands %d", stats.brands.total);
tvhinfo(LS_EPGDB, " seasons %d", stats.seasons.total);
tvhinfo(LS_EPGDB, " episodes %d", stats.episodes.total);
Expand Down Expand Up @@ -468,23 +470,23 @@ static int _epg_write_sect ( sbuf_t *sb, const char *sect )
static void epg_save_tsk_callback ( void *p, int dearmed )
{
sbuf_t *sb = p;
size_t size = sb->sb_ptr;
size_t size = sb->sb_ptr, orig;
int fd, r;

tvhinfo(LS_EPGDB, "save start");
fd = hts_settings_open_file(1, "epgdb.v%d", EPG_DB_VERSION);
if (fd >= 0) {
#if ENABLE_ZLIB
if (config.epg_compress) {
r = tvh_gzip_deflate_fd_header(fd, sb->sb_data, sb->sb_ptr, 3) < 0;
r = tvh_gzip_deflate_fd_header(fd, sb->sb_data, size, &orig, 3) < 0;
} else
#endif
r = tvh_write(fd, sb->sb_data, sb->sb_ptr);
r = tvh_write(fd, sb->sb_data, orig = size);
close(fd);
if (r)
tvherror(LS_EPGDB, "write error (size %zd)", size);
tvherror(LS_EPGDB, "write error (size %zd)", orig);
else
tvhinfo(LS_EPGDB, "stored (size %zd)", size);
tvhinfo(LS_EPGDB, "stored (size %zd)", orig);
} else
tvherror(LS_EPGDB, "unable to open epgdb file");
sbuf_free(sb);
Expand Down
2 changes: 1 addition & 1 deletion src/settings.c
Expand Up @@ -184,7 +184,7 @@ hts_settings_save(htsmsg_t *record, const char *pathfmt, ...)
size_t msglen;
r = htsmsg_binary_serialize(record, &msgdata, &msglen, 2*1024*1024);
if (!r && msglen >= 4) {
r = tvh_gzip_deflate_fd_header(fd, msgdata + 4, msglen - 4, 3);
r = tvh_gzip_deflate_fd_header(fd, msgdata + 4, msglen - 4, NULL, 3);
if (r)
ok = 0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/tvheadend.h
Expand Up @@ -821,7 +821,7 @@ char *regexp_escape ( const char *str );
uint8_t *tvh_gzip_inflate ( const uint8_t *data, size_t size, size_t orig );
uint8_t *tvh_gzip_deflate ( const uint8_t *data, size_t orig, size_t *size );
int tvh_gzip_deflate_fd ( int fd, const uint8_t *data, size_t orig, size_t *size, int speed );
int tvh_gzip_deflate_fd_header ( int fd, const uint8_t *data, size_t orig, int speed );
int tvh_gzip_deflate_fd_header ( int fd, const uint8_t *data, size_t orig, size_t *size, int speed );
#endif

/* URL decoding */
Expand Down
13 changes: 8 additions & 5 deletions src/zlib.c
Expand Up @@ -153,23 +153,26 @@ int tvh_gzip_deflate_fd ( int fd, const uint8_t *data, size_t orig, size_t *size
return r;
}

int tvh_gzip_deflate_fd_header ( int fd, const uint8_t *data, size_t orig, int speed )
int tvh_gzip_deflate_fd_header ( int fd, const uint8_t *data, size_t orig,
size_t *deflated_size, int speed )
{
uint8_t data2[4];
size_t size;
size_t size = 0;
int r;

if (deflated_size) *deflated_size = 0;
r = tvh_write(fd, "\xff\xffGZIP00\x00\x00\x00\x00", 12);
if (r)
return 1;
if (orig > 0) {
r = tvh_gzip_deflate_fd(fd, data, orig, &size, 3) < 0;
if (r || size > UINT_MAX)
return 1;
r = lseek(fd, 8, SEEK_SET) != (off_t)8;
if (r)
return 1;
}
r = lseek(fd, 8, SEEK_SET) != (off_t)8;
if (r)
return 1;
if (deflated_size) *deflated_size = size + 12;
data2[0] = (orig >> 24) & 0xff;
data2[1] = (orig >> 16) & 0xff;
data2[2] = (orig >> 8) & 0xff;
Expand Down

0 comments on commit 0c79a1d

Please sign in to comment.