Skip to content

OfflineLogStorage stops outputting logs after repeated enable/disable cycles #778

@mse-kondou-hitomi

Description

@mse-kondou-hitomi

Steps to reproduce:

  1. Enable OfflineLogStorage
  2. Output some logs
  3. Disable OfflineLogStorage
  4. Modify the OfflineLogStorage configuration file (only change the output file name)

Repeat steps 1–4.

Starting from the third iteration, the following log appears in dlt-daemon, and logs are no longer written to the file:

dlt_logstorage_prepare_msg_cache: Max size of Logstorage Cache already used. (ApId=[TIME] CtId=[.*])
dlt_logstorage_write: Unable to prepare. Skip filename [1030401715] because maxmimum trial has been reached.

Configuration details

dlt.conf -> OfflineLogStorageCacheSize is comment out.

# Maximal used memory for Logstorage Cache in KB (Default: 30000 KB)
# OfflineLogstorageCacheSize = 30000

dlt_logstorage.conf -> FileSize is 10485760(10MB).

[FILTER1]
LogAppName=TIME
ContextName=.*
EcuID=ECU1
LogLevel=DLT_LOG_INFO
File=dummy
FileSize=10485760
SyncBehavior=ON_DEMAND
NOFiles=10

Upon investigation, it was found that the global variable g_logstorage_cache_size, which manages the total cache size of OfflineLogStorage,
is incremented when OfflineLogStorage is enabled but not decremented when it is disabled.
As a result, when enabling it for the third time, the system determines that the cache size limit has been exceeded.

/* update current used cache size */
g_logstorage_cache_size += cache_size + sizeof(DltLogStorageCacheFooter);

1st: 10MB+16byte < 30MB ->OK
2nd: 10MB+16byte+10MB+16byte < 30MB ->OK
3rd: 10MB+16byte+10MB+16byte+10MB+16byte > 30MB ->NG

Proposed fix

When disabling OfflineLogStorage, subtract the previously added cache size.

src/offlinelogstorage/dlt_offline_logstorage.c

DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *data)
{
     ~~~
    if (data->cache != NULL) {
        free(data->cache);
        data->cache = NULL;

+       unsigned int cache_size = 0;
+      /* check for sync_specific_size strategy */
+      if (DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(data->sync,
+             DLT_LOGSTORAGE_SYNC_ON_SPECIFIC_SIZE) > 0)
+      {
+          cache_size = data->specific_size + sizeof(DltLogStorageCacheFooter);
+      }
+      else  /* other cache strategies */
+      {
+          cache_size = data->file_size + sizeof(DltLogStorageCacheFooter);
+      }
+      g_logstorage_cache_size = (g_logstorage_cache_size > cache_size) ? (g_logstorage_cache_size - cache_size) : 0;
+  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions