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 0;
}
  • API
    Two types of DLT user interfaces are provided to ap

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值