summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>2020-04-17 15:37:52 +0700
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2020-07-06 10:04:07 +0900
commit3d33c38601e2cedd3891c65c31993fd28d8e95bc (patch)
treeb5d0b0d0e28cbf9d91854d7e8a4a151229c93a26
parentc2f5a1935a61c11f1b4a43e88417a3baaa1e6dad (diff)
downloadDLT-daemon-3d33c38601e2cedd3891c65c31993fd28d8e95bc.tar.gz
Improve performance of DLT file parsing
Introduce new API to support quick parsing a DLT file. Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
-rw-r--r--include/dlt/dlt_common.h14
-rw-r--r--src/shared/dlt_common.c69
2 files changed, 83 insertions, 0 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index 026cf75..be033db 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -210,6 +210,9 @@ enum {
# define DLT_SIZE_WSID (sizeof(uint32_t))
# define DLT_SIZE_WTMS (sizeof(uint32_t))
+/* Size of buffer for text output */
+#define DLT_CONVERT_TEXTBUFSIZE 10024
+
/**
* Definitions for GET_LOG_INFO
*/
@@ -1042,6 +1045,17 @@ DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose
*/
DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose);
/**
+ * This function reads DLT file and parse DLT message one by one.
+ * Each message will be written into new file.
+ * If a filter is set, the filter list is used.
+ * @param file pointer to structure of organizing access to DLT file
+ * @param filename file to contain parsed DLT messages.
+ * @param type 1 = payload as hex, 2 = payload as ASCII.
+ * @param verbose if set to true verbose information is printed out.
+ * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
+ */
+DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename, int type, int verbose);
+/**
* Find next message in the DLT file and parse them.
* This function finds the next message in the DLT file.
* If a filter is set, the filter list is used.
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index c462ed0..5697163 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -3985,3 +3985,72 @@ int dlt_mkdir_recursive(const char *dir)
return ret;
}
#endif
+
+DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename,
+ int type, int verbose)
+{
+ PRINT_FUNCTION_VERBOSE(verbose);
+ int ret = DLT_RETURN_OK;
+ char text[DLT_CONVERT_TEXTBUFSIZE] = { 0 };
+
+ if (file == NULL || filename == NULL)
+ return DLT_RETURN_WRONG_PARAMETER;
+
+ FILE *output = fopen(filename, "w+");
+ if (output == NULL) {
+ dlt_vlog(LOG_ERR, "Cannot open output file %s for parsing\n", filename);
+ return DLT_RETURN_ERROR;
+ }
+
+ while(ret >= DLT_RETURN_OK && file->file_position < file->file_length) {
+ /* get file position at start of DLT message */
+ if (verbose) {
+ dlt_vlog(LOG_DEBUG, "Position in file: %ld\n", file->file_position);
+ }
+
+ /* read all header and payload */
+ ret = dlt_file_read_header(file, verbose);
+ if (ret < DLT_RETURN_OK)
+ break;
+
+ ret = dlt_file_read_header_extended(file, verbose);
+ if (ret < DLT_RETURN_OK)
+ break;
+
+ ret = dlt_file_read_data(file, verbose);
+ if (ret < DLT_RETURN_OK)
+ break;
+
+ if (file->filter) {
+ /* check the filters if message is used */
+ ret = dlt_message_filter_check(&(file->msg), file->filter, verbose);
+ if (ret != DLT_RETURN_TRUE)
+ continue;
+ }
+
+ ret = dlt_message_header(&(file->msg), text,
+ DLT_CONVERT_TEXTBUFSIZE, verbose);
+ if (ret < DLT_RETURN_OK)
+ break;
+
+ fprintf(output, "%s", text);
+
+ ret = dlt_message_payload(&(file->msg), text,
+ DLT_CONVERT_TEXTBUFSIZE, type, verbose);
+ if (ret < DLT_RETURN_OK)
+ break;
+
+ fprintf(output, "[%s]\n", text);
+
+ /* store index pointer to message position in DLT file */
+ file->counter++;
+ file->position = file->counter_total - 1;
+ /* increase total message counter */
+ file->counter_total++;
+ /* store position to next message */
+ file->file_position = ftell(file->handle);
+ } // while()
+
+ fclose(output);
+ return ret;
+}