-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trace Logger Feature Review and Merge #2953
base: devel
Are you sure you want to change the base?
Conversation
TraceBuffer::~TraceBuffer() { | ||
} | ||
|
||
TraceBuffer::TraceBuffer(const TraceBuffer& other) : Fw::SerializeBufferBase() { |
Check warning
Code scanning / CppCheck
Member variable 'TraceBuffer::m_bufferData' is not assigned in the copy constructor. Should it be copied? Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
return false; | ||
} | ||
|
||
bool ArrayProc::delete_element(U32 element) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
// Component construction and destruction | ||
// ---------------------------------------------------------------------- | ||
|
||
TraceFileLogger::TraceFileLogger(const char* const compName) : |
Check notice
Code scanning / CodeQL
Long function without assertion Note
TraceFileLoggerComponentBase::init(queueDepth,instance); | ||
} | ||
|
||
void TraceFileLogger::set_log_file(const char* fileName, const U32 maxSize) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
|
||
// The filter method selects which trace types to be logged and which to ignore. | ||
// The bit mask is based on the enum list for trace type in TraceCfg.fpp | ||
Fw::CmdResponse TraceFileLogger::filterTraceType(U16 traceType_bitmask, bool enable){ |
Check notice
Code scanning / CodeQL
Long function without assertion Note
|
||
} | ||
|
||
void TraceFileLogger::write_log_file(U8* data, U32 size) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
} | ||
} | ||
|
||
Fw::CmdResponse TraceFileLogger::process_traceId_storage(U32 traceId,bool enable) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
// Handler implementations for user-defined typed input ports | ||
// ---------------------------------------------------------------------- | ||
|
||
void TraceFileLogger::TraceBufferLogger_handler(FwIndexType portNum, |
Check notice
Code scanning / CodeQL
Long function without assertion Note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes...
Fw/Com/ComPacket.hpp
Outdated
@@ -26,6 +26,7 @@ namespace Fw { | |||
FW_PACKET_PACKETIZED_TLM, // !< Packetized telemetry packet type | |||
FW_PACKET_DP, //!< Data product packet | |||
FW_PACKET_IDLE, // !< Idle packet | |||
FW_PACKET_TRACE, // !< Trace packet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a new packet type. Where is it used? The traces would come down as a data product.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was part of initial implementation . Removed it.
//FW_ASSERT(text != nullptr); | ||
FW_ASSERT(this->getBuffLength() < FW_TRACE_BUFFER_MAX_SIZE); | ||
|
||
std::string str_format(reinterpret_cast<const char*>(this->m_bufferData),this->getBuffLength()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this being used? It looks like there is commented out code that we shouldn't deliver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was initially writing it as a string output to file to be able to read it. I've removed it since. I thought it would be nice to have for debugging purposes in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed commented out code
Fw/Trace/TraceEntity.hpp
Outdated
* TraceEntity.hpp | ||
* | ||
* Author: sreddy | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put in more comments describing what this class is for. Or, is it misspelled "TraceEntry"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's way better than TraceEntity. I'll change it.
Fw/Trace/docs/sdd.md
Outdated
- Event ID : A unique identifier recording a “Trace Event” | ||
- Time Tag : Captures a high precision timestamp | ||
- Client Data : A small sample of user arguments recorded into trace buffer | ||
3. Trace shall create trace points and log events in software automatically for thread switching(?) and ...TBD, ask Tim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) Tim says, and port calls in and out, and message queue and dequeue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol thanks Tim :)
|
||
//Only log trace types that are enabled by either config or user | ||
if(!(this->m_traceFilter & bit_mask)) { | ||
//TODO: Should we generate an event here, letting user know that this specific filter is disabled? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it would spam events.
//Make a call to reset | ||
Fw::SerializeBufferBase& buf_ref = m_file_buffer.getSerializeRepr(); | ||
buf_ref.resetSer(); | ||
(void)buf_ref.serialize(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these should never fail, you should assert OK.
(void)buf_ref.serialize(timeTag); | ||
if(FW_TRACE_RECORD_MINIMAL == false) { | ||
(void)buf_ref.serialize(args); | ||
traceSize = m_file_buffer.getSize(); //Record max size of each trace record for circular file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not understanding this - why wouldn't it be getBuffLength()
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if it is minimal, it is already fixed size and you can store more records...unless you think it would cause issues with ground decoding?
// ensure when the file is overwritten, we preserve older records | ||
this->write_log_file(m_file_buffer.getData(),traceSize); | ||
// If we choose not to use circular file write then use below instead. | ||
//this->write_log_file(m_file_buffer.getData(),buf_ref.getBuffLength()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this; we can add it later if we want to do it.
} | ||
|
||
void TraceFileLogger ::DumpTraceDp_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { | ||
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are writing a wrapping file, we don't need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that, it was part of the initial implementation, and I wasn't sure if we could configure the same file for both in-memory and file logger or if those two should be independent, given that there could be a redundancy.
TraceEntry::~TraceEntry() { | ||
} | ||
|
||
SerializeStatus TraceEntry::serialize(SerializeBufferBase& buffer) const { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
|
||
} | ||
|
||
SerializeStatus TraceEntry::deserialize(SerializeBufferBase& buffer) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
} | ||
} | ||
|
||
bool ArrayProc::search_array(U32 element, U8 *index) { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
MAX_TRACE_TYPES = 9 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirm trace types 0 - 3 exists, do a compile time assert otherwise. Do this in Fw/
|
||
namespace Fw { | ||
|
||
class TraceEntry : public ComPacket { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ComPacket , add serializable base class here instead
@@ -0,0 +1,41 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Trace Entry entirely. Not used anywhere
#ifdef NAME_MAX | ||
#define FILE_NAME_MAX NAME_MAX | ||
#else | ||
#define FILE_NAME_MAX 255 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete this and use the macro in Config/FpConfig.h instead for file path and fine name
// Trace ID filter array size | ||
#ifndef FILTER_TRACE_ID_SIZE | ||
#define FILTER_TRACE_ID_SIZE 10 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in Config/TraceFileLoggerCfg.hpp
static const FwSizeType FW_TRACE_MAX_SER_SIZE = (FW_TRACE_BUFFER_MAX_SIZE + sizeof(FwTraceIdType) + Fw::Time::SERIALIZED_SIZE); | ||
|
||
//Mask bit for filtering on trace types | ||
static const U16 FILTER_BIT = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it to *.cpp file and make it static const expr
//! | ||
//! \param queueDepth the depth of the message queue for the component | ||
//! \param instance: instance identifier. Default: 0. | ||
void init(FwSizeType queueDepth, FwEnumStoreType instance = 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this as its defined in the base class
//! \param maxSize The max size of the file | ||
//! | ||
//! \return true if creating the file was successful, false otherwise | ||
void set_log_file(const char* fileName, const U32 maxSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in private section
|
||
FW_ASSERT(fileName != nullptr); | ||
|
||
if(this->m_enable_trace == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On initialization, make sure the filename and size are stored and file is opened. When enable/disable command is sent, make sure the file writes continuously, on disable flush the file.
m_maxFileSize(0), | ||
m_byteCount(0), | ||
m_log_init(false), | ||
m_traceFilter(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Make an array proc constructor to pass the array reference and initialize the reference to the array here.
//! \param array_ptr pointer to the array to be used | ||
//! \param array_size Max array index | ||
//! | ||
void set_array(U32 *array_ptr, U8 array_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it and pass it as part of constructor as a reference
//! \param arrayIndex returns the index where (if) the array element exists | ||
//! | ||
//! \return true if the element is found in the array, false otherwise | ||
bool search_array(U32 element, U8 *index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FwSizeType instead of U8
Change Description
This PR is to merge the initial Trace logger into F-Prime.
Rationale
To add trace logging capabilities to capture a snapshot in time that will help with debugging software execution
Testing/Review Recommendations
Added UTs to test trace logging and filtering features along with commands.
Future Work
This is just a beginning of implementation of trace feature, the future work would include logging in memory (instead of a file), implementing platform specific logging feature (vxWorks for example) and being able to dump data products.