Create a DLT logs in C++. Problem with dlt-deamon

428 Views Asked by At

I have this code in c++ (extracted from the documentation):

#include <dlt/dlt.h>

DLT_DECLARE_CONTEXT(ctx); /* declare context */

int main()
{
    DLT_REGISTER_APP("TAPP", "Test Application for Logging");

    DLT_REGISTER_CONTEXT(ctx, "TES1", "Test Context for Logging");

    /* … */

    DLT_LOG(ctx, DLT_LOG_ERROR, DLT_CSTRING("This is an error"));
    DLT_LOG(ctx, DLT_LOG_INFO, DLT_CSTRING("This is an very important info: Hello"));

    /* … */

    DLT_UNREGISTER_CONTEXT(ctx);
    DLT_UNREGISTER_APP();
    return 0;
}

And this cmake file:

cmake_minimum_required(VERSION 3.10)
project(DLTExample)

# Encuentra la biblioteca DLT
find_package(automotive-dlt REQUIRED)

# Agrega los archivos fuente de tu programa
add_executable(DLTExample dltExample.cpp)

# Enlaza con la biblioteca DLT

target_link_libraries(DLTExample PRIVATE Genivi::dlt)

When I run the code I have this output:

[  615.286034]~DLT~ 7558~INFO     ~FIFO /tmp/dlt cannot be opened. Retrying later...
[  625.304701]~DLT~ 7558~WARNING  ~Lost log messages in user buffer when exiting: 6

I also tried to run the executable of my code with sudo but the output is the same.

I downloaded dlt-daemon from https://github.com/COVESA/dlt-daemon/tree/master and follow the instructions to install it (included sudo make install and sudo ldconfig).

When I type on the terminal dlt-daemon I have:

[ 1743.468119]~DLT~ 9406~NOTICE   ~Starting DLT Daemon; DLT Package Version: 2.18.10 STABLE, Package Revision: v2.18.10_14_g7a55368, build on Nov 15 2023 13:02:13 -SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM
[ 1743.468196]~DLT~ 9406~ERROR    ~FIFO user dir /tmp/dltpipes cannot be chmoded (Operation not permitted)!
[ 1743.468209]~DLT~ 9406~CRITICAL ~Initialization of phase 1 failed!

So I tried with sudo:

[ 1786.350247]~DLT~ 9472~NOTICE   ~Starting DLT Daemon; DLT Package Version: 2.18.10 STABLE, Package Revision: v2.18.10_14_g7a55368, build on Nov 15 2023 13:02:13
-SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM

[ 1786.350390]~DLT~ 9472~INFO     ~FIFO size: 65536
[ 1786.350415]~DLT~ 9472~WARNING  ~Unable to set send timeout Socket operation on non-socket.
[ 1786.350418]~DLT~ 9472~INFO     ~Activate connection type: 5
[ 1786.350439]~DLT~ 9472~INFO     ~dlt_daemon_socket_open: Socket created
[ 1786.350451]~DLT~ 9472~WARNING  ~dlt_daemon_socket_open: bind() error 98: Address already in use
[ 1786.350453]~DLT~ 9472~ERROR    ~Could not initialize main socket.
[ 1786.350455]~DLT~ 9472~CRITICAL ~Initialization of local connections failed!

As you can see there is still errors.

I also had this repo before I installed the dlt-daemon: https://github.com/COVESA/dlt-viewer/tree/master (I followed the install instructions)

I don't know what to do :( First I tried to change the permissions of the /tmp/dlt (I created the folder) but nothing happened so i removed it.

I just want to create a dlt file that works on dlt viewer so i can search and filter the logs there.

Any ideas?

Thanks in advance

2

There are 2 best solutions below

0
On

The problem was that I was not starting the dlt-receiver. So, you have to start the deamon, the receiver and the program that sends the dlt logs.

dlt-daemon

dlt-receive -o file_logs.dlt localhost
0
On

RCA: Both issues can be reproduced:

drmint@Old-Server:~/work/stackOF/example/build$ ./DLTExample
[ 1217.297547]~DLT~15389~INFO     ~FIFO /tmp/dlt cannot be opened. Retrying later...
[ 1227.315454]~DLT~15389~WARNING  ~Lost log messages in user buffer when exiting: 6

=> What is the root cause of this issue?

This is because dlt_user (DLTExample) is already started but no daemon available. In this case, logs will be stored in libdlt ring buffer, and when the app stops (by itself, by SIGKILL, etc), libdlt will try to fetch all the remaining logs to daemon. If deamon is still, saying, not available, all logs will be discarded.

What happend when you start dlt-daemon but this issue occurs?

drmint@Old-Server:~/work/stackOF/example/build$ dlt-daemon 
[ 1469.308306]~DLT~15418~NOTICE   ~Starting DLT Daemon; DLT Package Version: 2.18.10 STABLE, Package Revision: v2.18.10_14_g7a55368, build on Jan  8 2024 23:43:16
-SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM

[ 1469.308563]~DLT~15418~INFO     ~FIFO size: 65536
[ 1469.308618]~DLT~15418~WARNING  ~Unable to set send timeout Socket operation on non-socket.
[ 1469.308635]~DLT~15418~INFO     ~Activate connection type: 5
[ 1469.308676]~DLT~15418~INFO     ~dlt_daemon_socket_open: Socket created
[ 1469.308735]~DLT~15418~WARNING  ~dlt_daemon_socket_open: bind() error 98: Address already in use
[ 1469.308750]~DLT~15418~ERROR    ~Could not initialize main socket.
[ 1469.308768]~DLT~15418~CRITICAL ~Initialization of local connections failed!

The only reason is because another app/process is already running, taking the default port 3490:

drmint@Old-Server:~/work/stackOF/example/build$ socklist
type  port      inode     uid    pid   fd  name
tcp     53      25530    101      0    0 
tcp    631      29523      0      0    0 
tcp  37900     207181   1000   1720  112 firefox
tcp  49496     125332   1000   1720   56 firefox
tcp  41922     213895   1000   1720  106 firefox
tcp  59666     137533   1000   1720  111 firefox
tcp  36154     141221   1000   1720  207 firefox
tcp  35358     214702   1000   1720  175 firefox
tcp  36370      49222   1000   1720  147 firefox
tcp6   631      29522      0      0    0 
tcp6  3490     143450   1000  15636    4 dlt-daemon <= port in use
tcp6 33738          0      0      0    0 

Here I started dlt-daemon in daemonized mode, but you can reproduce by starting daemon in multi-terminals.

BEST PRACTICE:

  1. Please make sure dlt-daemon up and run, even daemonized mode or normal mode.

  2. Make sure only 1 available port (port not in use) for 1 dlt-daemon, you can start multi dlt-daemon by using different ports:

drmint@Old-Server:~/work/stackOF/example/build$ ps -elf | grep dlt
1 S drmint     15417     931  0  80   0 -   850 do_sys 23:53 ?        00:00:00 dlt-daemon -d
0 S drmint     15428   15341  0  80   0 -  2976 pipe_r 23:55 pts/1    00:00:00 grep --color=auto dlt
drmint@Old-Server:~/work/stackOF/example/build$ dlt-daemon -p 3491
[ 1690.784982]~DLT~15432~NOTICE   ~Starting DLT Daemon; DLT Package Version: 2.18.10 STABLE, Package Revision: v2.18.10_14_g7a55368, build on Jan  8 2024 23:43:16
-SYSTEMD -SYSTEMD_WATCHDOG -TEST -SHM

[ 1690.785223]~DLT~15432~INFO     ~FIFO size: 65536
[ 1690.785278]~DLT~15432~WARNING  ~Unable to set send timeout Socket operation on non-socket.
[ 1690.785295]~DLT~15432~INFO     ~Activate connection type: 5
[ 1690.785338]~DLT~15432~INFO     ~dlt_daemon_socket_open: Socket created
[ 1690.785371]~DLT~15432~INFO     ~dlt_daemon_socket_open: Listening on ip 0.0.0.0 and port: 3491
[ 1690.785391]~DLT~15432~INFO     ~dlt_daemon_socket_open: Socket send queue size: 16384
[ 1690.785448]~DLT~15432~INFO     ~Activate connection type: 1
[ 1690.785574]~DLT~15432~INFO     ~Activate connection type: 9
[ 1690.785612]~DLT~15432~INFO     ~Cannot open configuration file: /tmp/dlt-runtime.cfg
[ 1690.785630]~DLT~15432~INFO     ~Ringbuffer configuration: 500000/10000000/500000
[ 1690.786592]~DLT~15432~NOTICE   ~Failed to open ECU Software version file.
[ 1690.786669]~DLT~15432~WARNING  ~Unable to set send timeout Socket operation on non-socket.
[ 1690.786687]~DLT~15432~INFO     ~Activate connection type: 6
[ 1690.786705]~DLT~15432~INFO     ~Switched to buffer state for socket connections.
[ 1690.786742]~DLT~15432~WARNING  ~dlt_daemon_applications_load: cannot open file /tmp/dlt-runtime-application.cfg: No such file or directory
  1. dlt_clients (dlt-receive, dlt-viewer, etc) are in fact not necessary to be up and run whenever dlt_users doing the logging process. dlt-daemon has it own client-ringbuffer that can be configured via dlt.conf (default: /usr/lib/etc/dlt.conf), unless this buffer is full, logs will be stored there, and when there is a client done established TCP/IP or Serial connection with dlt-daemon, logs will be fetched.