Skip to content

Commit

Permalink
Make datamodel-provider inteface logging optional/configurable (proje…
Browse files Browse the repository at this point in the history
…ct-chip#36249)

* make more detailed logging optional in the codegen data model and enable it only on known large platforms

* Update src/app/common_flags.gni

Co-authored-by: Boris Zbarsky <[email protected]>

* Restyled by gn

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
4 people authored and yyzhong-g committed Dec 11, 2024
1 parent 5b36f16 commit 53fb0de
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ buildconfig_header("app_buildconfig") {
"CHIP_DEVICE_CONFIG_DYNAMIC_SERVER=${chip_build_controller_dynamic_server}",
"CHIP_CONFIG_ENABLE_BUSY_HANDLING_FOR_OPERATIONAL_SESSION_SETUP=${chip_enable_busy_handling_for_operational_session_setup}",
"CHIP_CONFIG_DATA_MODEL_CHECK_DIE_ON_FAILURE=${chip_data_model_check_die_on_failure}",
"CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING=${chip_data_model_extra_logging}",
]

if (chip_use_data_model_interface == "disabled") {
Expand Down
9 changes: 7 additions & 2 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ void WriteHandler::Close()
std::optional<bool> WriteHandler::IsListAttributePath(const ConcreteAttributePath & path)
{
#if CHIP_CONFIG_USE_DATA_MODEL_INTERFACE
VerifyOrReturnValue(mDataModelProvider != nullptr, std::nullopt,
ChipLogError(DataManagement, "Null data model while checking attribute properties."));
if (mDataModelProvider == nullptr)
{
#if CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING
ChipLogError(DataManagement, "Null data model while checking attribute properties.");
#endif
return std::nullopt;
}

auto info = mDataModelProvider->GetAttributeInfo(path);
if (!info.has_value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ std::optional<CommandId> EnumeratorCommandFinder::FindCommandId(Operation operat

if (err != CHIP_NO_ERROR)
{
#if CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING
// Report the error here since we lose actual error. This generally should NOT be possible as CommandHandlerInterface
// usually returns unimplemented or should just work for our use case (our callback never fails)
ChipLogError(DataManagement, "Enumerate error: %" CHIP_ERROR_FORMAT, err.Format());
#endif
return kInvalidCommandId;
}

Expand All @@ -155,8 +157,10 @@ std::variant<CHIP_ERROR, DataModel::ClusterInfo> LoadClusterInfo(const ConcreteC
DataVersion * versionPtr = emberAfDataVersionStorage(path);
if (versionPtr == nullptr)
{
#if CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING
ChipLogError(AppServer, "Failed to get data version for %d/" ChipLogFormatMEI, static_cast<int>(path.mEndpointId),
ChipLogValueMEI(cluster.clusterId));
#endif
return CHIP_ERROR_NOT_FOUND;
}

Expand Down Expand Up @@ -211,7 +215,7 @@ DataModel::ClusterEntry FirstServerClusterEntry(EndpointId endpointId, const Emb
return *entryValue;
}

#if CHIP_ERROR_LOGGING
#if CHIP_ERROR_LOGGING && CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING
if (CHIP_ERROR * errValue = std::get_if<CHIP_ERROR>(&entry))
{
ChipLogError(AppServer, "Failed to load cluster entry: %" CHIP_ERROR_FORMAT, errValue->Format());
Expand Down Expand Up @@ -571,7 +575,7 @@ std::optional<DataModel::ClusterInfo> CodegenDataModelProvider::GetClusterInfo(c

if (CHIP_ERROR * err = std::get_if<CHIP_ERROR>(&info))
{
#if CHIP_ERROR_LOGGING
#if CHIP_ERROR_LOGGING && CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING
ChipLogError(AppServer, "Failed to load cluster info: %" CHIP_ERROR_FORMAT, err->Format());
#else
(void) err->Format();
Expand Down
7 changes: 7 additions & 0 deletions src/app/common_flags.gni
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ declare_args() {
# If/once the chip_use_data_model_interface flag is removed or does not support
# a `check` option, this should alwo be removed
chip_data_model_check_die_on_failure = false

# This controls if more logging is supposed to be enabled into the data models.
# This is an optimization for small-flash size devices as extra logging requires
# additional flash for messages & code for formatting.
chip_data_model_extra_logging =
current_os == "linux" || current_os == "ios" || current_os == "mac" ||
current_os == "android"
}
2 changes: 2 additions & 0 deletions src/app/reporting/Read-DataModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ DataModel::ActionReturnStatus RetrieveClusterData(DataModel::Provider * dataMode
if (!status.IsOutOfSpaceEncodingResponse())
{
DataModel::ActionReturnStatus::StringStorage storage;
#if CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING
ChipLogError(DataManagement, "Failed to read attribute: %s", status.c_str(storage));
#endif
}
return status;
}
Expand Down

0 comments on commit 53fb0de

Please sign in to comment.