File: PAPI_state.c

package info (click to toggle)
papi 5.7.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (80 lines) | stat: -rw-r--r-- 2,589 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*****************************************************************************
 * We use PAPI_state to get the counting state of an EventSet.This function  *
 * returns the state of the entire EventSet.                                 *
 *****************************************************************************/


 
#include <stdio.h>
#include <stdlib.h>
#include "papi.h" /* This needs to be included every time you use PAPI */

#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__);  exit(retval); }


int main()
{

   int retval; 
   int status = 0;
   int EventSet = PAPI_NULL;

   /****************************************************************************
   *  This part initializes the library and compares the version number of the *
   * header file, to the version of the library, if these don't match then it  *
   * is likely that PAPI won't work correctly.If there is an error, retval     *
   * keeps track of the version number.                                        *
   ****************************************************************************/

   if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
   {
      printf("Library initialization error! \n");
	  exit(-1);
   }

   /*Creating the Eventset */
   if((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* Add Total Instructions Executed to our EventSet */
   if ((retval=PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
      ERROR_RETURN(retval);

   if ((retval=PAPI_state(EventSet, &status)) != PAPI_OK)
      ERROR_RETURN(retval);

   printstate(status);

   /* Start counting */
   if ((retval=PAPI_start(EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   if (PAPI_state(EventSet, &status) != PAPI_OK)
      ERROR_RETURN(retval);
     
   printstate(status);       
 
   /* free the resources used by PAPI */
   PAPI_shutdown();

   exit(0);
}

int printstate(int status)
{
   if(status & PAPI_STOPPED)
      printf("Eventset is currently stopped or inactive \n");
   if(status & PAPI_RUNNING)
      printf("Eventset is currently running \n");
   if(status & PAPI_PAUSED)
      printf("Eventset is currently Paused \n");
   if(status & PAPI_NOT_INIT) 
      printf(" Eventset defined but not initialized \n");
   if(status & PAPI_OVERFLOWING)
      printf(" Eventset has overflowing enabled \n");
   if(status & PAPI_PROFILING)
      printf(" Eventset has profiling enabled \n"); 
   if(status & PAPI_MULTIPLEXING)
      printf(" Eventset has multiplexing enabled \n"); 
   return 0;
}