linux-memory.c File Reference

Include dependency graph for linux-memory.c:

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)

Function Documentation

int _linux_get_dmem_info ( PAPI_dmem_info_t d  ) 

Definition at line 48 of file linux-memory.c.

00049 {
00050     char fn[PATH_MAX], tmp[PATH_MAX];
00051     FILE *f;
00052     int ret;
00053     long long sz = 0, lck = 0, res = 0, shr = 0, stk = 0, txt = 0, dat =
00054         0, dum = 0, lib = 0, hwm = 0;
00055 
00056     sprintf( fn, "/proc/%ld/status", ( long ) getpid(  ) );
00057     f = fopen( fn, "r" );
00058     if ( f == NULL ) {
00059         PAPIERROR( "fopen(%s): %s\n", fn, strerror( errno ) );
00060         return PAPI_ESYS;
00061     }
00062     while ( 1 ) {
00063         if ( fgets( tmp, PATH_MAX, f ) == NULL )
00064             break;
00065         if ( strspn( tmp, "VmSize:" ) == strlen( "VmSize:" ) ) {
00066             sscanf( tmp + strlen( "VmSize:" ), "%lld", &sz );
00067             d->size = sz;
00068             continue;
00069         }
00070         if ( strspn( tmp, "VmHWM:" ) == strlen( "VmHWM:" ) ) {
00071             sscanf( tmp + strlen( "VmHWM:" ), "%lld", &hwm );
00072             d->high_water_mark = hwm;
00073             continue;
00074         }
00075         if ( strspn( tmp, "VmLck:" ) == strlen( "VmLck:" ) ) {
00076             sscanf( tmp + strlen( "VmLck:" ), "%lld", &lck );
00077             d->locked = lck;
00078             continue;
00079         }
00080         if ( strspn( tmp, "VmRSS:" ) == strlen( "VmRSS:" ) ) {
00081             sscanf( tmp + strlen( "VmRSS:" ), "%lld", &res );
00082             d->resident = res;
00083             continue;
00084         }
00085         if ( strspn( tmp, "VmData:" ) == strlen( "VmData:" ) ) {
00086             sscanf( tmp + strlen( "VmData:" ), "%lld", &dat );
00087             d->heap = dat;
00088             continue;
00089         }
00090         if ( strspn( tmp, "VmStk:" ) == strlen( "VmStk:" ) ) {
00091             sscanf( tmp + strlen( "VmStk:" ), "%lld", &stk );
00092             d->stack = stk;
00093             continue;
00094         }
00095         if ( strspn( tmp, "VmExe:" ) == strlen( "VmExe:" ) ) {
00096             sscanf( tmp + strlen( "VmExe:" ), "%lld", &txt );
00097             d->text = txt;
00098             continue;
00099         }
00100         if ( strspn( tmp, "VmLib:" ) == strlen( "VmLib:" ) ) {
00101             sscanf( tmp + strlen( "VmLib:" ), "%lld", &lib );
00102             d->library = lib;
00103             continue;
00104         }
00105     }
00106     fclose( f );
00107 
00108     sprintf( fn, "/proc/%ld/statm", ( long ) getpid(  ) );
00109     f = fopen( fn, "r" );
00110     if ( f == NULL ) {
00111         PAPIERROR( "fopen(%s): %s\n", fn, strerror( errno ) );
00112         return PAPI_ESYS;
00113     }
00114     ret =
00115         fscanf( f, "%lld %lld %lld %lld %lld %lld %lld", &dum, &dum, &shr, &dum,
00116                 &dum, &dat, &dum );
00117     if ( ret != 7 ) {
00118         PAPIERROR( "fscanf(7 items): %d\n", ret );
00119         fclose(f);
00120         return PAPI_ESYS;
00121     }
00122     d->pagesize = getpagesize(  );
00123     d->shared = ( shr * d->pagesize ) / 1024;
00124     fclose( f );
00125 
00126     return PAPI_OK;
00127 }

Here is the call graph for this function:

int _linux_get_memory_info ( PAPI_hw_info_t hwinfo,
int  cpu_type 
)

Definition at line 912 of file linux-memory.c.

00913 {
00914     ( void ) cpu_type;       /*unused */
00915     int retval = PAPI_OK;
00916 
00917 #if defined(__i386__)||defined(__x86_64__)
00918     x86_get_memory_info( hwinfo );
00919 #elif defined(__ia64__)
00920     ia64_get_memory_info( hwinfo );
00921 #elif defined(__powerpc__)
00922     ppc64_get_memory_info( hwinfo );
00923 #elif defined(__sparc__)
00924     sparc_get_memory_info( hwinfo );
00925 #elif defined(__arm__)
00926     #warning "WARNING! linux_get_memory_info() does nothing on ARM!"
00927         generic_get_memory_info (hwinfo);
00928 #else
00929         generic_get_memory_info (hwinfo);
00930 #endif
00931 
00932     return retval;
00933 }

Here is the call graph for this function:

Here is the caller graph for this function:

int _linux_update_shlib_info ( papi_mdi_t mdi  ) 

Definition at line 936 of file linux-memory.c.

00937 {
00938 
00939     char fname[PAPI_HUGE_STR_LEN];
00940     unsigned long t_index = 0, d_index = 0, b_index = 0, counting = 1;
00941     char buf[PAPI_HUGE_STR_LEN + PAPI_HUGE_STR_LEN], perm[5], dev[16];
00942     char mapname[PAPI_HUGE_STR_LEN], lastmapname[PAPI_HUGE_STR_LEN];
00943     unsigned long begin = 0, end = 0, size = 0, inode = 0, foo = 0;
00944     PAPI_address_map_t *tmp = NULL;
00945     FILE *f;
00946 
00947     memset( fname, 0x0, sizeof ( fname ) );
00948     memset( buf, 0x0, sizeof ( buf ) );
00949     memset( perm, 0x0, sizeof ( perm ) );
00950     memset( dev, 0x0, sizeof ( dev ) );
00951     memset( mapname, 0x0, sizeof ( mapname ) );
00952     memset( lastmapname, 0x0, sizeof ( lastmapname ) );
00953 
00954     sprintf( fname, "/proc/%ld/maps", ( long ) mdi->pid );
00955     f = fopen( fname, "r" );
00956 
00957     if ( !f ) {
00958         PAPIERROR( "fopen(%s) returned < 0", fname );
00959         return PAPI_OK;
00960     }
00961 
00962   again:
00963     while ( !feof( f ) ) {
00964         begin = end = size = inode = foo = 0;
00965         if ( fgets( buf, sizeof ( buf ), f ) == 0 )
00966             break;
00967         /* If mapname is null in the string to be scanned, we need to detect that */
00968         if ( strlen( mapname ) )
00969             strcpy( lastmapname, mapname );
00970         else
00971             lastmapname[0] = '\0';
00972         /* If mapname is null in the string to be scanned, we need to detect that */
00973         mapname[0] = '\0';
00974         sscanf( buf, "%lx-%lx %4s %lx %s %ld %s", &begin, &end, perm, &foo, dev,
00975                 &inode, mapname );
00976         size = end - begin;
00977 
00978         /* the permission string looks like "rwxp", where each character can
00979          * be either the letter, or a hyphen.  The final character is either
00980          * p for private or s for shared. */
00981 
00982         if ( counting ) {
00983             if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
00984                 if ( strcmp( mdi->exe_info.fullname, mapname )
00985                      == 0 ) {
00986                     mdi->exe_info.address_info.text_start =
00987                         ( caddr_t ) begin;
00988                     mdi->exe_info.address_info.text_end =
00989                         ( caddr_t ) ( begin + size );
00990                 }
00991                 t_index++;
00992             } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
00993                         ( inode != 0 )
00994                         &&
00995                         ( strcmp
00996                           ( mdi->exe_info.fullname,
00997                             mapname ) == 0 ) ) {
00998                 mdi->exe_info.address_info.data_start =
00999                     ( caddr_t ) begin;
01000                 mdi->exe_info.address_info.data_end =
01001                     ( caddr_t ) ( begin + size );
01002                 d_index++;
01003             } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
01004                         ( inode == 0 )
01005                         &&
01006                         ( strcmp
01007                           ( mdi->exe_info.fullname,
01008                             lastmapname ) == 0 ) ) {
01009                 mdi->exe_info.address_info.bss_start =
01010                     ( caddr_t ) begin;
01011                 mdi->exe_info.address_info.bss_end =
01012                     ( caddr_t ) ( begin + size );
01013                 b_index++;
01014             }
01015         } else if ( !counting ) {
01016             if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
01017                 if ( strcmp( mdi->exe_info.fullname, mapname )
01018                      != 0 ) {
01019                     t_index++;
01020                     tmp[t_index - 1].text_start = ( caddr_t ) begin;
01021                     tmp[t_index - 1].text_end = ( caddr_t ) ( begin + size );
01022                     strncpy( tmp[t_index - 1].name, mapname, PAPI_MAX_STR_LEN );
01023                 }
01024             } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
01025                         ( inode != 0 ) ) {
01026                 if ( ( strcmp
01027                        ( mdi->exe_info.fullname,
01028                          mapname ) != 0 )
01029                      && ( t_index > 0 ) &&
01030                      ( tmp[t_index - 1].data_start == 0 ) ) {
01031                     tmp[t_index - 1].data_start = ( caddr_t ) begin;
01032                     tmp[t_index - 1].data_end = ( caddr_t ) ( begin + size );
01033                 }
01034             } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
01035                         ( inode == 0 ) ) {
01036                 if ( ( t_index > 0 ) && ( tmp[t_index - 1].bss_start == 0 ) ) {
01037                     tmp[t_index - 1].bss_start = ( caddr_t ) begin;
01038                     tmp[t_index - 1].bss_end = ( caddr_t ) ( begin + size );
01039                 }
01040             }
01041         }
01042     }
01043 
01044     if ( counting ) {
01045         /* When we get here, we have counted the number of entries in the map
01046            for us to allocate */
01047 
01048         tmp =
01049             ( PAPI_address_map_t * ) papi_calloc( t_index,
01050                                                   sizeof
01051                                                   ( PAPI_address_map_t ) );
01052         if ( tmp == NULL ) {
01053             PAPIERROR( "Error allocating shared library address map" );
01054             fclose(f);
01055             return PAPI_ENOMEM;
01056         }
01057         t_index = 0;
01058         rewind( f );
01059         counting = 0;
01060         goto again;
01061     } else {
01062         if ( mdi->shlib_info.map )
01063             papi_free( mdi->shlib_info.map );
01064         mdi->shlib_info.map = tmp;
01065         mdi->shlib_info.count = t_index;
01066 
01067         fclose( f );
01068     }
01069 
01070     return PAPI_OK;
01071 }

Here is the call graph for this function:

Here is the caller graph for this function:

int generic_get_memory_info ( PAPI_hw_info_t hw_info  ) 

Definition at line 900 of file linux-memory.c.

00901 {
00902 
00903 
00904     /* Now fetch the cache info */
00905     hw_info->mem_hierarchy.levels = 0;
00906 
00907     return 0;
00908 }

Here is the caller graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1