PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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.

49 {
50  char fn[PATH_MAX], tmp[PATH_MAX];
51  FILE *f;
52  int ret;
53  long long sz = 0, lck = 0, res = 0, shr = 0, stk = 0, txt = 0, dat =
54  0, dum = 0, lib = 0, hwm = 0;
55 
56  sprintf( fn, "/proc/%ld/status", ( long ) getpid( ) );
57  f = fopen( fn, "r" );
58  if ( f == NULL ) {
59  PAPIERROR( "fopen(%s): %s\n", fn, strerror( errno ) );
60  return PAPI_ESYS;
61  }
62  while ( 1 ) {
63  if ( fgets( tmp, PATH_MAX, f ) == NULL )
64  break;
65  if ( strspn( tmp, "VmSize:" ) == strlen( "VmSize:" ) ) {
66  sscanf( tmp + strlen( "VmSize:" ), "%lld", &sz );
67  d->size = sz;
68  continue;
69  }
70  if ( strspn( tmp, "VmHWM:" ) == strlen( "VmHWM:" ) ) {
71  sscanf( tmp + strlen( "VmHWM:" ), "%lld", &hwm );
72  d->high_water_mark = hwm;
73  continue;
74  }
75  if ( strspn( tmp, "VmLck:" ) == strlen( "VmLck:" ) ) {
76  sscanf( tmp + strlen( "VmLck:" ), "%lld", &lck );
77  d->locked = lck;
78  continue;
79  }
80  if ( strspn( tmp, "VmRSS:" ) == strlen( "VmRSS:" ) ) {
81  sscanf( tmp + strlen( "VmRSS:" ), "%lld", &res );
82  d->resident = res;
83  continue;
84  }
85  if ( strspn( tmp, "VmData:" ) == strlen( "VmData:" ) ) {
86  sscanf( tmp + strlen( "VmData:" ), "%lld", &dat );
87  d->heap = dat;
88  continue;
89  }
90  if ( strspn( tmp, "VmStk:" ) == strlen( "VmStk:" ) ) {
91  sscanf( tmp + strlen( "VmStk:" ), "%lld", &stk );
92  d->stack = stk;
93  continue;
94  }
95  if ( strspn( tmp, "VmExe:" ) == strlen( "VmExe:" ) ) {
96  sscanf( tmp + strlen( "VmExe:" ), "%lld", &txt );
97  d->text = txt;
98  continue;
99  }
100  if ( strspn( tmp, "VmLib:" ) == strlen( "VmLib:" ) ) {
101  sscanf( tmp + strlen( "VmLib:" ), "%lld", &lib );
102  d->library = lib;
103  continue;
104  }
105  }
106  fclose( f );
107 
108  sprintf( fn, "/proc/%ld/statm", ( long ) getpid( ) );
109  f = fopen( fn, "r" );
110  if ( f == NULL ) {
111  PAPIERROR( "fopen(%s): %s\n", fn, strerror( errno ) );
112  return PAPI_ESYS;
113  }
114  ret =
115  fscanf( f, "%lld %lld %lld %lld %lld %lld %lld", &dum, &dum, &shr, &dum,
116  &dum, &dat, &dum );
117  if ( ret != 7 ) {
118  PAPIERROR( "fscanf(7 items): %d\n", ret );
119  fclose(f);
120  return PAPI_ESYS;
121  }
122  d->pagesize = getpagesize( );
123  d->shared = ( shr * d->pagesize ) / 1024;
124  fclose( f );
125 
126  return PAPI_OK;
127 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int errno
double f(double a)
Definition: cpi.c:23
return PAPI_OK
Definition: linux-nvml.c:458
long long heap
Definition: papi.h:876
fclose(thread_wqfd)
long long ret
Definition: iozone.c:1346
long long resident
Definition: papi.h:871
long long pagesize
Definition: papi.h:879
#define PAPI_ESYS
Definition: papi.h:253
long long locked
Definition: papi.h:877
void PAPIERROR(char *format,...)
long long library
Definition: papi.h:875
long long shared
Definition: papi.h:873
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
#define PATH_MAX
Definition: fileop.c:68
long long text
Definition: papi.h:874
long long stack
Definition: papi.h:878
long long tmp
Definition: iozone.c:12031
long long size
Definition: papi.h:870
long long high_water_mark
Definition: papi.h:872
int sz
Definition: fileop.c:80

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.

913 {
914  ( void ) cpu_type; /*unused */
915  int retval = PAPI_OK;
916 
917 #if defined(__i386__)||defined(__x86_64__)
918  x86_get_memory_info( hwinfo );
919 #elif defined(__ia64__)
920  ia64_get_memory_info( hwinfo );
921 #elif defined(__powerpc__)
922  ppc64_get_memory_info( hwinfo );
923 #elif defined(__sparc__)
924  sparc_get_memory_info( hwinfo );
925 #elif defined(__arm__)
926  #warning "WARNING! linux_get_memory_info() does nothing on ARM!"
927  generic_get_memory_info (hwinfo);
928 #else
929  generic_get_memory_info (hwinfo);
930 #endif
931 
932  return retval;
933 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int generic_get_memory_info(PAPI_hw_info_t *hw_info)
Definition: linux-memory.c:900
ssize_t retval
Definition: libasync.c:338

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.

937 {
938 
939  char fname[PAPI_HUGE_STR_LEN];
940  unsigned long t_index = 0, d_index = 0, b_index = 0, counting = 1;
941  char buf[PAPI_HUGE_STR_LEN + PAPI_HUGE_STR_LEN], perm[5], dev[16];
942  char mapname[PAPI_HUGE_STR_LEN], lastmapname[PAPI_HUGE_STR_LEN];
943  unsigned long begin = 0, end = 0, size = 0, inode = 0, foo = 0;
944  PAPI_address_map_t *tmp = NULL;
945  FILE *f;
946 
947  memset( fname, 0x0, sizeof ( fname ) );
948  memset( buf, 0x0, sizeof ( buf ) );
949  memset( perm, 0x0, sizeof ( perm ) );
950  memset( dev, 0x0, sizeof ( dev ) );
951  memset( mapname, 0x0, sizeof ( mapname ) );
952  memset( lastmapname, 0x0, sizeof ( lastmapname ) );
953 
954  sprintf( fname, "/proc/%ld/maps", ( long ) mdi->pid );
955  f = fopen( fname, "r" );
956 
957  if ( !f ) {
958  PAPIERROR( "fopen(%s) returned < 0", fname );
959  return PAPI_OK;
960  }
961 
962  again:
963  while ( !feof( f ) ) {
964  begin = end = size = inode = foo = 0;
965  if ( fgets( buf, sizeof ( buf ), f ) == 0 )
966  break;
967  /* If mapname is null in the string to be scanned, we need to detect that */
968  if ( strlen( mapname ) )
969  strcpy( lastmapname, mapname );
970  else
971  lastmapname[0] = '\0';
972  /* If mapname is null in the string to be scanned, we need to detect that */
973  mapname[0] = '\0';
974  sscanf( buf, "%lx-%lx %4s %lx %s %ld %s", &begin, &end, perm, &foo, dev,
975  &inode, mapname );
976  size = end - begin;
977 
978  /* the permission string looks like "rwxp", where each character can
979  * be either the letter, or a hyphen. The final character is either
980  * p for private or s for shared. */
981 
982  if ( counting ) {
983  if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
984  if ( strcmp( mdi->exe_info.fullname, mapname )
985  == 0 ) {
987  ( caddr_t ) begin;
989  ( caddr_t ) ( begin + size );
990  }
991  t_index++;
992  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
993  ( inode != 0 )
994  &&
995  ( strcmp
996  ( mdi->exe_info.fullname,
997  mapname ) == 0 ) ) {
999  ( caddr_t ) begin;
1001  ( caddr_t ) ( begin + size );
1002  d_index++;
1003  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1004  ( inode == 0 )
1005  &&
1006  ( strcmp
1007  ( mdi->exe_info.fullname,
1008  lastmapname ) == 0 ) ) {
1010  ( caddr_t ) begin;
1012  ( caddr_t ) ( begin + size );
1013  b_index++;
1014  }
1015  } else if ( !counting ) {
1016  if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
1017  if ( strcmp( mdi->exe_info.fullname, mapname )
1018  != 0 ) {
1019  t_index++;
1020  tmp[t_index - 1].text_start = ( caddr_t ) begin;
1021  tmp[t_index - 1].text_end = ( caddr_t ) ( begin + size );
1022  strncpy( tmp[t_index - 1].name, mapname, PAPI_MAX_STR_LEN );
1023  }
1024  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1025  ( inode != 0 ) ) {
1026  if ( ( strcmp
1027  ( mdi->exe_info.fullname,
1028  mapname ) != 0 )
1029  && ( t_index > 0 ) &&
1030  ( tmp[t_index - 1].data_start == 0 ) ) {
1031  tmp[t_index - 1].data_start = ( caddr_t ) begin;
1032  tmp[t_index - 1].data_end = ( caddr_t ) ( begin + size );
1033  }
1034  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1035  ( inode == 0 ) ) {
1036  if ( ( t_index > 0 ) && ( tmp[t_index - 1].bss_start == 0 ) ) {
1037  tmp[t_index - 1].bss_start = ( caddr_t ) begin;
1038  tmp[t_index - 1].bss_end = ( caddr_t ) ( begin + size );
1039  }
1040  }
1041  }
1042  }
1043 
1044  if ( counting ) {
1045  /* When we get here, we have counted the number of entries in the map
1046  for us to allocate */
1047 
1048  tmp =
1049  ( PAPI_address_map_t * ) papi_calloc( t_index,
1050  sizeof
1051  ( PAPI_address_map_t ) );
1052  if ( tmp == NULL ) {
1053  PAPIERROR( "Error allocating shared library address map" );
1054  fclose(f);
1055  return PAPI_ENOMEM;
1056  }
1057  t_index = 0;
1058  rewind( f );
1059  counting = 0;
1060  goto again;
1061  } else {
1062  if ( mdi->shlib_info.map )
1063  papi_free( mdi->shlib_info.map );
1064  mdi->shlib_info.map = tmp;
1065  mdi->shlib_info.count = t_index;
1066 
1067  fclose( f );
1068  }
1069 
1070  return PAPI_OK;
1071 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
memset(eventId, 0, size)
double f(double a)
Definition: cpi.c:23
#define papi_free(a)
Definition: papi_memory.h:35
caddr_t text_end
Definition: papi.h:695
return PAPI_OK
Definition: linux-nvml.c:458
caddr_t bss_start
Definition: papi.h:698
PAPI_exe_info_t exe_info
fclose(thread_wqfd)
#define PAPI_HUGE_STR_LEN
Definition: papi.h:465
PAPI_shlib_info_t shlib_info
char buf[200]
Definition: iozone.c:19609
char *long long size
Definition: iozone.c:12023
caddr_t text_start
Definition: papi.h:694
PAPI_address_map_t address_info
Definition: papi.h:706
pthread_attr_t foo
Definition: iozone.c:18592
get the executable&#39;s address space info
Definition: papi.h:692
void PAPIERROR(char *format,...)
#define PAPI_ENOMEM
Definition: papi.h:252
strcpy(filename, default_filename)
caddr_t data_start
Definition: papi.h:696
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
char * name
Definition: iozone.c:23648
PAPI_address_map_t * map
Definition: papi.h:711
caddr_t bss_end
Definition: papi.h:699
caddr_t data_end
Definition: papi.h:697
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
char fullname[PAPI_HUGE_STR_LEN]
Definition: papi.h:705
long long tmp
Definition: iozone.c:12031
rewind(w_traj_fd)
#define papi_calloc(a, b)
Definition: papi_memory.h:37
void begin()

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.

901 {
902 
903 
904  /* Now fetch the cache info */
905  hw_info->mem_hierarchy.levels = 0;
906 
907  return 0;
908 }
int levels
Definition: papi.h:771
PAPI_mh_info_t mem_hierarchy
Definition: papi.h:796

Here is the caller graph for this function: