#include "titanium.h" #include "needs!T11PAPICounter.c.h" #include "T11PAPICounter.h" #include "T11NativeUtils4lang2ti.h" #include "T5Class4lang4java.h" #include "layout!ti5cdescmT11PAPICounter.h" #include #include void m9PAPI_initmT11PAPICounter(); void m13PAPI_shutdownmT11PAPICounter(); void m10PAPI_startImT11PAPICounter(jint eventSet); jlong m9PAPI_stopIJmT11PAPICounter(jint eventSet, jlong value); jint m12PAPI_cleanupImT11PAPICounter(jint eventSet); void PAPI_init(); jint m20PAPI_initSingleEventIImT11PAPICounter(jint event, jint eventSet); jint m15PAPI_checkEventImT11PAPICounter(jint event); void PAPI_initSingleEvent(int event, int *tag); static __tic_lock_t TI_PAPI_lock = __tic_lock_decl_initializer; static int isInit = 0; jint m15PAPI_checkEventImT11PAPICounter(jint event){ int retval; __tic_lock(&TI_PAPI_lock); retval = PAPI_query_event((int) event); __tic_unlock(&TI_PAPI_lock); if (retval == PAPI_OK){ return (jint) 1; } else{ return (jint) 0; } } void m9PAPI_initmT11PAPICounter(){ __tic_lock(&TI_PAPI_lock); if (isInit == 0){ isInit = 1; PAPI_init(); } __tic_unlock(&TI_PAPI_lock); } void PAPI_init(){ int retval; retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 0, (jint) retval); } retval = PAPI_multiplex_init(); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 1, (jint) retval); } retval = PAPI_set_debug(PAPI_VERB_ECONT); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 2, (jint) retval); } #ifdef MEMORY_SHARED retval = PAPI_thread_init((unsigned long (*)(void))(pthread_self), 0); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 3, (jint) retval); } #endif } jint m20PAPI_initSingleEventIImT11PAPICounter(jint event, jint eventSet){ int tmp = (int) eventSet; __tic_lock(&TI_PAPI_lock); PAPI_initSingleEvent((int) event, &tmp); __tic_unlock(&TI_PAPI_lock); return (jint) tmp; } void PAPI_initSingleEvent(int event, int *tag) { int retval; retval = PAPI_query_event(event); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 4, (jint) retval); } retval = PAPI_create_eventset(tag); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 5, (jint) retval); } retval = PAPI_add_event(tag, event); if (retval == PAPI_ECNFLCT){ __tic_unlock(&TI_PAPI_lock); m28throwTooManyCounterExceptionmT11PAPICounter(); } if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 6, (jint) retval); } } void m13PAPI_shutdownmT11PAPICounter(){ __tic_lock(&TI_PAPI_lock); PAPI_shutdown(); __tic_unlock(&TI_PAPI_lock); } void m10PAPI_startImT11PAPICounter(jint eventSet){ int retval; __tic_lock(&TI_PAPI_lock); retval = PAPI_start((int) eventSet); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 7, (jint) retval); } __tic_unlock(&TI_PAPI_lock); } jlong m9PAPI_stopIJmT11PAPICounter(jint eventSet, jlong value){ long long int tmp[1]; int retval; __tic_lock(&TI_PAPI_lock); tmp[0] = 0; retval = PAPI_stop((int) eventSet, tmp); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 8, (jint) retval); } __tic_unlock(&TI_PAPI_lock); return (jlong) tmp[0]; } jint m12PAPI_cleanupImT11PAPICounter(jint eventSet){ int tmp = (int) eventSet; int retval; __tic_lock(&TI_PAPI_lock); retval = PAPI_cleanup_eventset(&tmp); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 9, (jint) retval); } retval = PAPI_destroy_eventset(&tmp); if (retval != PAPI_OK){ __tic_unlock(&TI_PAPI_lock); m18throwPAPIExceptionIImT11PAPICounter((jint) 10, (jint) retval); } __tic_unlock(&TI_PAPI_lock); return (jint) tmp; }