diff options
author | Guido Lerch <guido.lerch@gmail.com> | 2015-09-05 11:15:05 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-05 11:29:13 -0700 |
commit | ff0859ff213bca011e33c74db01e1e8e4803fa18 (patch) | |
tree | 63a46f4a6a0d7f6aab19adc61a23cc6563ed64f7 /uemis-downloader.c | |
parent | 4ba5dd85d4078d320b4d16d94fb3f973e54fcadb (diff) | |
download | subsurface-ff0859ff213bca011e33c74db01e1e8e4803fa18.tar.gz |
Uemis downloader: add helper function to estimate memory needs
[Dirk Hohndel: refactored one huge commit into smaller pieces]
Signed-off-by: Guido Lerch <guido.lerch@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'uemis-downloader.c')
-rw-r--r-- | uemis-downloader.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/uemis-downloader.c b/uemis-downloader.c index 8c72354ef..16d7811ae 100644 --- a/uemis-downloader.c +++ b/uemis-downloader.c @@ -34,6 +34,9 @@ //#define UEMIS_DEBUG 1 + 2 #define UEMIS_MAX_FILES 4000 +#define UEMIS_MEM_FULL 3 +#define UEMIS_MEM_CRITICAL 1 +#define UEMIS_MEM_OK 0 #if UEMIS_DEBUG & 64 /* we are reading from a copy of the filesystem, not the device - no need to wait */ #define UEMIS_TIMEOUT 50 /* 50ns */ @@ -900,6 +903,39 @@ static char *uemis_get_divenr(char *deviceidstr) return strdup(divenr); } +/* do some more sophisticated calculations here to try and predict if the next round of + * divelog/divedetail reads will fit into the UEMIS buffer, + * filenr holds now the uemis filenr after having read several logs including the dive details, + * fCapacity will five us the average number of files needed for all currently loaded data + * remember the maximum file usage per dive + * return : UEMIS_MEM_OK if there is enough memeory for a full round + * UEMIS_MEM_CRITICAL if the memory is good for reading the dive logs + * UEMIS_MEM_FULL if the memory is exhaused + */ +static int get_memory(struct dive_table *td) +{ + + if (td->nr == 0) + return UEMIS_MEM_OK; + + if (filenr / td->nr > max_mem_used) + max_mem_used = filenr / td->nr; + /* predict based on the max_mem_used value if the set of next 11 divelogs plus details + * fit into the memory before we have to disconnect the UEMIS and continuem. To be on + * the safe side we calculate using 12 dives. */ + if (max_mem_used * 11 > UEMIS_MAX_FILES - filenr) { + /* the next set of divelogs will most likely not fit into the memory */ + if (nr_divespots * 2 > UEMIS_MAX_FILES - filenr) { + /* if we get here we have a severe issue as the divespots will not fit into + * this run either. */ + return UEMIS_MEM_FULL; + } + /* we continue reading the divespots */ + return UEMIS_MEM_CRITICAL; + } + return UEMIS_MEM_OK; +} + const char *do_uemis_import(device_data_t *data) { const char *mountpath = data->devname; |