PAPI  5.0.1.0
PAPI_state.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * We use PAPI_state to get the counting state of an EventSet.This function  *
00003  * returns the state of the entire EventSet.                                 *
00004  *****************************************************************************/
00005 
00006 
00007  
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include "papi.h" /* This needs to be included every time you use PAPI */
00011 
00012 #define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__);  exit(retval); }
00013 
00014 
00015 int main()
00016 {
00017 
00018    int retval; 
00019    int status = 0;
00020    int EventSet = PAPI_NULL;
00021 
00022    /****************************************************************************
00023    *  This part initializes the library and compares the version number of the *
00024    * header file, to the version of the library, if these don't match then it  *
00025    * is likely that PAPI won't work correctly.If there is an error, retval     *
00026    * keeps track of the version number.                                        *
00027    ****************************************************************************/
00028 
00029    if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
00030    {
00031       printf("Library initialization error! \n");
00032       exit(-1);
00033    }
00034 
00035    /*Creating the Eventset */
00036    if((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
00037       ERROR_RETURN(retval);
00038 
00039    /* Add Total Instructions Executed to our EventSet */
00040    if ((retval=PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
00041       ERROR_RETURN(retval);
00042 
00043    if ((retval=PAPI_state(EventSet, &status)) != PAPI_OK)
00044       ERROR_RETURN(retval);
00045 
00046    printstate(status);
00047 
00048    /* Start counting */
00049    if ((retval=PAPI_start(EventSet)) != PAPI_OK)
00050       ERROR_RETURN(retval);
00051 
00052    if (PAPI_state(EventSet, &status) != PAPI_OK)
00053       ERROR_RETURN(retval);
00054      
00055    printstate(status);       
00056  
00057    /* free the resources used by PAPI */
00058    PAPI_shutdown();
00059 
00060    exit(0);
00061 }
00062 
00063 int printstate(int status)
00064 {
00065    if(status & PAPI_STOPPED)
00066       printf("Eventset is currently stopped or inactive \n");
00067    if(status & PAPI_RUNNING)
00068       printf("Eventset is currently running \n");
00069    if(status & PAPI_PAUSED)
00070       printf("Eventset is currently Paused \n");
00071    if(status & PAPI_NOT_INIT) 
00072       printf(" Eventset defined but not initialized \n");
00073    if(status & PAPI_OVERFLOWING)
00074       printf(" Eventset has overflowing enabled \n");
00075    if(status & PAPI_PROFILING)
00076       printf(" Eventset has profiling enabled \n"); 
00077    if(status & PAPI_MULTIPLEXING)
00078       printf(" Eventset has multiplexing enabled \n"); 
00079    return 0;
00080 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines