src/components/sde/sde.c
/** Takes a native event name and passes back the code 
 * @param event_name -- a pointer for the name to be copied to
 * @param event_code -- the native event code
 */
Takes a native event name and passes back the code
@param event_name -- a pointer for the name to be copied to
@param event_code -- the native event code
Takes a native event name and passes back the code @param event_name -- a pointer for the name to be copied to @param event_code -- the native event code
static int
_sde_ntv_name_to_code(const char *event_name, unsigned int *event_code ) 
{
    papisde_library_desc_t *lib_handle;
    char *pos, *tmp_lib_name;
    sde_counter_t *tmp_item = NULL;
    SUBDBG( "%s\n", event_name );
    papi_sde_lock();
    papisde_control_t *gctl = _papisde_global_control;
    tmp_lib_name = strdup(event_name);
    pos = strstr(tmp_lib_name, "::");
    if( NULL != pos ){ 
        *pos = '\0';
        if( NULL == gctl ){
            lib_handle = do_sde_init(tmp_lib_name);
            if(NULL == lib_handle){
                PAPIERROR("Unable to register library in SDE component.\n");
                papi_sde_unlock();
                return PAPI_ECMP;
            }
            gctl = _papisde_global_control;
        }else{
            int is_library_present = 0;
            lib_handle = gctl->lib_list_head;
            while(NULL != lib_handle){ 
                if( !strcmp(lib_handle->libraryName, tmp_lib_name) ){
                    is_library_present = 1;
                    tmp_item = ht_lookup_by_name(lib_handle->lib_counters, event_name);
                    break;
                }
                lib_handle = lib_handle->next;
            }
            if( !is_library_present ){
                lib_handle = do_sde_init(tmp_lib_name);
                if(NULL == lib_handle){
                    PAPIERROR("Unable to register library in SDE component.\n");
                    papi_sde_unlock();
                    return PAPI_ECMP;
                }
             }
        }
        free(tmp_lib_name); 
        if( NULL != tmp_item ){
            SUBDBG("Found matching counter with global uniq id: %d in library: %s\n", tmp_item->glb_uniq_id, lib_handle->libraryName );
            *event_code = tmp_item->glb_uniq_id;
            papi_sde_unlock();
            return PAPI_OK;
        } else {
            SUBDBG("Did not find event %s in library %s. Registering a placeholder.\n", event_name, lib_handle->libraryName );  
            unsigned int counter_uniq_id = gctl->num_reg_events++;
            gctl->num_live_events++;
            _sde_vector.cmp_info.num_native_events = gctl->num_live_events;
            tmp_item = allocate_and_insert( lib_handle, event_name, counter_uniq_id, PAPI_SDE_RO, PAPI_SDE_long_long, NULL, NULL, NULL );
            if(NULL == tmp_item) {
                papi_sde_unlock();
                SUBDBG("Event %s does not exist in library %s and placeholder could not be inserted.\n", event_name, lib_handle->libraryName);
                return PAPI_ECMP;
            }
            *event_code = tmp_item->glb_uniq_id;
            papi_sde_unlock();
            return PAPI_OK;
        }
    }else{
        free(tmp_lib_name);
    }
    if( NULL == gctl ){
        papi_sde_unlock();
        return PAPI_ENOEVNT;
    }
    lib_handle = gctl->lib_list_head;
    while(NULL != lib_handle){
        tmp_item = ht_lookup_by_name(lib_handle->lib_counters, event_name);
        if( NULL != tmp_item ){
            *event_code = tmp_item->glb_uniq_id;
            papi_sde_unlock();
            SUBDBG("Found matching counter with global uniq id: %d in library: %s\n", tmp_item->glb_uniq_id, lib_handle->libraryName );
            return PAPI_OK;
        } else {
            SUBDBG("Failed to find event %s in library %s. Looking in other libraries.\n", event_name, lib_handle->libraryName );  
        }
        lib_handle = lib_handle->next;
    }
    papi_sde_unlock();
    return PAPI_ENOEVNT;
}
static int _sde_ntv_name_to_code ( const char * event_name , unsigned int * event_code ) { papisde_library_desc_t * lib_handle ; char * pos , * tmp_lib_name ; sde_counter_t * tmp_item = NULL ; SUBDBG ( " \n " , event_name ) ; papi_sde_lock ( ) ; papisde_control_t * gctl = _papisde_global_control ; tmp_lib_name = strdup ( event_name ) ; pos = strstr ( tmp_lib_name , " " ) ; if ( NULL != pos ) { * pos = ' \0 ' ; if ( NULL == gctl ) { lib_handle = do_sde_init ( tmp_lib_name ) ; if ( NULL == lib_handle ) { PAPIERROR ( " \n " ) ; papi_sde_unlock ( ) ; return PAPI_ECMP ; } gctl = _papisde_global_control ; } else { int is_library_present = 0 ; lib_handle = gctl -> lib_list_head ; while ( NULL != lib_handle ) { if ( ! strcmp ( lib_handle -> libraryName , tmp_lib_name ) ) { is_library_present = 1 ; tmp_item = ht_lookup_by_name ( lib_handle -> lib_counters , event_name ) ; break ; } lib_handle = lib_handle -> next ; } if ( ! is_library_present ) { lib_handle = do_sde_init ( tmp_lib_name ) ; if ( NULL == lib_handle ) { PAPIERROR ( " \n " ) ; papi_sde_unlock ( ) ; return PAPI_ECMP ; } } } free ( tmp_lib_name ) ; if ( NULL != tmp_item ) { SUBDBG ( " \n " , tmp_item -> glb_uniq_id , lib_handle -> libraryName ) ; * event_code = tmp_item -> glb_uniq_id ; papi_sde_unlock ( ) ; return PAPI_OK ; } else { SUBDBG ( " \n " , event_name , lib_handle -> libraryName ) ; unsigned int counter_uniq_id = gctl -> num_reg_events ++ ; gctl -> num_live_events ++ ; _sde_vector . cmp_info . num_native_events = gctl -> num_live_events ; tmp_item = allocate_and_insert ( lib_handle , event_name , counter_uniq_id , PAPI_SDE_RO , PAPI_SDE_long_long , NULL , NULL , NULL ) ; if ( NULL == tmp_item ) { papi_sde_unlock ( ) ; SUBDBG ( " \n " , event_name , lib_handle -> libraryName ) ; return PAPI_ECMP ; } * event_code = tmp_item -> glb_uniq_id ; papi_sde_unlock ( ) ; return PAPI_OK ; } } else { free ( tmp_lib_name ) ; } if ( NULL == gctl ) { papi_sde_unlock ( ) ; return PAPI_ENOEVNT ; } lib_handle = gctl -> lib_list_head ; while ( NULL != lib_handle ) { tmp_item = ht_lookup_by_name ( lib_handle -> lib_counters , event_name ) ; if ( NULL != tmp_item ) { * event_code = tmp_item -> glb_uniq_id ; papi_sde_unlock ( ) ; SUBDBG ( " \n " , tmp_item -> glb_uniq_id , lib_handle -> libraryName ) ; return PAPI_OK ; } else { SUBDBG ( " \n " , event_name , lib_handle -> libraryName ) ; } lib_handle = lib_handle -> next ; } papi_sde_unlock ( ) ; return PAPI_ENOEVNT ; }
Takes a native event name and passes back the code
 @param event_name -- a pointer for the name to be copied to
 @param event_code -- the native event code
Takes a native event name and passes back the code @param event_name -- a pointer for the name to be copied to @param event_code -- the native event code
// Let's see if the event has the library name as a prefix (as it should). Note that this is // the event name as it comes from the framework, so it should contain the library name, although // when the library registers an event counter it will not use the library name as part of the event name. // Good, it does. // If no library has initialized the library side of the component, and the application is already inquiring // about an event, let's initialize the component pretending to be the library which corresponds to this event. // If the library side of the component has been initialized, then look for the library. // Look for the library. // We found the library. // Now, look for the event in the library. // If the library side of the component was initialized, but the specific library hasn't called // papi_sde_init() then we call it here to allocate the data structures. // We don't need the library name any more. // Use the current number of registered events as the index of the new one, and increment it. // At this point in the code "lib_handle" contains a pointer to the data structure for this library whether // the actual library has been initialized or not. // If no library has initialized the component and we don't know a library name, then we have to return. // If the event name does not have the library name as a prefix, then we need to look in all the libraries for the event. However, in this case // we can _not_ register a placeholder because we don't know which library the event belongs to.