From 9d21755bba868cc7df4f0d7ccd44534bfc0fa59f Mon Sep 17 00:00:00 2001 From: gitamohr Date: Mon, 7 Nov 2022 09:48:49 -0800 Subject: [PATCH] sdfdump: Imbue sdfdump with malloc tag reporting when invoked with malloc tags enabled. (Internal change: 2254611) --- pxr/usd/bin/sdfdump/sdfdump.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pxr/usd/bin/sdfdump/sdfdump.cpp b/pxr/usd/bin/sdfdump/sdfdump.cpp index bcb262224b..9473e103b9 100644 --- a/pxr/usd/bin/sdfdump/sdfdump.cpp +++ b/pxr/usd/bin/sdfdump/sdfdump.cpp @@ -25,10 +25,12 @@ #include "pxr/base/arch/attributes.h" #include "pxr/base/arch/stackTrace.h" #include "pxr/base/arch/vsnprintf.h" +#include "pxr/base/tf/mallocTag.h" #include "pxr/base/tf/ostreamMethods.h" #include "pxr/base/tf/patternMatcher.h" #include "pxr/base/tf/stringUtils.h" #include "pxr/base/tf/scopeDescription.h" +#include "pxr/base/tf/stringUtils.h" #include "pxr/usd/sdf/layer.h" #include @@ -517,14 +519,31 @@ main(int argc, char const *argv[]) params.fullArrays = fullArrays; params.timeTolerance = timeTolerance; + // If malloc tags is enabled, keep layers alive so we can report per-layer + // allocations properly. + std::vector keepAlive; + bool mallocTagsEnabled = TfMallocTag::IsInitialized(); + for (auto const &file: inputFiles) { TF_DESCRIBE_SCOPE("Opening layer @%s@", file.c_str()); + TfAutoMallocTag tag(TfStringPrintf("Opening layer @%s@", file.c_str())); auto layer = SdfLayer::FindOrOpen(file); if (!layer) { Err("failed to open layer <%s>", file.c_str()); continue; } Report(layer, params); + if (mallocTagsEnabled) { + keepAlive.push_back(std::move(layer)); + } + } + + if (mallocTagsEnabled) { + printf("MaxTotalBytes allocated: %zu\n", + TfMallocTag::GetMaxTotalBytes()); + TfMallocTag::CallTree callTree; + TfMallocTag::GetCallTree(&callTree); + callTree.Report(std::cout); } return 0;