From 39a03248a3fc2168332e8bd9b663935f5282243d Mon Sep 17 00:00:00 2001 From: Fredrik Svedberg Date: Thu, 30 Jun 2022 10:57:57 +0200 Subject: Log ofm data base64 encoded Added base64 encoded printing of ofm data to speed up logging of large ofms. Change-Id: Ibebd0a3557396eb68d69789f2c016161e085e64a --- .../inference_process/src/inference_process.cpp | 43 +++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/applications/inference_process/src/inference_process.cpp b/applications/inference_process/src/inference_process.cpp index e96d601..0c47d1e 100644 --- a/applications/inference_process/src/inference_process.cpp +++ b/applications/inference_process/src/inference_process.cpp @@ -41,6 +41,33 @@ using namespace std; +namespace { +const char *BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +void printBase64(const uint8_t *data, size_t len) { + size_t count = len / 3; + size_t remainder = len % 3; + char buf[] = "===="; + while (count--) { + buf[0] = BASE64[data[0] >> 2]; + buf[1] = BASE64[(data[0] & 3) << 4 | data[1] >> 4]; + buf[2] = BASE64[(data[1] & 0xf) << 2 | data[2] >> 6]; + buf[3] = BASE64[data[2] & 0x3f]; + LOG("%s", buf); + data += 3; + } + if (remainder) { + uint8_t b2 = remainder > 1 ? data[1] : 0; + buf[0] = BASE64[data[0] >> 2]; + buf[1] = BASE64[(data[0] & 3) << 4 | b2 >> 4]; + buf[2] = remainder > 1 ? BASE64[(b2 & 0xf) << 2] : '='; + buf[3] = '='; + LOG("%s", buf); + } +} + +} // namespace + namespace InferenceProcess { DataPtr::DataPtr(void *_data, size_t _size) : data(_data), size(_size) {} @@ -338,20 +365,8 @@ void InferenceProcess::printOutputTensor(TfLiteTensor *output, size_t bytesToPri if (numBytesToPrint) { LOG("\"crc32\": \"%08" PRIx32 "\",\n", crc32); LOG("\"data\":\""); - - for (int i = 0; i < numBytesToPrint - 1; ++i) { - /* - * Workaround an issue when compiling with GCC where by - * printing only a '\n' the produced global output is wrong. - */ - if (i % 15 == 0 && i != 0) { - LOG("0x%02x,\n", output->data.uint8[i]); - } else { - LOG("0x%02x,", output->data.uint8[i]); - } - } - - LOG("0x%02x\"\n", output->data.uint8[numBytesToPrint - 1]); + printBase64(output->data.uint8, numBytesToPrint); + LOG("\"\n"); } else { LOG("\"crc32\": \"%08" PRIx32 "\"\n", crc32); } -- cgit v1.2.1