-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add functionality to dump ring buffer to disk file
For example: /usr/bin/dlt-logstorage-ctrl -D /tmp/ss.dlt will dump the entries in ringbuffer to file /tmp/ss.dlt
- Loading branch information
1 parent
2118762
commit e614fdd
Showing
7 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* SPDX license identifier: MPL-2.0 | ||
* | ||
* Copyright (C) 2022, Daimler TSS GmbH | ||
* | ||
* This file is part of COVESA Project DLT - Diagnostic Log and Trace. | ||
* | ||
* This Source Code Form is subject to the terms of the | ||
* Mozilla Public License (MPL), v. 2.0. | ||
* If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* For further information see https://www.covesa.global/. | ||
* | ||
* \file dlt_buffer_dump.c | ||
*/ | ||
|
||
#include "dlt_buffer_dump.h" | ||
#include "dlt-daemon_cfg.h" | ||
#include <syslog.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
DltReturnValue dlt_ringbuffer_copy(const DltBuffer *src, DltBuffer *dst) { | ||
if (src == NULL || dst == NULL) { | ||
return DLT_RETURN_WRONG_PARAMETER; | ||
} | ||
|
||
dst->size = src->size; | ||
dst->min_size = src->min_size; | ||
dst->max_size = src->max_size; | ||
dst->step_size = src->step_size; | ||
|
||
int length = dst->size + sizeof(DltBufferHead); | ||
dst->shm = malloc(length); | ||
memcpy(dst->shm, src->shm, length); | ||
dst->mem = (unsigned char *) (dst->shm + sizeof(DltBufferHead)); | ||
|
||
return DLT_RETURN_OK; | ||
} | ||
|
||
DltReturnValue dlt_buffer_dump(const DltDaemon *daemon, const DltBuffer *ring_buffer, const char *dump_file_path) { | ||
uint8_t data[DLT_DAEMON_RCVBUFSIZE] = {0}; | ||
int length; | ||
DltBuffer buffer = {0}; | ||
|
||
DltReturnValue ret = dlt_ringbuffer_copy(ring_buffer, &buffer); | ||
if (ret != DLT_RETURN_OK) { | ||
return ret; | ||
} | ||
|
||
FILE *file = fopen(dump_file_path, "w"); | ||
if (file == NULL) { | ||
dlt_vlog(LOG_ERR, "Could not open dump file:%s\n", dump_file_path); | ||
dlt_buffer_free_dynamic(&buffer); | ||
return DLT_RETURN_WRONG_PARAMETER; | ||
} | ||
|
||
DltStorageHeader storage_header = {0}; | ||
dlt_set_storageheader(&storage_header, daemon->ecuid); | ||
|
||
while ((length = dlt_buffer_copy(&buffer, data, sizeof(data))) > 0) { | ||
fwrite(&storage_header, sizeof(DltStorageHeader), 1, file); | ||
fwrite(&data, length, 1, file); | ||
dlt_buffer_remove(&buffer); | ||
} | ||
|
||
fclose(file); | ||
dlt_buffer_free_dynamic(&buffer); | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX license identifier: MPL-2.0 | ||
* | ||
* Copyright (C) 2022, Daimler TSS GmbH | ||
* | ||
* This file is part of COVESA Project DLT - Diagnostic Log and Trace. | ||
* | ||
* This Source Code Form is subject to the terms of the | ||
* Mozilla Public License (MPL), v. 2.0. | ||
* If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* For further information see https://www.covesa.global/. | ||
* | ||
* \file dlt_buffer_dump.h | ||
*/ | ||
|
||
#ifndef AUTOMOTIVE_DLT_SRC_DAEMON_DLT_BUFFER_DUMP_H_ | ||
#define AUTOMOTIVE_DLT_SRC_DAEMON_DLT_BUFFER_DUMP_H_ | ||
|
||
#include "dlt_client.h" | ||
#include "dlt_common.h" | ||
#include "dlt_daemon_common.h" | ||
|
||
/** | ||
* Copy the ring buffer from src to dst | ||
* @param src the ringbuffer source | ||
* @param dst the ringbuffer dest | ||
* @return DLT_RETURN OK if it is successful | ||
*/ | ||
DltReturnValue dlt_ringbuffer_copy(const DltBuffer *src, DltBuffer *dst); | ||
|
||
/** | ||
* dump the ringbuffer to disk | ||
* @param daemon the DltDaemon | ||
* @param ring_buffer the ringbuffer | ||
* @param dump_file_path the dump file path | ||
* @return DLT_RETURN OK if it is successful | ||
*/ | ||
DltReturnValue dlt_buffer_dump(const DltDaemon *daemon, const DltBuffer *ring_buffer, const char *dump_file_path); | ||
|
||
#endif //AUTOMOTIVE_DLT_SRC_DAEMON_DLT_BUFFER_DUMP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters