mirror of
https://github.com/espressif/openthread.git
synced 2026-09-17 22:50:07 +00:00
[mac] unify and optimize MAC operation logging (#13404)
This commit consolidates the debug logging for MAC operation state transitions into a helper method `Mac::LogOperation()`.
This commit is contained in:
+29
-4
@@ -585,7 +585,7 @@ void Mac::StartOperation(Operation aOperation)
|
||||
{
|
||||
SetPending(aOperation);
|
||||
|
||||
LogDebg("Request to start operation \"%s\"", OperationToString(aOperation));
|
||||
LogOperation(kRequest, aOperation);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_STAY_AWAKE_BETWEEN_FRAGMENTS
|
||||
if (mDelayingSleep)
|
||||
@@ -662,7 +662,7 @@ void Mac::PerformNextOperation(void)
|
||||
if (mOperation != kOperationIdle)
|
||||
{
|
||||
ClearPending(mOperation);
|
||||
LogDebg("Starting operation \"%s\"", OperationToString(mOperation));
|
||||
LogOperation(kStarting, mOperation);
|
||||
mTimer.Stop(); // Stop the timer before any non-idle operation, have the operation itself be responsible to
|
||||
// start the timer (if it wants to).
|
||||
}
|
||||
@@ -708,7 +708,7 @@ exit:
|
||||
|
||||
void Mac::FinishOperation(void)
|
||||
{
|
||||
LogDebg("Finishing operation \"%s\"", OperationToString(mOperation));
|
||||
LogOperation(kFinishing, mOperation);
|
||||
mOperation = kOperationIdle;
|
||||
}
|
||||
|
||||
@@ -2324,7 +2324,7 @@ uint8_t Mac::ComputeLinkMargin(int8_t aRss) const { return ot::ComputeLinkMargin
|
||||
|
||||
// LCOV_EXCL_START
|
||||
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_DEBG)
|
||||
|
||||
const char *Mac::OperationToString(Operation aOperation)
|
||||
{
|
||||
@@ -2361,6 +2361,31 @@ const char *Mac::OperationToString(Operation aOperation)
|
||||
return kStrings[aOperation];
|
||||
}
|
||||
|
||||
const char *Mac::OperationActionToString(OperationAction aAction)
|
||||
{
|
||||
#define OperationActionMapList(_) \
|
||||
_(kRequest, "Request to start") \
|
||||
_(kStarting, "Starting") \
|
||||
_(kFinishing, "Finishing")
|
||||
|
||||
DefineEnumStringArray(OperationActionMapList);
|
||||
|
||||
return kStrings[aAction];
|
||||
}
|
||||
|
||||
void Mac::LogOperation(OperationAction aAction, Operation aOperation) const
|
||||
{
|
||||
LogDebg("%s operation \"%s\"", OperationActionToString(aAction), OperationToString(aOperation));
|
||||
}
|
||||
|
||||
#else // OT_SHOULD_LOG_AT(OT_LOG_LEVEL_DEBG)
|
||||
|
||||
void Mac::LogOperation(OperationAction, Operation) const {}
|
||||
|
||||
#endif // OT_SHOULD_LOG_AT(OT_LOG_LEVEL_DEBG)
|
||||
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
|
||||
void Mac::LogFrameRxFailure(const RxFrame *aFrame, Error aError) const
|
||||
{
|
||||
LogLevel logLevel;
|
||||
|
||||
+11
-1
@@ -753,6 +753,13 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
enum OperationAction : uint8_t // Used in `LogOperation`
|
||||
{
|
||||
kRequest,
|
||||
kStarting,
|
||||
kFinishing,
|
||||
};
|
||||
|
||||
// Callbacks from `SubMac` or `Trel::Link`
|
||||
void HandleReceivedFrame(RxFrame *aFrame, Error aError);
|
||||
void RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel);
|
||||
@@ -803,6 +810,10 @@ private:
|
||||
void LogFrameRxFailure(const RxFrame *aFrame, Error aError) const;
|
||||
void LogFrameTxFailure(const TxFrame &aFrame, Error aError, uint8_t aRetryCount, bool aWillRetx) const;
|
||||
void LogBeacon(const char *aActionText) const;
|
||||
void LogOperation(OperationAction aAction, Operation aOperation) const;
|
||||
|
||||
static const char *OperationToString(Operation aOperation);
|
||||
static const char *OperationActionToString(OperationAction aAction);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_CSL_TRANSMITTER_ENABLE
|
||||
void ProcessCsl(const RxFrame &aFrame, const Address &aSrcAddr);
|
||||
@@ -818,7 +829,6 @@ private:
|
||||
Error HandleWakeupFrame(const RxFrame &aFrame);
|
||||
void UpdateWakeupListening(void);
|
||||
#endif
|
||||
static const char *OperationToString(Operation aOperation);
|
||||
|
||||
using OperationTask = TaskletIn<Mac, &Mac::PerformNextOperation>;
|
||||
using MacTimer = TimerMilliIn<Mac, &Mac::HandleTimer>;
|
||||
|
||||
Reference in New Issue
Block a user