4

C で PAPI api を使用してアプリケーションのシステムのパフォーマンスを分析したいと考えています。一般的な構造は、
- PAPIを初期化します-対象
のカウンターを初期化します-カウンターを
開始します
-アプリケーションのメインロジックを実行します
-カウンターを終了し、値を読み取ります

アプリケーションの最後に最終値を読み取るのではなく、1 秒ごとにカウンターを定期的に読み取りたいと考えています。PAPI出力は、プログラム実行後のL2キャッシュミスの総数など、プログラム実行の終了時に集計値を提供しますか? もう 1 つの例は、プログラムの最後に命令の総数ではなく、インスタンスごとに命令の数を読み取ることです。

4

1 に答える 1

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 */


}
于 2012-09-12T09:15:59.563 に答える