From b8dc3b162832602c976629291f26d8a2374d6280 Mon Sep 17 00:00:00 2001 From: Hangyu Kuang Date: Mon, 29 Apr 2019 18:12:16 -0700 Subject: [ECOService] Add debugString functionality to ECOData. The ECOData could now be dumped to a std::string. Sample output: processSessionStats ECOData(type = Stats) = { int32_t encoder-target-bitrate-bps = 22000000, int32_t encoder-level = 65536, float encoder-framerate-fps = 30.000000, int32_t encoder-profile = 8, int32_t encoder-kfi-frames = 30, int32_t encoder-type = 1, string stats-type = stats-type-session} Bug: 117877984 Test: Unit test. Change-Id: Ia6e018f2b46b64d4f8a1e00b1c4e41d123061ddb --- media/eco/ECOData.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ media/eco/ECOSession.cpp | 3 ++ media/eco/include/eco/ECOData.h | 3 ++ 3 files changed, 78 insertions(+) (limited to 'media/eco') diff --git a/media/eco/ECOData.cpp b/media/eco/ECOData.cpp index 1c6048a..189e609 100644 --- a/media/eco/ECOData.cpp +++ b/media/eco/ECOData.cpp @@ -20,6 +20,7 @@ #include "eco/ECOData.h" #include +#include #include #include @@ -344,6 +345,77 @@ ECOData::ECODataKeyValuePair ECODataKeyValueIterator::next() const { return ECOData::ECODataKeyValuePair(mIterator->first, mIterator->second); } +std::string ECOData::debugString() const { + std::string s = "ECOData(type = "; + + std::string tmp; + switch (mDataType) { + case DATA_TYPE_UNKNOWN: + tmp = "Unknown"; + break; + case DATA_TYPE_STATS: + tmp = "Stats"; + break; + case DATA_TYPE_INFO: + tmp = "Info"; + break; + case DATA_TYPE_STATS_PROVIDER_CONFIG: + tmp = "Stats provider config"; + break; + case DATA_TYPE_INFO_LISTENER_CONFIG: + tmp = "Info listener config"; + break; + default: + break; + } + s.append(tmp); + s.append(") = {\n "); + + // Writes out the key-value pairs one by one. + for (const auto& it : mKeyValueStore) { + const size_t SIZE = 100; + char keyValue[SIZE]; + const ECODataValueType& value = it.second; + switch (static_cast(value.index())) { + case kTypeInt32: + snprintf(keyValue, SIZE, "int32_t %s = %d, ", it.first.c_str(), + std::get(it.second)); + break; + case kTypeInt64: + snprintf(keyValue, SIZE, "int64_t %s = %" PRId64 ", ", it.first.c_str(), + std::get(it.second)); + break; + case kTypeSize: + snprintf(keyValue, SIZE, "size_t %s = %zu, ", it.first.c_str(), + std::get(it.second)); + break; + case kTypeFloat: + snprintf(keyValue, SIZE, "float %s = %f, ", it.first.c_str(), + std::get(it.second)); + break; + case kTypeDouble: + snprintf(keyValue, SIZE, "double %s = %f, ", it.first.c_str(), + std::get(it.second)); + break; + case kTypeString: + snprintf(keyValue, SIZE, "string %s = %s, ", it.first.c_str(), + std::get(it.second).c_str()); + break; + case kTypeInt8: + snprintf(keyValue, SIZE, "int8_t %s = %d, ", it.first.c_str(), + std::get(it.second)); + break; + default: + break; + } + s.append(keyValue); + } + + s.append("\n }"); + + return s; +} + } // namespace eco } // namespace media } // namespace android diff --git a/media/eco/ECOSession.cpp b/media/eco/ECOSession.cpp index 319bac5..eefc3d6 100644 --- a/media/eco/ECOSession.cpp +++ b/media/eco/ECOSession.cpp @@ -114,6 +114,8 @@ void ECOSession::run() { } bool ECOSession::processStats(const ECOData& stats) { + ECOLOGV("%s: receive stats: %s", __FUNCTION__, stats.debugString().c_str()); + if (stats.getDataType() != ECOData::DATA_TYPE_STATS) { ECOLOGE("Invalid stats. ECOData with type: %s", stats.getDataTypeString().c_str()); return false; @@ -191,6 +193,7 @@ bool ECOSession::processSessionStats(const ECOData& stats) { } if (mListener != nullptr) { + ECOLOGV("%s: publish info: %s", __FUNCTION__, info.debugString().c_str()); mListener->onNewInfo(info); } diff --git a/media/eco/include/eco/ECOData.h b/media/eco/include/eco/ECOData.h index 9848110..cb42982 100644 --- a/media/eco/include/eco/ECOData.h +++ b/media/eco/include/eco/ECOData.h @@ -158,6 +158,9 @@ public: friend bool copyKeyValue(const ECOData& src, ECOData* dst); + // Dump the ECOData as a string. + std::string debugString() const; + protected: // ValueType. This must match the index in ECODataValueType. enum ValueType { -- cgit v1.2.3