DLT(Diagnostic Log and Trace)嵌入式系统程序运行记录

  • DLT的使用有属于Application范畴与Context范畴。在使用DLT时,需要包含以下头文件:
#include <dlt/dlt.h>

同时需要link相应的dlt库文件。

  • Context范畴需要使用以下statement去申明及注册:
DLT_DECLARE_CONTEXT(BCcontext); // declare the context name.

DLT_REGISTER_CONTEXT(BCcontext,"BCCT","DLT BC Context"); // register the Context id.

DLT_IMPORT_CONTEXT(BCcontext); // import DLT Context in other source file.

DLT_UNREGISTER_CONTEXT(BCcontext);   // DLT Context un-registration
  • Application范畴需要使用以下statement去注册:
DLT_REGISTER_APP("BC","DLT BC DBUS Wrapper"); // register the Application id.
DLT_UNREGISTER_APP(); // DLT Application un-registration
//Set daemon log limit and trace status. Anything above this log level will not be printed.

DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEBUG, DLT_TRACE_STATUS_DEFAULT);
  • DLT log 有以下几种格式
DLT_LOG(BCcontext,DLT_LOG_INFO,DLT_STRING("output normal information directly.")); 
DLT_LOG(BCcontext,DLT_LOG_WARN,DLT_STRING("output warning information directly."));  
DLT_LOG(BCcontext,DLT_LOG_ERROR,DLT_STRING("output error information directly.")); 

DLT_LOG(BCcontext,DLT_LOG_INFO,DLT_STRING("RadioMsg_Signal_Coverage_Area_Handler"),                                                 
                           DLT_STRING("default type data"),DLT_UINT(default value),
                           DLT_STRING("one byte"),DLT_UINT8(char),
                           DLT_STRING("two byte"),DLT_UINT16(short),
                           DLT_STRING("four byte"),DLT_UINT32(int));
  • 上位机可以使用DLT-viewer软件通过网络SSH协议连接到目标板上去查看系统的运行情况。

DLT library

To use DLT from an application, the application has to link again the DLT library. When the DLT daemon is installed on the system , there will a shared library with the name libdlt.so which provides the interface for applications to get a connection to the DLT daemon. The library path and include path must be set in the build environment prior to building a program using the shared dlt library. By default, the include file “dlt.h” is located in a directory called “dlt/” within the standard include directory.

  • Using DLT with cmake
    To use DLT with cmake, the following lines are the important ones:
pkg_check_modules(DLT REQUIRED automotive-dlt)

to INCLUDE_DIRECTORIES, add

${DLT_INCLUDE_DIRS}

and to TARGET_LINK_LIBRARIES:

${DLT_LIBRARIES}
  • Logging instruction
    Include the dlt header file:
#include <dlt/dlt.h>
  • Create logging context (place it beneath the define section):
DLT_DECLARE_CONTEXT(myContext);
  • Register the application and the context in main:
int main(int argc, const char\* argv\[\])
{
DLT_REGISTER_APP("LOG","Test Application for Logging");

DLT_REGISTER_CONTEXT(mycontext,"TEST","Test Context for Logging");
...
}

Important note: If your application uses fork(), you may not call DLT_REGISTER_APP before fork(). And fork() should never be called after DLT_REGISTER_APP. This is because of state information and inter process communication channel to daemon would be copied to new process, but threads would be not.

  • Use one of the DLT macros or the DLT function interface:
    Here we use the macro interface of DLT
DLT_LOG(mycontext,DLT_LOG_WARN,DLT_INT(5),DLT_STRING("This is a warning"));
DLT_LOG(mycontext,DLT_LOG_INFO,DLT_INT(5),DLT_STRING("But this only information"));
  • Unregister the application and the context which are registered
DLT_UNREGISTER_CONTEXT(mycontext);
DLT_UNREGISTER_APP();
  • Logging example
    gedit dltdemo.c &
    Copy the example code below into dltdemo.c
    gcc -o dltdemo -ldlt dltdemo.c
    rolf.haimerl|./dltdemo

  • DLT - Hello world

#include <stdio.h>
#include <dlt/dlt.h>
DLT_DECLARE_CONTEXT(mycontext);
int main()
{
   int num;

   DLT_REGISTER_APP("MYAP","My Application");
   DLT_REGISTER_CONTEXT(mycontext,"MYCT", "My Context");

   printf("Hello world");

   for(num=0;num<10;num++) {
      DLT_LOG(mycontext,DLT_LOG_INFO,DLT_STRING("Hello world"),DLT_INT(num));
      sleep(1);
   }

   DLT_UNREGISTER_CONTEXT(mycontext);
   DLT_UNREGISTER_APP();
   return 
  • 2
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Log and trace是一种记录和追踪系统运行时信息的技术。在软件开发和调试过程中,logtrace可以帮助开发人员了解系统的运行状态、诊断问题和调试代码。引用\[1\]中的代码示例展示了如何使用Logger对象记录一些有用的信息。而引用\[2\]中提到了AUTOSAR Dlt模块,它主要用于接收来自不同模块的日志和跟踪信息,并通过通信总线传输这些数据,使其在ECU外部可见。Dlt模块使用Dlt协议来定义各种命令,这些命令可以用于在运行时修改Dlt模块的行为,例如设置日志级别、启用/禁用跟踪消息、获取日志信息等。通过使用Dlt模块,开发人员可以更方便地进行日志记录和跟踪系统运行时信息的工作。 #### 引用[.reference_title] - *1* [AP AUTOSAR11 —— Log and Trace](https://blog.csdn.net/usstmiracle/article/details/113743475)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [[Classic AUTOSAR学习] DLT模块(Log&Trace)](https://blog.csdn.net/u012332571/article/details/126559913)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值