-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[K32W] Improve debugging + CPU speed #7717
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,60 +21,54 @@ | |
static bool isLogInitialized; | ||
extern uint8_t gOtLogUartInstance; | ||
extern "C" void K32WWriteBlocking(const uint8_t * aBuf, uint32_t len); | ||
extern "C" uint32_t otPlatAlarmMilliGetNow(void); | ||
|
||
namespace chip { | ||
namespace Logging { | ||
namespace Platform { | ||
|
||
void GetMessageString(char * buf, uint8_t chipCategory, uint8_t otLevelLog) | ||
void GetMessageString(char * buf, uint8_t bufLen, const char * module, uint8_t category) | ||
{ | ||
if (chipCategory != kLogCategory_None) | ||
int writtenLen = 0; | ||
const char * categoryString; | ||
|
||
writtenLen = snprintf(buf, bufLen, "[%lu]", otPlatAlarmMilliGetNow()); | ||
assert((writtenLen > 0) && (writtenLen < bufLen)); | ||
bufLen -= writtenLen; | ||
|
||
if (category != kLogCategory_None) | ||
{ | ||
switch (chipCategory) | ||
switch (category) | ||
{ | ||
case kLogCategory_Error: | ||
memcpy(buf, "[Error]", 7); | ||
categoryString = "E"; | ||
break; | ||
case kLogCategory_Progress: | ||
default: | ||
memcpy(buf, "[Progress]", 10); | ||
categoryString = "P"; | ||
break; | ||
case kLogCategory_Detail: | ||
memcpy(buf, "[Debug]", 7); | ||
break; | ||
} | ||
} | ||
|
||
if (otLevelLog != OT_LOG_LEVEL_NONE) | ||
{ | ||
switch (otLevelLog) | ||
{ | ||
case OT_LOG_LEVEL_CRIT: | ||
memcpy(buf, "[Error]", 7); | ||
categoryString = "D"; | ||
break; | ||
case OT_LOG_LEVEL_WARN: | ||
memcpy(buf, "[Warn]", 6); | ||
break; | ||
case OT_LOG_LEVEL_NOTE: | ||
case OT_LOG_LEVEL_INFO: | ||
default: | ||
memcpy(buf, "[Info]", 6); | ||
break; | ||
case OT_LOG_LEVEL_DEBG: | ||
memcpy(buf, "[Debug]", 7); | ||
break; | ||
categoryString = "U"; | ||
} | ||
|
||
writtenLen = snprintf(buf + writtenLen, bufLen, "[%s]", categoryString); | ||
assert((writtenLen > 0) && (writtenLen < bufLen)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, what guaratees the assert holds? I don't see anything. |
||
bufLen -= writtenLen; | ||
} | ||
|
||
writtenLen = snprintf(buf + writtenLen, bufLen, "[%s]", module); | ||
assert((writtenLen > 0) && (writtenLen < bufLen)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
} | ||
|
||
} // namespace Platform | ||
} // namespace Logging | ||
} // namespace chip | ||
|
||
void FillPrefix(char * buf, uint8_t bufLen, uint8_t chipCategory, uint8_t otLevelLog) | ||
void FillPrefix(char * buf, uint8_t bufLen, const char * module, uint8_t category) | ||
{ | ||
/* add the error string */ | ||
chip::Logging::Platform::GetMessageString(buf, chipCategory, otLevelLog); | ||
chip::Logging::Platform::GetMessageString(buf, bufLen, module, category); | ||
} | ||
|
||
namespace chip { | ||
|
@@ -91,7 +85,7 @@ void __attribute__((weak)) OnLogOutput(void) {} | |
} // namespace DeviceLayer | ||
} // namespace chip | ||
|
||
void GenericLog(const char * format, va_list arg) | ||
void GenericLog(const char * format, va_list arg, const char * module, uint8_t category) | ||
{ | ||
|
||
#if K32W_LOG_ENABLED | ||
|
@@ -106,9 +100,8 @@ void GenericLog(const char * format, va_list arg) | |
otPlatUartEnable(); | ||
} | ||
|
||
/* Prefix is composed of [Debug String][MOdule Name String] */ | ||
FillPrefix(formattedMsg, CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, chip::Logging::kLogCategory_None, | ||
chip::Logging::kLogCategory_Detail); | ||
/* Prefix is composed of [Time Reference][Debug String][Module Name String] */ | ||
FillPrefix(formattedMsg, CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE - 1, module, category); | ||
prefixLen = strlen(formattedMsg); | ||
|
||
// Append the log message. | ||
|
@@ -137,7 +130,7 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) | |
(void) category; | ||
|
||
#if K32W_LOG_ENABLED | ||
GenericLog(msg, v); | ||
GenericLog(msg, v, module, category); | ||
// Let the application know that a log message has been emitted. | ||
DeviceLayer::OnLogOutput(); | ||
|
||
|
@@ -157,9 +150,10 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) | |
extern "C" void LwIPLog(const char * msg, ...) | ||
{ | ||
va_list v; | ||
const char * module = "LWIP"; | ||
|
||
va_start(v, msg); | ||
GenericLog(msg, v); | ||
GenericLog(msg, v, module, chip::Logging::kLogCategory_None); | ||
va_end(v); | ||
} | ||
|
||
|
@@ -171,12 +165,13 @@ extern "C" void LwIPLog(const char * msg, ...) | |
extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char * aFormat, ...) | ||
{ | ||
va_list v; | ||
const char * module = "OT"; | ||
|
||
(void) aLogLevel; | ||
(void) aLogRegion; | ||
|
||
va_start(v, aFormat); | ||
GenericLog(aFormat, v); | ||
GenericLog(aFormat, v, module, chip::Logging::kLogCategory_None); | ||
va_end(v); | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this assert valid? What guarantees that
writtenLen >= bufLen
can't happen here?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.
We can calculate the minimum size and document this as a precondition?