2011-11-16 7 views
3

性能測定のために定期的にPAPIを使用する方法
がということです開始カウンター
は - アプリケーション
のメインロジックを実行 - エンドカウンタを、私はカウンターを読みたい値には、私はC言語で一般的な構造をPAPI APIを使用して自分のアプリケーションのために、システムのパフォーマンスを分析する

を読んで、定期的にアプリケーションの終了時に、最終的な値を読み取るのではなく、1秒ごとを言います。 PAPI出力は、プログラムの実行終了時に、プログラム実行後のL2キャッシュミスの総数などの集計値を与えますか?別の例は、プログラムの最後にある命令の総数ではなく、毎回のインスタンスで命令の数を読み取ることです。

+0

一つの解決策は、2つのスレッドを使用してにすることができます。メインアプリケーションを実行するための1および他のちょうどあなたが定期的にカウンターを読み込むこと初期化して使用することを決定します。 – Leos313

答えて

3

あなたはこれについて何か考えましたか?私は同じことをやっているが、私は奇妙な結果を得ている:私のカウンターは私が好きなほど頻繁に更新されていない。レコードの

が、ここで私がテストし、うまく機能したサンプルは、次のとおりです。

#include <papi.h> 
#include <stdio.h> 
#include <stdlib.h> 

main() 
{ 
int retval, EventSet = PAPI_NULL; 
long_long values[3]; 
    unsigned counter; 
    unsigned c; 
    unsigned long fact; 
    unsigned stoppoint; 


     /* Initialize the PAPI library */ 
     retval = PAPI_library_init(PAPI_VER_CURRENT); 

     if (retval != PAPI_VER_CURRENT) { 
      fprintf(stderr, "PAPI library init error!\n"); 
      exit(1); 
     } 

     /* Create the Event Set */ 
     if (PAPI_create_eventset(&EventSet) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 

     /* Add Total Instructions Executed to our EventSet */ 
     if (PAPI_add_event(EventSet, PAPI_TOT_INS) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 

     /* Add Total Instructions Executed to our EventSet */ 
     if (PAPI_add_event(EventSet, PAPI_TOT_CYC) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 

     /* Add Total Instructions Executed to our EventSet */ 
     if (PAPI_add_event(EventSet, PAPI_LST_INS) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 


    srand (time(NULL)); 
    stoppoint = 50+(rand() % 100); 
/* Do some computation here */ 
    for (counter = 0; counter < stoppoint; counter++) 
    { 
     /* Initialize the PAPI library */ 
     retval = PAPI_library_init(PAPI_VER_CURRENT); 

     if (retval != PAPI_VER_CURRENT) { 
      fprintf(stderr, "PAPI library init error!\n"); 
      exit(1); 
     } 


     /* Start counting */ 
     if (PAPI_start(EventSet) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 


       fact = 1; 
     for (c = 1; c <= counter; c++) 
     { 
        fact = c * c; 
     } 




     printf("Factorial of %d is %lu\n", counter, fact); 
     if (PAPI_read(EventSet, values) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 
     printf ("\nTotal Instructions Completed:\t%lld\t Total Cycles:\t%lld\tLoad Store Instructions\t%lld\n\n", values[0], values[1], values[2]); 
     /* Do some computation here */ 

     if (PAPI_stop(EventSet, values) != PAPI_OK) 
      printf ("%s:%d\t ERROR\n", __FILE__, __LINE__); 

      } 
     /* End of computation */ 


} 
関連する問題