メモリー割り当て API

インテル® VTune™ プロファイラーは、malloc 形式のヒープ管理関数のセマンティクスを識別するのに有用な一連の API を提供します。

これらの API を使用してコードにアノテーションを追加すると、インテル® VTune™ プロファイラーはメモリーアクセス解析の一部としてメモリー・オブジェクトを正確に判別できます。

使用法

メモリー割り当て API を使用するには次のガイドラインに従ってください。

コードでメモリー割り当て API を使用する

操作

説明

typedef void* __itt_heap_function; __itt_heap_function __itt_heap_function_create( const __itt_char* <name>, const __itt_char* <domain> );

begin および end 呼び出しとドメインに一致するハンドルタイプを宣言します。

  • name = アノテートする関数の名前です。

  • domain = 一致する関数のセットを識別する文字列です。例えば、alloc_my_structsfree_my_structs、および realloc_my_structs など、すべて my_struct で動作する 3 つの関数がある場合、同じドメインを 3 つの__itt_heap_function_create()呼び出しに渡します。

void __itt_heap_allocate_begin( __itt_heap_function <h>, size_t <size>, int <initialized> ); void __itt_heap_allocate_end( __itt_heap_function <h>, void** <addr>, size_t <size>, int <initialized> );

割り当て関数を特定します。h = この関数名が __itt_heap_function_create() に渡されたときに返されるハンドル。

  • size = 要求されたメモリー領域のバイト単位のサイズ。

  • initialized = このルーチンによってメモリー領域が初期化されるかどうかを示すフラグ。

  • addr = この関数が割り当てられたメモリー領域のアドレスへのポインター。割り当てが失敗した場合は 0。

void __itt_heap_free_begin( __itt_heap_function <h>, void* <addr> ); void __itt_heap_free_end( __itt_heap_function <h>, void* <addr> );

割り当て解除関数を特定します。

  • h = この関数名が __itt_heap_function_create() に渡されたときに返されるハンドル。

  • addr = この関数が解放するメモリー領域のアドレスへのポインター。

void __itt_heap_reallocate_begin( __itt_heap_function <h>, void* <addr>, size_t <new_size>, int <initialized> ); void __itt_heap_reallocate_end( __itt_heap_function <h>, void* <addr>, void** <new_addr>, size_t <new_size>, int <initialized> );

再割り当て関数を特定します。

注:itt_heap_reallocate_end()は、メモリーが返されなくとも要求後に呼び出す必要があります。インテル® VTune™ プロファイラー は、C ランタイムの realloc セマンティクスを想定しています。

  • h = この関数名が __itt_heap_function_create() に渡されたときに返されるハンドル。

  • addr =この関数が再割り当するメモリー領域のアドレスへのポインター。addr が NULL の場合、インテル® VTune™ プロファイラーはこれを割り当てのように扱います。

  • new_addr = 再割り当てされたメモリー領域のアドレスを保持するポインターへのポインター。

  • size = 要求されたメモリー領域のバイト単位のサイズ。new_size が 0 の場合、インテル® VTune™ プロファイラーはこれを解放のように扱います。

使用例: ヒープ割り当て

#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"); }

関連情報