From: Jaroslav Kysela Date: Sun, 13 Nov 2016 20:50:18 +0000 (+0100) Subject: timeshift: add memoryinfo support X-Git-Tag: v4.2.1~224 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2411090173dfae4fc07a934fb73c84329983c704;p=thirdparty%2Ftvheadend.git timeshift: add memoryinfo support --- diff --git a/src/timeshift.c b/src/timeshift.c index 3502b258b..4e5de790f 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -38,6 +38,9 @@ static int timeshift_index = 0; struct timeshift_conf timeshift_conf; +memoryinfo_t timeshift_memoryinfo = { .my_name = "Timeshift" }; +memoryinfo_t timeshift_memoryinfo_ram = { .my_name = "Timeshift RAM buffer" }; + /* * Packet log */ @@ -75,6 +78,9 @@ void timeshift_init ( void ) { htsmsg_t *m; + memoryinfo_register(×hift_memoryinfo); + memoryinfo_register(×hift_memoryinfo_ram); + timeshift_filemgr_init(); /* Defaults */ @@ -101,6 +107,9 @@ void timeshift_term ( void ) timeshift_filemgr_term(); free(timeshift_conf.path); timeshift_conf.path = NULL; + + memoryinfo_unregister(×hift_memoryinfo); + memoryinfo_unregister(×hift_memoryinfo_ram); } /* @@ -418,7 +427,9 @@ timeshift_destroy(streaming_target_t *pad) if (ts->path) free(ts->path); + free(ts); + memoryinfo_free(×hift_memoryinfo, sizeof(timeshift_t)); } /** @@ -432,6 +443,8 @@ streaming_target_t *timeshift_create { timeshift_t *ts = calloc(1, sizeof(timeshift_t)); + memoryinfo_alloc(×hift_memoryinfo, sizeof(timeshift_t)); + /* Must hold global lock */ lock_assert(&global_lock); diff --git a/src/timeshift.h b/src/timeshift.h index 49b2afb20..1252bfa05 100644 --- a/src/timeshift.h +++ b/src/timeshift.h @@ -20,6 +20,7 @@ #define __TVH_TIMESHIFT_H__ #include "idnode.h" +#include "memoryinfo.h" typedef struct timeshift_conf { idnode_t idnode; @@ -41,6 +42,9 @@ typedef struct timeshift_conf { extern struct timeshift_conf timeshift_conf; extern const idclass_t timeshift_conf_class; +extern memoryinfo_t timeshift_memoryinfo; +extern memoryinfo_t timeshift_memoryinfo_ram; + void timeshift_init ( void ); void timeshift_term ( void ); diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index 21195bfde..06e3e846f 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -1,4 +1,4 @@ -/** +/* * TV headend - Timeshift File Manager * Copyright (C) 2012 Adam Sutton * @@ -81,16 +81,20 @@ static void* timeshift_reaper_callback ( void *p ) /* Free memory */ while ((ti = TAILQ_FIRST(&tsf->iframes))) { TAILQ_REMOVE(&tsf->iframes, ti, link); + memoryinfo_free(×hift_memoryinfo, sizeof(*ti)); free(ti); } while ((tid = TAILQ_FIRST(&tsf->sstart))) { TAILQ_REMOVE(&tsf->sstart, tid, link); sm = tid->data; streaming_msg_free(sm); + memoryinfo_free(×hift_memoryinfo, sizeof(*tid)); free(tid); } free(tsf->path); + memoryinfo_free(×hift_memoryinfo_ram, tsf->ram_size); free(tsf->ram); + memoryinfo_free(×hift_memoryinfo, sizeof(*tsf)); free(tsf); pthread_mutex_lock(×hift_reaper_lock); @@ -178,6 +182,7 @@ void timeshift_filemgr_close ( timeshift_file_t *tsf ) /* maintain unused memory block */ ram = realloc(tsf->ram, tsf->woff); if (ram) { + memoryinfo_append(×hift_memoryinfo_ram, tsf->ram_size - tsf->woff); tsf->ram = ram; tsf->ram_size = tsf->woff; } @@ -238,6 +243,7 @@ static timeshift_file_t * timeshift_filemgr_file_init timeshift_file_t *tsf; tsf = calloc(1, sizeof(timeshift_file_t)); + memoryinfo_alloc(×hift_memoryinfo, sizeof(*tsf)); tsf->time = mono2sec(start_time) / TIMESHIFT_FILE_PERIOD; tsf->last = start_time; tsf->wfd = -1; @@ -331,6 +337,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int64_t start_time ) tvhtrace(LS_TIMESHIFT, "ts %d create RAM segment with %"PRId64" bytes (time %"PRId64")", ts->id, tsf_tmp->ram_size, start_time); ts->ram_segments++; + memoryinfo_alloc(×hift_memoryinfo_ram, tsf_tmp->ram_size); } break; } else { @@ -371,6 +378,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int64_t start_time ) ts->id, ti ? " (from last file)" : ""); timeshift_index_data_t *ti2 = calloc(1, sizeof(timeshift_index_data_t)); if (ti) { + memoryinfo_alloc(×hift_memoryinfo, sizeof(timeshift_index_data_t)); sm = streaming_msg_clone(ti->data); } else { sm = streaming_msg_create(SMT_START); diff --git a/src/timeshift/timeshift_writer.c b/src/timeshift/timeshift_writer.c index 199214415..c300ee6e5 100644 --- a/src/timeshift/timeshift_writer.c +++ b/src/timeshift/timeshift_writer.c @@ -73,6 +73,7 @@ static ssize_t _write pthread_mutex_unlock(&tsf->ram_lock); return -1; } + memoryinfo_append(×hift_memoryinfo_ram, alloc); tsf->ram = ram; tsf->ram_size += alloc; } @@ -257,6 +258,7 @@ static void _handle_sstart ( timeshift_t *ts, timeshift_file_t *tsf, streaming_m { timeshift_index_data_t *ti = calloc(1, sizeof(timeshift_index_data_t)); + memoryinfo_alloc(×hift_memoryinfo, sizeof(*ti)); ti->pos = tsf->size; ti->data = sm; TAILQ_INSERT_TAIL(&tsf->sstart, ti, link); @@ -285,6 +287,7 @@ static inline ssize_t _process_msg0 if (pkt->pkt_componentindex == ts->vididx && pkt->pkt_frametype == PKT_I_FRAME) { timeshift_index_iframe_t *ti = calloc(1, sizeof(timeshift_index_iframe_t)); + memoryinfo_alloc(×hift_memoryinfo, sizeof(*ti)); ti->pos = tsf->size; ti->time = sm->sm_time; TAILQ_INSERT_TAIL(&tsf->iframes, ti, link);