From b2ce65d9947849160e04e751075c7fe4b5dcd158 Mon Sep 17 00:00:00 2001 From: ManikandanC Date: Mon, 22 May 2017 10:57:21 +0530 Subject: Dynamic allocation of msg buffer It is possible to change the default buffer size for log message creation via environment variable: export DLT_LOG_MSG_BUF_LEN= Instead of using a static buffer with size of 1390 bytes, the buffer is allocated dynamically with the specified value.The max size is restricted to approx 65k. Signed-off-by: Christoph Lipka Signed-off-by: ManikandanC --- src/examples/dlt-example-user.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/examples') diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index 532402a..12d9c37 100644 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -103,6 +103,7 @@ void usage() printf(" -m mode Set log mode 0=off,1=external,2=internal,3=both\n"); printf(" -l level Set log level to , level=-1..6\n"); printf(" -t timeout Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n"); + printf(" -r size Send raw data with specified size instead of string\n"); #ifdef DLT_TEST_ENABLE printf(" -c Corrupt user header\n"); printf(" -s size Corrupt message size\n"); @@ -130,6 +131,7 @@ int main(int argc, char* argv[]) char *message = 0; int lvalue = DLT_LOG_WARN; char *tvalue = 0; + int rvalue = -1; int index; int c; @@ -142,9 +144,9 @@ int main(int argc, char* argv[]) opterr = 0; #ifdef DLT_TEST_ENABLE - while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:s:l:t:")) != -1) + while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:r:s:l:t:")) != -1) #else - while ((c = getopt (argc, argv, "vgakd:f:n:m:l:t:")) != -1) + while ((c = getopt (argc, argv, "vgakd:f:n:m:l:r:t:")) != -1) #endif /* DLT_TEST_ENABLE */ { switch (c) @@ -211,6 +213,11 @@ int main(int argc, char* argv[]) tvalue = optarg; break; } + case 'r': + { + rvalue = atoi(optarg); + break; + } case '?': { if (optopt == 'd' || optopt == 'f' || optopt == 'n'|| optopt == 'l' || optopt == 't') @@ -238,9 +245,17 @@ int main(int argc, char* argv[]) } } - for (index = optind; index < argc; index++) + if (rvalue == -1) + { + for (index = optind; index < argc; index++) + { + message = argv[index]; + } + } + else /* allocate raw buffer */ { - message = argv[index]; + message = calloc(sizeof(char), rvalue); + memset(message, 'X', rvalue-1); } if (message == 0) @@ -377,8 +392,15 @@ int main(int argc, char* argv[]) } else { - /* Verbose mode */ - DLT_LOG(mycontext,lvalue,DLT_INT(num),DLT_STRING(text)); + if (rvalue == -1) + { + /* Verbose mode */ + DLT_LOG(mycontext,lvalue,DLT_INT(num),DLT_STRING(text)); + } + else + { + DLT_LOG(mycontext,lvalue,DLT_RAW(text, rvalue)); + } } if (delay>0) -- cgit v1.2.1