Chinaunix首页 | 论坛 | 博客
  • 博客访问: 396983
  • 博文数量: 103
  • 博客积分: 3073
  • 博客等级: 中校
  • 技术积分: 1078
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-23 15:04
文章分类

全部博文(103)

文章存档

2012年(13)

2011年(76)

2010年(14)

分类: LINUX

2012-02-10 09:17:58

                                                                                                                
~                                                                                                                             
~                                                                                                                             
~                                                                                                                             
~                                                                                                                             

  1. //#include "papi.h"
  2. #include "/home/zxx/papi-4.2.0/src/papi.h"
  3. #include <stdlib.h>
  4. #include <stdio.h>

  5. int main() {

  6.     int EventSet;
  7.         int i, sum;
  8.     long_long values[1], values1[1], values2[1];

  9.     /* Initialize the PAPI library */
  10.     if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
  11.                 exit(-1);
  12.       // exit(-1);

  13.     /* Create an EventSet */
  14.     EventSet = PAPI_NULL;
  15.     if (PAPI_create_eventset(&EventSet) != PAPI_OK)
  16.         exit(-1);

  17.     /* Add an event about Total Instructions Executed (PAPI_TOT_INS) to EventSet */
  18.     if (PAPI_add_event(EventSet, PAPI_TOT_INS) != PAPI_OK)
  19.         exit(-1);

  20.     /* Start counting events */
  21.     if (PAPI_start(EventSet) != PAPI_OK)
  22.         exit(-1);

  23.     /* Read counters before workload running*/
  24.     if (PAPI_read(EventSet, values1) != PAPI_OK)
  25.         exit(-1);

  26.     /* Do some computation here */
  27.         for (i=0;i<10000;i++)
  28.                 sum+=i;

  29.     /* Stop counting events */
  30.     /* Stop counting events */
  31.     if (PAPI_stop(EventSet, values2) != PAPI_OK)
  32.         exit(-1);


  33.     /* Clean up EventSet */
  34.     if (PAPI_cleanup_eventset(EventSet) != PAPI_OK)
  35.         exit(-1);

  36.     /* Destroy the EventSet */
  37.     if (PAPI_destroy_eventset(&EventSet) != PAPI_OK)
  38.         exit(-1);

  39.     /* Shutdown PAPI */
  40.     PAPI_shutdown();
  41.     /* Get value */
  42.  // values[0] = values2[0] – values1[0];
  43.         values[0]=values2[0]-values1[0];
  44.         printf("%d\n",values[0]);
  45.         return 0;
  46. }
  47. ~

                                                                                                                           
~                                                                                                                             
~                                                                       
阅读(2444) | 评论(0) | 转发(0) |
0

上一篇:Page Coloring

下一篇:How to use function pointer

给主人留下些什么吧!~~