breadcrumbs: Deep Memory Profiler > page_name: cpp-object-type-identifier title: C++ Object Type Identifier (a.k.a. Type Profiler)
The C++ Object Type Identifier (a.k.a. Type Profiler) is another profiling feature to find “Which type is the object?". For example, it reports:
“An object at 0x37f3c88 is an instance of std::string.”
RTTI is not enough to find a type of an object only from its address [1]. You can try it with the following steps. See the Design Doc if interested.
Edit .gclient to checkout the modified version of Clang.
solutions = [
{ "name" : "src",
"url" : "http://git.chromium.org/chromium/src.git",
...
"custom_deps" : {
...
"src/third_party/llvm-allocated-type": "http://src.chromium.org/chrome/trunk/deps/third_party/llvm-allocated-type",
...
},
...
},
]
Build Chromium with additional build options. (“clang_type_profiler=1” is the required option.)
export GYP_DEFINES='clang_type_profiler=1'
export GYP_GENERATORS='ninja'
export GYP_GENERATOR_FLAGS='output_dir=out_type_profile'
gclient runhooks
ninja -C out_type_profile/Debug -j 16 chrome
Run the customized Chromium with Deep Memory Profiler as usual.
Run the dmprof script with a policy label “t0”.
tools/deep_memory_profiler/dmprof csv -p **t0** ~/profile/00-test.12345.0002.heap > ~/profile/00-test.12345.result.csv
Run the customized Chromium with TCMalloc's heap-profiler and an environment variable “HEAP_PROFILE_TYPE_STATISTICS=1”.
HEAPPROFILE=/tmp/prefix HEAP_PROFILE_TIME_INTERVAL=20 HEAP_PROFILE_TYPE_STATISTICS=1 out_type_profile/Debug/chrome --no-sandbox
Type statistics “prefix..????.type” is dumped with every heap profile dump. It is a classification of all malloc'ed objects by their types. For example, " 13: 520 @ N3WTF5MutexE" means that 13 objects of WTF::Mutex occupy 520 bytes.
type statistics:
3739: 841574 @ (no_typeinfo)
1: 16 @ N3WTF13WTFThreadDataE
1: 16 @ N3WTF14ThreadSpecificINS_13WTFThreadDataEE4DataE
...
13: 520 @ N3WTF5MutexE
...
Type Profiler just records mapping from object addresses to their types. You can utilize the mapping by yourself. To use it from your code,