From 99554bcc1ae43201045aeef2d7efba7bf7a6539e Mon Sep 17 00:00:00 2001 From: xlxiangli <xlxiangli@google.com> Date: Mon, 31 Jul 2023 12:05:40 +0000 Subject: [PATCH] Port JVET_Z0150_MEMORY_USAGE_PRINT --- source/App/EncoderApp/encmain.cpp | 36 +++++++++++++++++++++++++++++++ source/Lib/CommonLib/TypeDef.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/source/App/EncoderApp/encmain.cpp b/source/App/EncoderApp/encmain.cpp index 971aef526a..d15232cb0c 100644 --- a/source/App/EncoderApp/encmain.cpp +++ b/source/App/EncoderApp/encmain.cpp @@ -76,6 +76,33 @@ static void printMacroSettings() } } +#if JVET_Z0150_MEMORY_USAGE_PRINT +#ifdef __linux +#include <cstdlib> +#include <cstdio> +#include <cstring> + +int getProcStatusValue(const char* key) +{ + FILE* file = fopen("/proc/self/status", "r"); + int result = -1; + char line[128]; + + int len = strlen(key); + while (fgets(line, 128, file) != nullptr) + { + if (strncmp(line, key, len) == 0) + { + result = atoi(line+len); + break; + } + } + fclose(file); + return result; +} +#endif +#endif + // ==================================================================================================================== // Main function // ==================================================================================================================== @@ -325,6 +352,15 @@ int main(int argc, char* argv[]) encApp->applyNnPostFilter(); } } + +#if JVET_Z0150_MEMORY_USAGE_PRINT +#ifdef __linux + int vm = getProcStatusValue("VmPeak:"); + int rm = getProcStatusValue("VmHWM:"); + printf("\nMemory Usage: VmPeak= %d KB ( %.1f GiB ), VmHWM= %d KB ( %.1f GiB )\n", vm, (double)vm/(1024*1024), rm, (double)rm/(1024*1024)); +#endif +#endif + // ending time clock_t endClock = clock(); auto endTime = std::chrono::steady_clock::now(); diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index 9f4b0205cd..af8db417c3 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -58,6 +58,8 @@ //########### place macros to be removed in next cycle below this line ############### +#define JVET_Z0150_MEMORY_USAGE_PRINT 1 // JVET-Z0150: Print memory usage + #define JVET_AE0060_COND_SIG_INF 1 // signal nnpfc_chroma_loc_info_present_flag only when nnpfc_out_order_idc is not equal to 0 and infer nnpfc_chroma_loc_info_present_flag to be equal to 0 when not present. #define JVET_AE0057_MTT_ET 1 // JVET-AE0057: MTT split modes early termination -- GitLab