diff options
author | Hangyu Kuang <hkuang@google.com> | 2019-04-29 18:12:16 -0700 |
---|---|---|
committer | Hangyu Kuang <hkuang@google.com> | 2019-05-01 13:27:35 -0700 |
commit | b8dc3b162832602c976629291f26d8a2374d6280 (patch) | |
tree | d96d046ef6a235b713eb14b656ca87be87471444 /media/eco | |
parent | 546bfe07fce6fa9712edb2fbfa6a983cd34021b1 (diff) | |
download | av-b8dc3b162832602c976629291f26d8a2374d6280.tar.gz |
[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
Diffstat (limited to 'media/eco')
-rw-r--r-- | media/eco/ECOData.cpp | 72 | ||||
-rw-r--r-- | media/eco/ECOSession.cpp | 3 | ||||
-rw-r--r-- | media/eco/include/eco/ECOData.h | 3 |
3 files changed, 78 insertions, 0 deletions
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 <binder/Parcel.h> +#include <inttypes.h> #include <utils/Errors.h> #include <utils/Log.h> @@ -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<ValueType>(value.index())) { + case kTypeInt32: + snprintf(keyValue, SIZE, "int32_t %s = %d, ", it.first.c_str(), + std::get<int32_t>(it.second)); + break; + case kTypeInt64: + snprintf(keyValue, SIZE, "int64_t %s = %" PRId64 ", ", it.first.c_str(), + std::get<int64_t>(it.second)); + break; + case kTypeSize: + snprintf(keyValue, SIZE, "size_t %s = %zu, ", it.first.c_str(), + std::get<size_t>(it.second)); + break; + case kTypeFloat: + snprintf(keyValue, SIZE, "float %s = %f, ", it.first.c_str(), + std::get<float>(it.second)); + break; + case kTypeDouble: + snprintf(keyValue, SIZE, "double %s = %f, ", it.first.c_str(), + std::get<double>(it.second)); + break; + case kTypeString: + snprintf(keyValue, SIZE, "string %s = %s, ", it.first.c_str(), + std::get<std::string>(it.second).c_str()); + break; + case kTypeInt8: + snprintf(keyValue, SIZE, "int8_t %s = %d, ", it.first.c_str(), + std::get<int8_t>(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 { |