次の手順では、次に示すようにdprime.d
ファイルから.h
ファイルを作成します:
# dtrace -h -s dprime.d
作成されるdprime.h
ファイルには、dprime.d
ファイル内で定義されている各プローブ・ポイントへの参照が含まれます。
次に、アプリケーション・ソース・ファイルprimain.c
で、#include "dprime.h"
ファイルへの参照を追加し、適切な場所に適切なプローブ・スイマクロを追加します。
生成されたprimain.c
ファイルでは、プローブのマクロ(例は太字で表示されている)が大文字で表示されるため簡単に認識できます:
#include <stdio.h> #include "primelib.h" #include "dprime.h" /* * Nominal C program churning to provide a code base we might want to * instrument with D */ // Search for a divisor -- thereby proving composite value of the input. int main() { int targVal, divisor, factorA=0, factorB=0; printf( "Enter a positive target integer to test for prime status: " ); scanf( "%d", &targVal ); // Check that the user input is valid if( targVal < 2 ) { printf( "Invalid input value -- exiting now\n" ); return -2; } if (PRIMEGET_QUERY_USERENTRY_ENABLED()) PRIMEGET_QUERY_USERENTRY(targVal); // Search for a divisor using method and function A int lastCheck; lastCheck = findMaxCheck( targVal ); printf( "%d highest value to check as divisor\n", lastCheck ); if (PRIMEGET_QUERY_MAXCHECKVAL_ENABLED()) PRIMEGET_QUERY_MAXCHECKVAL(lastCheck, targVal); factorA = seekFactorA( targVal, lastCheck ); if (PRIMEGET_QUERY_FACTORRETURNA_ENABLED()) PRIMEGET_QUERY_FACTORRETURNA(factorA, targVal); // Search for a divisor using method and function B factorB = seekFactorB( targVal ); if (PRIMEGET_QUERY_FACTORRETURNB_ENABLED()) PRIMEGET_QUERY_FACTORRETURNB(factorB, targVal); // Warn if the methods give different results if (factorA != factorB) printf( "%d does not equal %d! How can this be?\n", factorA, factorB ); // Print results if( !factorA ) printf( "%d is a prime number\n", targVal ); else printf( "%d is not prime because there is a factor %d\n", targVal, factorA ); if (PRIMEGET_QUERY_FINAL_ENABLED()) PRIMEGET_QUERY_FINAL(); return 0; }
関連付けられたプローブが有効になっている場合(一部のコンシューマがこのプローブを使用している場合)、任意の*
_ENABLED()
プローブはtrue値に変換され、関連付けられたプローブが有効になっていない場合は。
続行する前に、プローブが有効化され、dprime.h
ファイルに示すマクロとして表示されていることを確認します。 「Oracle® Linux: DTraceガイド」の「プローブが有効になっているかどうかのテスト」を参照してください。
該当する値が存在する場合は、プローブでその値も識別できるように、マクロに目的の値を含めてください。
次に、makefile
ファイルを変更する必要があります。 段階的なステップは、「Oracle® Linux: DTraceガイド」の「プローブありアプリケーションのビルド」を参照してください。