3.3.3 例: dprime.dファイルからの.hファイルの作成

次の手順では、次に示すように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ガイドプローブありアプリケーションのビルドを参照してください。