インテル® VTune™ プロファイラーは、malloc 形式のヒープ管理関数のセマンティクスを識別するのに有用な一連の API を提供します。
これらの API を使用してコードにアノテーションを追加すると、インテル® VTune™ プロファイラーはメモリーアクセス解析の一部としてメモリー・オブジェクトを正確に判別できます。
メモリー割り当て API を使用するには次のガイドラインに従ってください。
ルーチンのラッパー関数を作成し、それらの関数に __Itt_heap_*_begin および __itt_heap_*_end 呼び出しを追加します。
allocate/free 関数のペアに対して一意のドメインを割り当てて、__itt_heap_function_create を呼び出します。これにより、インテル® VTune™ プロファイラーは、allocate 関数呼び出しごとに対応する free 関数の呼び出しを確認できます。
すべての allocate 関数と free 関数の前後にアノテーションを追加します。
すべての関数ペアを同じスタックフレームから呼び出します。そうしないと、インテル® VTune™ プロファイラーは例外が発生したと仮定し、割り当ては失敗します。
対応する begin 関数なしで end 関数を呼び出してはなりません。
操作 |
説明 |
---|---|
|
begin および end 呼び出しとドメインに一致するハンドルタイプを宣言します。
|
|
割り当て関数を特定します。h = この関数名が __itt_heap_function_create() に渡されたときに返されるハンドル。
|
|
割り当て解除関数を特定します。
|
|
再割り当て関数を特定します。 注:itt_heap_reallocate_end()は、メモリーが返されなくとも要求後に呼び出す必要があります。インテル® VTune™ プロファイラー は、C ランタイムの realloc セマンティクスを想定しています。
|
#include <ittnotify.h> void* user_defined_malloc(size_t size); void user_defined_free(void *p); void* user_defined_realloc(void *p, size_t s); __itt_heap_function my_allocator; __itt_heap_function my_reallocator; __itt_heap_function my_freer; void* my_malloc(size_t s) { void* p; __itt_heap_allocate_begin(my_allocator, s, 0); p = user_defined_malloc(s); __itt_heap_allocate_end(my_allocator, &p, s, 0); return p; } void my_free(void *p) { __itt_heap_free_begin (my_freer, p); user_defined_free(p); __itt_heap_free_end (my_freer, p); } void* my_realloc(void *p, size_t s) { void *np; __itt_heap_reallocate_begin (my_reallocator, p, s, 0); np = user_defined_realloc(p, s); __itt_heap_reallocate_end(my_reallocator, p, &np, s, 0); return(np); } // Make sure to call this init routine before any calls to // user defined allocators. void init_itt_calls() { my_allocator = __itt_heap_function_create("my_malloc", "mydomain"); my_reallocator = __itt_heap_function_create("my_realloc", "mydomain"); my_freer = __itt_heap_function_create("my_free", "mydomain"); }