|
PAPI
5.0.1.0
|
appio component This file contains the source code for a component that enables PAPI to access application level file and socket I/O information. It does this through function replacement in the first person and by trapping syscalls in the third person. More...

Go to the source code of this file.
Credit to: Jose Pedro Oliveira jpo@di.uminho.pt whose code in the linux net component was used as a template for many sections of code in this component.
Definition in file appio.c.
| enum _appio_stats_t |
Definition at line 67 of file appio.c.
{
READ_BYTES = 0,
READ_CALLS,
READ_ERR,
READ_INTERRUPTED,
READ_WOULD_BLOCK,
READ_SHORT,
READ_EOF,
READ_BLOCK_SIZE,
READ_USEC,
WRITE_BYTES,
WRITE_CALLS,
WRITE_ERR,
WRITE_SHORT,
WRITE_WOULD_BLOCK,
WRITE_BLOCK_SIZE,
WRITE_USEC,
OPEN_CALLS,
OPEN_ERR,
OPEN_FDS,
SELECT_USEC,
RECV_BYTES,
RECV_CALLS,
RECV_ERR,
RECV_INTERRUPTED,
RECV_WOULD_BLOCK,
RECV_SHORT,
RECV_EOF,
RECV_BLOCK_SIZE,
RECV_USEC
} _appio_stats_t ;
| int __close | ( | int | fd | ) |

| int __open | ( | const char * | pathname, |
| int | flags, | ||
| mode_t | mode | ||
| ) |

| int __select | ( | int | nfds, |
| fd_set * | readfds, | ||
| fd_set * | writefds, | ||
| fd_set * | exceptfds, | ||
| struct timeval * | timeout | ||
| ) |


| int _appio_ctl | ( | hwd_context_t * | ctx, |
| int | code, | ||
| _papi_int_option_t * | option | ||
| ) |
| int _appio_init_component | ( | int | cidx | ) |
Definition at line 337 of file appio.c.
{
SUBDBG("_appio_component %d\n", cidx);
_appio_native_events = (APPIO_native_event_entry_t *) papi_calloc(sizeof(APPIO_native_event_entry_t), APPIO_MAX_COUNTERS);
if (_appio_native_events == NULL ) {
PAPIERROR( "malloc():Could not get memory for events table" );
return PAPI_ENOMEM;
}
int i;
for (i=0; i<APPIO_MAX_COUNTERS; i++) {
_appio_native_events[i].name = _appio_counter_info[i].name;
_appio_native_events[i].description = _appio_counter_info[i].description;
_appio_native_events[i].resources.selector = i + 1;
}
/* Export the total number of events available */
_appio_vector.cmp_info.num_native_events = APPIO_MAX_COUNTERS;;
/* Export the component id */
_appio_vector.cmp_info.CmpIdx = cidx;
return PAPI_OK;
}

| int _appio_init_control_state | ( | hwd_control_state_t * | ctl | ) |
| int _appio_init_thread | ( | hwd_context_t * | ctx | ) |
| int _appio_ntv_code_to_bits | ( | unsigned int | EventCode, |
| hwd_register_t * | bits | ||
| ) |
Definition at line 623 of file appio.c.
{
int index = EventCode;
if ( index >= 0 && index < APPIO_MAX_COUNTERS ) {
memcpy( ( APPIO_register_t * ) bits,
&( _appio_native_events[index].resources ),
sizeof ( APPIO_register_t ) );
return PAPI_OK;
}
return PAPI_ENOEVNT;
}
| int _appio_ntv_code_to_descr | ( | unsigned int | EventCode, |
| char * | desc, | ||
| int | len | ||
| ) |
Definition at line 606 of file appio.c.
{
int index = EventCode;
if ( index >= 0 && index < APPIO_MAX_COUNTERS ) {
strncpy(desc, _appio_counter_info[index].description, len );
return PAPI_OK;
}
return PAPI_ENOEVNT;
}
| int _appio_ntv_code_to_name | ( | unsigned int | EventCode, |
| char * | name, | ||
| int | len | ||
| ) |
Definition at line 589 of file appio.c.
{
int index = EventCode;
if ( index >= 0 && index < APPIO_MAX_COUNTERS ) {
strncpy( name, _appio_counter_info[index].name, len );
return PAPI_OK;
}
return PAPI_ENOEVNT;
}
| int _appio_ntv_enum_events | ( | unsigned int * | EventCode, |
| int | modifier | ||
| ) |
Definition at line 538 of file appio.c.
{
int index;
switch ( modifier ) {
case PAPI_ENUM_FIRST:
*EventCode = 0;
return PAPI_OK;
break;
case PAPI_ENUM_EVENTS:
index = *EventCode;
if ( index < APPIO_MAX_COUNTERS - 1 ) {
*EventCode = *EventCode + 1;
return PAPI_OK;
} else {
return PAPI_ENOEVNT;
}
break;
default:
return PAPI_EINVAL;
break;
}
return PAPI_EINVAL;
}
| int _appio_ntv_name_to_code | ( | char * | name, |
| unsigned int * | EventCode | ||
| ) |
Definition at line 570 of file appio.c.
{
int i;
for ( i=0; i<APPIO_MAX_COUNTERS; i++) {
if (strcmp(name, _appio_counter_info[i].name) == 0) {
*EventCode = i;
return PAPI_OK;
}
}
return PAPI_ENOEVNT;
}
| int _appio_read | ( | hwd_context_t * | ctx, |
| hwd_control_state_t * | ctl, | ||
| long long ** | events, | ||
| int | flags | ||
| ) |
Definition at line 396 of file appio.c.
{
(void) flags;
(void) ctx;
SUBDBG("_appio_read %p %p\n", ctx, ctl);
APPIO_control_state_t *appio_ctl = (APPIO_control_state_t *) ctl;
int i;
for ( i=0; i<appio_ctl->num_events; i++ ) {
int index = appio_ctl->counter_bits[i];
SUBDBG("event=%d, index=%d, val=%lld\n", i, index, _appio_register_current[index]);
appio_ctl->values[index] = _appio_register_current[index];
}
*events = appio_ctl->values;
return PAPI_OK;
}
| int _appio_reset | ( | hwd_context_t * | ctx, |
| hwd_control_state_t * | ctl | ||
| ) |
| int _appio_set_domain | ( | hwd_control_state_t * | ctl, |
| int | domain | ||
| ) |
Definition at line 507 of file appio.c.
{
( void ) ctl;
int found = 0;
if ( PAPI_DOM_USER & domain ) found = 1;
if ( PAPI_DOM_KERNEL & domain ) found = 1;
if ( PAPI_DOM_OTHER & domain ) found = 1;
if ( !found )
return PAPI_EINVAL;
return PAPI_OK;
}
| int _appio_shutdown_component | ( | void | ) |
| int _appio_shutdown_thread | ( | hwd_context_t * | ctx | ) |
| int _appio_start | ( | hwd_context_t * | ctx, |
| hwd_control_state_t * | ctl | ||
| ) |
Definition at line 378 of file appio.c.
{
( void ) ctx;
SUBDBG("_appio_start %p %p\n", ctx, ctl);
APPIO_control_state_t *appio_ctl = (APPIO_control_state_t *) ctl;
/* this memset needs to move to thread_init */
memset(_appio_register_current, 0, APPIO_MAX_COUNTERS * sizeof(_appio_register_current[0]));
/* set initial values to 0 */
memset(appio_ctl->values, 0, APPIO_MAX_COUNTERS*sizeof(appio_ctl->values[0]));
return PAPI_OK;
}
| int _appio_stop | ( | hwd_context_t * | ctx, |
| hwd_control_state_t * | ctl | ||
| ) |
Definition at line 418 of file appio.c.
{
(void) ctx;
SUBDBG("_appio_stop ctx=%p ctl=%p\n", ctx, ctl);
APPIO_control_state_t *appio_ctl = (APPIO_control_state_t *) ctl;
int i;
for ( i=0; i<appio_ctl->num_events; i++ ) {
int index = appio_ctl->counter_bits[i];
SUBDBG("event=%d, index=%d, val=%lld\n", i, index, _appio_register_current[index]);
appio_ctl->values[i] = _appio_register_current[index];
}
return PAPI_OK;
}
| int _appio_update_control_state | ( | hwd_control_state_t * | ctl, |
| NativeInfo_t * | native, | ||
| int | count, | ||
| hwd_context_t * | ctx | ||
| ) |
Definition at line 474 of file appio.c.
{
( void ) ctx;
( void ) ctl;
SUBDBG("_appio_update_control_state ctx=%p ctl=%p num_events=%d\n", ctx, ctl, count);
int i, index;
APPIO_control_state_t *appio_ctl = (APPIO_control_state_t *) ctl;
(void) ctx;
for ( i = 0; i < count; i++ ) {
index = native[i].ni_event;
appio_ctl->counter_bits[i] = index;
native[i].ni_position = index;
}
appio_ctl->num_events = count;
return PAPI_OK;
}

| size_t _IO_fwrite | ( | const void * | ptr, |
| size_t | size, | ||
| size_t | nmemb, | ||
| FILE * | stream | ||
| ) |

| int close | ( | int | fd | ) |
Definition at line 209 of file appio.c.
{
size_t retval;
SUBDBG("appio: intercepted fread(%p,%lu,%lu,%p)\n", ptr, (unsigned long) size, (unsigned long) nmemb, (void*) stream);
long long start_ts = PAPI_get_real_usec();
retval = _IO_fread(ptr,size,nmemb,stream);
long long duration = PAPI_get_real_usec() - start_ts;
int n = _appio_register_current[READ_CALLS]++; // read calls
if (retval > 0) {
_appio_register_current[READ_BLOCK_SIZE]= (n * _appio_register_current[READ_BLOCK_SIZE]+ size*nmemb)/(n+1);//mean size
_appio_register_current[READ_BYTES]+= retval * size; // read bytes
if (retval < nmemb) _appio_register_current[READ_SHORT]++; // read short
_appio_register_current[READ_USEC] += duration;
}
/* A value of zero returned means one of two things..*/
if (retval == 0) {
if (feof(stream)) _appio_register_current[READ_EOF]++; // read eof
else _appio_register_current[READ_ERR]++; // read err
}
return retval;
}


Definition at line 298 of file appio.c.
{
size_t retval;
SUBDBG("appio: intercepted fwrite(%p,%lu,%lu,%p)\n", ptr, (unsigned long) size, (unsigned long) nmemb, (void*) stream);
long long start_ts = PAPI_get_real_usec();
retval = _IO_fwrite(ptr,size,nmemb,stream);
long long duration = PAPI_get_real_usec() - start_ts;
int n = _appio_register_current[WRITE_CALLS]++; // write calls
if (retval > 0) {
_appio_register_current[WRITE_BLOCK_SIZE]= (n * _appio_register_current[WRITE_BLOCK_SIZE] + size*nmemb)/(n+1); // mean block size
_appio_register_current[WRITE_BYTES]+= retval * size; // write bytes
if (retval < nmemb) _appio_register_current[WRITE_SHORT]++; // short write
_appio_register_current[WRITE_USEC] += duration;
}
if (retval == 0) _appio_register_current[WRITE_ERR]++; // err
return retval;
}


| int open | ( | const char * | pathname, |
| int | flags, | ||
| mode_t | mode | ||
| ) |
Definition at line 149 of file appio.c.
{
int retval;
SUBDBG("appio: intercepted open(%s,%d,%d)\n", pathname, flags, mode);
retval = __open(pathname,flags,mode);
_appio_register_current[OPEN_CALLS]++;
if (retval < 0) _appio_register_current[OPEN_ERR]++;
else _appio_register_current[OPEN_FDS]++;
return retval;
}


Definition at line 176 of file appio.c.
{
int retval;
SUBDBG("appio: intercepted read(%d,%p,%lu)\n", fd, buf, (unsigned long)count);
// check if read would block on descriptor
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
int ready = __select(fd+1, &readfds, NULL, NULL, &zerotv);
if (ready == 0) _appio_register_current[READ_WOULD_BLOCK]++;
long long start_ts = PAPI_get_real_usec();
retval = __read(fd,buf, count);
long long duration = PAPI_get_real_usec() - start_ts;
int n = _appio_register_current[READ_CALLS]++; // read calls
if (retval > 0) {
_appio_register_current[READ_BLOCK_SIZE]= (n * _appio_register_current[READ_BLOCK_SIZE] + count)/(n+1); // mean size
_appio_register_current[READ_BYTES] += retval; // read bytes
if (retval < (int)count) _appio_register_current[READ_SHORT]++; // read short
_appio_register_current[READ_USEC] += duration;
}
if (retval < 0) {
_appio_register_current[READ_ERR]++; // read err
if (EINTR == errno)
_appio_register_current[READ_INTERRUPTED]++; // signal interrupted the read
if ((EAGAIN == errno) || (EWOULDBLOCK == errno))
_appio_register_current[READ_WOULD_BLOCK]++; //read would block on descriptor marked as non-blocking
}
if (retval == 0) _appio_register_current[READ_EOF]++; // read eof
return retval;
}


| int select | ( | int | nfds, |
| fd_set * | readfds, | ||
| fd_set * | writefds, | ||
| fd_set * | exceptfds, | ||
| struct timeval * | timeout | ||
| ) |
Definition at line 164 of file appio.c.
{
int retval;
SUBDBG("appio: intercepted select(%d,%p,%p,%p,%p)\n", nfds,readfds,writefds,exceptfds,timeout);
long long start_ts = PAPI_get_real_usec();
retval = __select(nfds,readfds,writefds,exceptfds,timeout);
long long duration = PAPI_get_real_usec() - start_ts;
_appio_register_current[SELECT_USEC] += duration;
return retval;
}


Definition at line 232 of file appio.c.
{
int retval;
SUBDBG("appio: intercepted write(%d,%p,%lu)\n", fd, buf, (unsigned long)count);
// check if write would block on descriptor
fd_set writefds;
FD_ZERO(&writefds);
FD_SET(fd, &writefds);
int ready = __select(fd+1, NULL, &writefds, NULL, &zerotv);
if (ready == 0) _appio_register_current[WRITE_WOULD_BLOCK]++;
long long start_ts = PAPI_get_real_usec();
retval = __write(fd,buf, count);
long long duration = PAPI_get_real_usec() - start_ts;
int n = _appio_register_current[WRITE_CALLS]++; // write calls
if (retval >= 0) {
_appio_register_current[WRITE_BLOCK_SIZE]= (n * _appio_register_current[WRITE_BLOCK_SIZE] + count)/(n+1); // mean size
_appio_register_current[WRITE_BYTES]+= retval; // write bytes
if (retval < (int)count) _appio_register_current[WRITE_SHORT]++; // short write
_appio_register_current[WRITE_USEC] += duration;
}
if (retval < 0) _appio_register_current[WRITE_ERR]++; // err
return retval;
}


struct appio_counters _appio_counter_info[ 29 ] [static] |
__thread long long _appio_register_current[29] [static] |
| int errno |