|
PAPI
5.0.1.0
|

Go to the source code of this file.
Functions | |
| int | _linux_get_dmem_info (PAPI_dmem_info_t *d) |
| int | generic_get_memory_info (PAPI_hw_info_t *hw_info) |
| int | _linux_get_memory_info (PAPI_hw_info_t *hwinfo, int cpu_type) |
| int | _linux_update_shlib_info (papi_mdi_t *mdi) |
| int _linux_get_dmem_info | ( | PAPI_dmem_info_t * | d | ) |
< A System/C library call failed
< A System/C library call failed
< A System/C library call failed
< No error
Definition at line 45 of file linux-memory.c.
{
char fn[PATH_MAX], tmp[PATH_MAX];
FILE *f;
int ret;
long long sz = 0, lck = 0, res = 0, shr = 0, stk = 0, txt = 0, dat =
0, dum = 0, lib = 0, hwm = 0;
sprintf( fn, "/proc/%ld/status", ( long ) getpid( ) );
f = fopen( fn, "r" );
if ( f == NULL ) {
PAPIERROR( "fopen(%s): %s\n", fn, strerror( errno ) );
return PAPI_ESYS;
}
while ( 1 ) {
if ( fgets( tmp, PATH_MAX, f ) == NULL )
break;
if ( strspn( tmp, "VmSize:" ) == strlen( "VmSize:" ) ) {
sscanf( tmp + strlen( "VmSize:" ), "%lld", &sz );
d->size = sz;
continue;
}
if ( strspn( tmp, "VmHWM:" ) == strlen( "VmHWM:" ) ) {
sscanf( tmp + strlen( "VmHWM:" ), "%lld", &hwm );
d->high_water_mark = hwm;
continue;
}
if ( strspn( tmp, "VmLck:" ) == strlen( "VmLck:" ) ) {
sscanf( tmp + strlen( "VmLck:" ), "%lld", &lck );
d->locked = lck;
continue;
}
if ( strspn( tmp, "VmRSS:" ) == strlen( "VmRSS:" ) ) {
sscanf( tmp + strlen( "VmRSS:" ), "%lld", &res );
d->resident = res;
continue;
}
if ( strspn( tmp, "VmData:" ) == strlen( "VmData:" ) ) {
sscanf( tmp + strlen( "VmData:" ), "%lld", &dat );
d->heap = dat;
continue;
}
if ( strspn( tmp, "VmStk:" ) == strlen( "VmStk:" ) ) {
sscanf( tmp + strlen( "VmStk:" ), "%lld", &stk );
d->stack = stk;
continue;
}
if ( strspn( tmp, "VmExe:" ) == strlen( "VmExe:" ) ) {
sscanf( tmp + strlen( "VmExe:" ), "%lld", &txt );
d->text = txt;
continue;
}
if ( strspn( tmp, "VmLib:" ) == strlen( "VmLib:" ) ) {
sscanf( tmp + strlen( "VmLib:" ), "%lld", &lib );
d->library = lib;
continue;
}
}
fclose( f );
sprintf( fn, "/proc/%ld/statm", ( long ) getpid( ) );
f = fopen( fn, "r" );
if ( f == NULL ) {
PAPIERROR( "fopen(%s): %s\n", fn, strerror( errno ) );
return PAPI_ESYS;
}
ret =
fscanf( f, "%lld %lld %lld %lld %lld %lld %lld", &dum, &dum, &shr, &dum,
&dum, &dat, &dum );
if ( ret != 7 ) {
PAPIERROR( "fscanf(7 items): %d\n", ret );
fclose(f);
return PAPI_ESYS;
}
d->pagesize = getpagesize( );
d->shared = ( shr * d->pagesize ) / 1024;
fclose( f );
return PAPI_OK;
}

| int _linux_get_memory_info | ( | PAPI_hw_info_t * | hwinfo, |
| int | cpu_type | ||
| ) |
< No error
Definition at line 835 of file linux-memory.c.
{
( void ) cpu_type; /*unused */
int retval = PAPI_OK;
#if defined(__i386__)||defined(__x86_64__)
x86_get_memory_info( hwinfo );
#elif defined(__ia64__)
ia64_get_memory_info( hwinfo );
#elif defined(__powerpc__)
ppc64_get_memory_info( hwinfo );
#elif defined(__sparc__)
sparc_get_memory_info( hwinfo );
#elif defined(__arm__)
#warning "WARNING! linux_get_memory_info() does nothing on ARM!"
generic_get_memory_info (hwinfo);
#else
generic_get_memory_info (hwinfo);
#endif
return retval;
}


| int _linux_update_shlib_info | ( | papi_mdi_t * | mdi | ) |
< No error
< Insufficient memory
< No error
Definition at line 859 of file linux-memory.c.
{
char fname[PAPI_HUGE_STR_LEN];
unsigned long t_index = 0, d_index = 0, b_index = 0, counting = 1;
char buf[PAPI_HUGE_STR_LEN + PAPI_HUGE_STR_LEN], perm[5], dev[16];
char mapname[PAPI_HUGE_STR_LEN], lastmapname[PAPI_HUGE_STR_LEN];
unsigned long begin = 0, end = 0, size = 0, inode = 0, foo = 0;
PAPI_address_map_t *tmp = NULL;
FILE *f;
memset( fname, 0x0, sizeof ( fname ) );
memset( buf, 0x0, sizeof ( buf ) );
memset( perm, 0x0, sizeof ( perm ) );
memset( dev, 0x0, sizeof ( dev ) );
memset( mapname, 0x0, sizeof ( mapname ) );
memset( lastmapname, 0x0, sizeof ( lastmapname ) );
sprintf( fname, "/proc/%ld/maps", ( long ) mdi->pid );
f = fopen( fname, "r" );
if ( !f ) {
PAPIERROR( "fopen(%s) returned < 0", fname );
return PAPI_OK;
}
again:
while ( !feof( f ) ) {
begin = end = size = inode = foo = 0;
if ( fgets( buf, sizeof ( buf ), f ) == 0 )
break;
/* If mapname is null in the string to be scanned, we need to detect that */
if ( strlen( mapname ) )
strcpy( lastmapname, mapname );
else
lastmapname[0] = '\0';
/* If mapname is null in the string to be scanned, we need to detect that */
mapname[0] = '\0';
sscanf( buf, "%lx-%lx %4s %lx %s %ld %s", &begin, &end, perm, &foo, dev,
&inode, mapname );
size = end - begin;
/* the permission string looks like "rwxp", where each character can
* be either the letter, or a hyphen. The final character is either
* p for private or s for shared. */
if ( counting ) {
if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
if ( strcmp( mdi->exe_info.fullname, mapname )
== 0 ) {
mdi->exe_info.address_info.text_start =
( caddr_t ) begin;
mdi->exe_info.address_info.text_end =
( caddr_t ) ( begin + size );
}
t_index++;
} else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
( inode != 0 )
&&
( strcmp
( mdi->exe_info.fullname,
mapname ) == 0 ) ) {
mdi->exe_info.address_info.data_start =
( caddr_t ) begin;
mdi->exe_info.address_info.data_end =
( caddr_t ) ( begin + size );
d_index++;
} else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
( inode == 0 )
&&
( strcmp
( mdi->exe_info.fullname,
lastmapname ) == 0 ) ) {
mdi->exe_info.address_info.bss_start =
( caddr_t ) begin;
mdi->exe_info.address_info.bss_end =
( caddr_t ) ( begin + size );
b_index++;
}
} else if ( !counting ) {
if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
if ( strcmp( mdi->exe_info.fullname, mapname )
!= 0 ) {
t_index++;
tmp[t_index - 1].text_start = ( caddr_t ) begin;
tmp[t_index - 1].text_end = ( caddr_t ) ( begin + size );
strncpy( tmp[t_index - 1].name, mapname, PAPI_MAX_STR_LEN );
}
} else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
( inode != 0 ) ) {
if ( ( strcmp
( mdi->exe_info.fullname,
mapname ) != 0 )
&& ( t_index > 0 ) &&
( tmp[t_index - 1].data_start == 0 ) ) {
tmp[t_index - 1].data_start = ( caddr_t ) begin;
tmp[t_index - 1].data_end = ( caddr_t ) ( begin + size );
}
} else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
( inode == 0 ) ) {
if ( ( t_index > 0 ) && ( tmp[t_index - 1].bss_start == 0 ) ) {
tmp[t_index - 1].bss_start = ( caddr_t ) begin;
tmp[t_index - 1].bss_end = ( caddr_t ) ( begin + size );
}
}
}
}
if ( counting ) {
/* When we get here, we have counted the number of entries in the map
for us to allocate */
tmp =
( PAPI_address_map_t * ) papi_calloc( t_index,
sizeof
( PAPI_address_map_t ) );
if ( tmp == NULL ) {
PAPIERROR( "Error allocating shared library address map" );
fclose(f);
return PAPI_ENOMEM;
}
t_index = 0;
rewind( f );
counting = 0;
goto again;
} else {
if ( mdi->shlib_info.map )
papi_free( mdi->shlib_info.map );
mdi->shlib_info.map = tmp;
mdi->shlib_info.count = t_index;
fclose( f );
}
return PAPI_OK;
}


| int generic_get_memory_info | ( | PAPI_hw_info_t * | hw_info | ) |
Definition at line 823 of file linux-memory.c.
{
/* Now fetch the cache info */
hw_info->mem_hierarchy.levels = 0;
return 0;
}
