Skip to content

Commit

Permalink
[ember] Optimize out ember strings in release builds (#18806)
Browse files Browse the repository at this point in the history
* [ember] Optimize out ember strings in release builds

Ember strings are still included in the binary even if the
progress logging is disabled. The change saves around 14kB
of flash in the case of nRF connect examples.

Signed-off-by: Damian Krolik <[email protected]>

* Fix build
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Jun 28, 2022
1 parent 81ea8b6 commit 9604833
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,15 @@ bool IsFeatureSupported(EndpointId endpoint, EmberAfStatus (*getFn1)(chip::Endpo
return false;
}

void emberAfPumpConfigurationAndControlClusterServerInitCallback(EndpointId endpoint)
template <typename T1, typename T2>
const char * FeatureSupportedDebugString(EndpointId endpoint, EmberAfStatus (*getFn1)(chip::EndpointId endpointId, T1 & value),
EmberAfStatus (*getFn2)(chip::EndpointId endpointId, T2 & value))
{
bool constPressureSupported = false;
bool constPropPressureSupported = false;
bool constFlowSupported = false;
bool constTemperatureSupported = false;
bool constSpeedSupported = false;
return IsFeatureSupported(endpoint, getFn1, getFn2) ? "Supported" : "Not Supported";
}

void emberAfPumpConfigurationAndControlClusterServerInitCallback(EndpointId endpoint)
{
emberAfDebugPrintln("Initialize PCC Server Cluster [EP:%d]", endpoint);

// Determine the internal feature set of the pump, depending on the pump
Expand All @@ -283,16 +284,17 @@ void emberAfPumpConfigurationAndControlClusterServerInitCallback(EndpointId endp
// has finished its init process, it might setup these attributevalues
// to something NonNull, and then we must re-calcualte the feature set.

constPressureSupported = IsFeatureSupported(endpoint, Attributes::MinConstPressure::Get, Attributes::MaxConstPressure::Get);
emberAfDebugPrintln("Constant Pressure %s", constPressureSupported ? "Supported" : "Not Supported");
constPropPressureSupported = IsFeatureSupported(endpoint, Attributes::MinCompPressure::Get, Attributes::MaxCompPressure::Get);
emberAfDebugPrintln("Constant Proportional Pressure %s", constPropPressureSupported ? "Supported" : "Not Supported");
constFlowSupported = IsFeatureSupported(endpoint, Attributes::MinConstFlow::Get, Attributes::MaxConstFlow::Get);
emberAfDebugPrintln("Constant Flow %s", constFlowSupported ? "Supported" : "Not Supported");
constTemperatureSupported = IsFeatureSupported(endpoint, Attributes::MinConstTemp::Get, Attributes::MaxConstTemp::Get);
emberAfDebugPrintln("Constant Temperature %s", constTemperatureSupported ? "Supported" : "Not Supported");
constSpeedSupported = IsFeatureSupported(endpoint, Attributes::MinConstSpeed::Get, Attributes::MaxConstSpeed::Get);
emberAfDebugPrintln("Constant Speed %s", constSpeedSupported ? "Supported" : "Not Supported");
emberAfDebugPrintln(
"Constant Pressure %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstPressure::Get, Attributes::MaxConstPressure::Get));
emberAfDebugPrintln("Constant Proportional Pressure %s",
FeatureSupportedDebugString(endpoint, Attributes::MinCompPressure::Get, Attributes::MaxCompPressure::Get));
emberAfDebugPrintln("Constant Flow %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstFlow::Get, Attributes::MaxConstFlow::Get));
emberAfDebugPrintln("Constant Temperature %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstTemp::Get, Attributes::MaxConstTemp::Get));
emberAfDebugPrintln("Constant Speed %s",
FeatureSupportedDebugString(endpoint, Attributes::MinConstSpeed::Get, Attributes::MaxConstSpeed::Get));
}

chip::Protocols::InteractionModel::Status MatterPumpConfigurationAndControlClusterServerPreAttributeChangedCallback(
Expand Down
8 changes: 4 additions & 4 deletions src/app/util/ember-print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,29 @@ bool emberAfPrintReceivedMessages = true;

using namespace chip::Logging;

#if CHIP_PROGRESS_LOGGING

void emberAfPrint(int category, const char * format, ...)
{
#if _CHIP_USE_LOGGING
if (format != nullptr)
{
va_list args;
va_start(args, format);
chip::Logging::LogV(chip::Logging::kLogModule_Zcl, chip::Logging::kLogCategory_Progress, format, args);
va_end(args);
}
#endif
}

#if !CHIP_PW_TOKENIZER_LOGGING
void emberAfPrintln(int category, const char * format, ...)
{
#if _CHIP_USE_LOGGING
if (format != nullptr)
{
va_list args;
va_start(args, format);
chip::Logging::LogV(chip::Logging::kLogModule_Zcl, chip::Logging::kLogCategory_Progress, format, args);
va_end(args);
}
#endif
}
#endif

Expand Down Expand Up @@ -101,3 +99,5 @@ void emberAfPrintString(int category, const uint8_t * string)
{
emberAfPrint(category, "%.*s", emberAfStringLength(string), string + 1);
}

#endif // CHIP_PROGRESS_LOGGING
24 changes: 19 additions & 5 deletions src/app/util/ember-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@
* @brief Prints a log message
* @param category - Currently ignored as zcl categories do not map to chip categories. Defaults to kLogCategory_Progress
* @param format - Format string to print
* */
*/
#if CHIP_PROGRESS_LOGGING
void emberAfPrint(int category, const char * format, ...) ENFORCE_FORMAT(2, 3);
#else
#define emberAfPrint(...) ((void) 0)
#endif

/**
* @brief Prints a log followed by new line line
* @param category - Currently ignored as zcl categories do not map to chip categories. Defaults to kLogCategory_Progress
* @param format - Format string to print
* */
*/
#if CHIP_PW_TOKENIZER_LOGGING
#define emberAfPrintln(MOD, MSG, ...) ChipLogProgress(Zcl, MSG, __VA_ARGS__);
#else
#elif CHIP_PROGRESS_LOGGING
void emberAfPrintln(int category, const char * format, ...) ENFORCE_FORMAT(2, 3);
#else
#define emberAfPrintln(...) ((void) 0)
#endif

/**
Expand All @@ -47,12 +53,20 @@ void emberAfPrintln(int category, const char * format, ...) ENFORCE_FORMAT(2, 3)
* @param buffer - Buffer to print.
* @param length - Length of buffer
* @param withSpace - Pass in true if a space should be printed between each byte.
* */
*/
#if CHIP_PROGRESS_LOGGING
void emberAfPrintBuffer(int category, const uint8_t * buffer, uint16_t length, bool withSpace);
#else
#define emberAfPrintBuffer(...) ((void) 0)
#endif

/**
* @brief Prints a strings
* @param category - Currently ignored as zcl categories do not map to chip categories. Defaults to kLogCategory_Progress.
* @param string - Buffer to print as a string
* */
*/
#if CHIP_PROGRESS_LOGGING
void emberAfPrintString(int category, const uint8_t * string);
#else
#define emberAfPrintString(...) ((void) 0)
#endif
6 changes: 0 additions & 6 deletions src/app/util/time-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ uint32_t emberAfGetUtcFromTimeStruct(EmberAfTimeStruct * time);
*/
uint8_t emberAfGetWeekdayFromUtc(uint32_t utcTime);

/*
* @brief Prints out a human readable date form from the given ZCL data type.
*/
void emberAfPrintDate(const EmberAfDate * date);
void emberAfPrintDateln(const EmberAfDate * date);

/**
* @brief Sets current time.
* Convenience function for setting the time to a value.
Expand Down

0 comments on commit 9604833

Please sign in to comment.