src/components/io/linux-io.c
/** Initialize hardware counters, setup the function vector table
 * and get hardware information, this routine is called when the
 * PAPI process is initialized (IE PAPI_library_init)
 */
Initialize hardware counters, setup the function vector table
and get hardware information, this routine is called when the
PAPI process is initialized
Initialize hardware counters setup the function vector table and get hardware information this routine is called when the PAPI process is initialized
static int
_io_init_component( int cidx )
{
    _io_context_t myCtx;
    int ret, fileIdx;
    SUBDBG( "_io_init_component..." );
    ret = io_count_events(&myCtx);
    if (ret != PAPI_OK) return(ret);
    rewind(myCtx.pFile);
    if (myCtx.EventCount > IO_COUNTERS) {
        snprintf(_io_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN-1,
        "File '%s' has %i events, exceeds counter limit of %i.", IO_FILENAME, myCtx.EventCount, IO_COUNTERS);
        fclose(myCtx.pFile);
        return PAPI_ENOSUPP;
    }
    gEventCount = myCtx.EventCount;
    io_native_table =
        ( IO_native_event_entry_t * )
        papi_calloc(gEventCount, sizeof(IO_native_event_entry_t) );
    if ( io_native_table == NULL ) {
        fclose(myCtx.pFile);
        return PAPI_ENOMEM;
    }
    for (fileIdx = 0; fileIdx < gEventCount; fileIdx++) {
        (void) fgets(myCtx.line, FILE_LINE_SIZE, myCtx.pFile);
        char name[FILE_LINE_SIZE] = {0};
        long long tmplong = 0LL;
        (void) sscanf(myCtx.line, "%s %lld\n", name, &tmplong);
        name[strlen(name)-1]=0;     
        strncpy(io_native_table[fileIdx].name, name, PAPI_MAX_STR_LEN-1);
        io_native_table[fileIdx].fileIdx=fileIdx;
        io_native_table[fileIdx].desc[0]=0;         
        if (strcmp("rchar", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Characters read.");
        }
        if (strcmp("wchar", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Characters written."); 
        }
        if (strcmp("syscr", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Characters read by system calls."); 
        }
        if (strcmp("syscw", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Characters written by system calls."); 
        }
        if (strcmp("read_bytes", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Binary bytes read."); 
        }
        if (strcmp("write_bytes", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Binary bytes written."); 
        }
        if (strcmp("cancelled_write_bytes", name) == 0) {
            strcpy(io_native_table[fileIdx].desc, "Binary write bytes cancelled."); 
        }
        if (io_native_table[fileIdx].desc[0] == 0) {    
            strcpy(io_native_table[fileIdx].desc, "No description available."); 
        }
    } 
    fclose(myCtx.pFile);
    _io_vector.cmp_info.num_native_events = gEventCount;
    _io_vector.cmp_info.num_cntrs = IO_COUNTERS;
    _io_vector.cmp_info.num_mpx_cntrs = IO_COUNTERS;
    _io_vector.cmp_info.CmpIdx = cidx;
    return PAPI_OK;
}
static int _io_init_component ( int cidx ) { _io_context_t myCtx ; int ret , fileIdx ; SUBDBG ( " " ) ; ret = io_count_events ( & myCtx ) ; if ( ret != PAPI_OK ) return ( ret ) ; rewind ( myCtx . pFile ) ; if ( myCtx . EventCount > IO_COUNTERS ) { snprintf ( _io_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN - 1 , " " , IO_FILENAME , myCtx . EventCount , IO_COUNTERS ) ; fclose ( myCtx . pFile ) ; return PAPI_ENOSUPP ; } gEventCount = myCtx . EventCount ; io_native_table = ( IO_native_event_entry_t * ) papi_calloc ( gEventCount , sizeof ( IO_native_event_entry_t ) ) ; if ( io_native_table == NULL ) { fclose ( myCtx . pFile ) ; return PAPI_ENOMEM ; } for ( fileIdx = 0 ; fileIdx < gEventCount ; fileIdx ++ ) { ( void ) fgets ( myCtx . line , FILE_LINE_SIZE , myCtx . pFile ) ; char name [ FILE_LINE_SIZE ] = { 0 } ; long long tmplong = 0LL ; ( void ) sscanf ( myCtx . line , " \n " , name , & tmplong ) ; name [ strlen ( name ) - 1 ] = 0 ; strncpy ( io_native_table [ fileIdx ] . name , name , PAPI_MAX_STR_LEN - 1 ) ; io_native_table [ fileIdx ] . fileIdx = fileIdx ; io_native_table [ fileIdx ] . desc [ 0 ] = 0 ; if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( strcmp ( " " , name ) == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } if ( io_native_table [ fileIdx ] . desc [ 0 ] == 0 ) { strcpy ( io_native_table [ fileIdx ] . desc , " " ) ; } } fclose ( myCtx . pFile ) ; _io_vector . cmp_info . num_native_events = gEventCount ; _io_vector . cmp_info . num_cntrs = IO_COUNTERS ; _io_vector . cmp_info . num_mpx_cntrs = IO_COUNTERS ; _io_vector . cmp_info . CmpIdx = cidx ; return PAPI_OK ; }
Initialize hardware counters, setup the function vector table
 and get hardware information, this routine is called when the
 PAPI process is initialized (IE PAPI_library_init)
Initialize hardware counters setup the function vector table and get hardware information this routine is called when the PAPI process is initialized ( IE PAPI_library_init )
// Must be same for all threads, now. /* Allocate memory for the native event table */ // No check for error here, we would have caught it in io_count_events(). // null terminate over ':' we found. // flag for successful copy. // If none of the above found, generic description. // END READING. // Export the total number of events available, at least on the init thread. /* Export the component id */