PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux-memory.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int _linux_get_dmem_info (PAPI_dmem_info_t *d)
 
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:497
long long heap
Definition: papi.h:879
fclose(thread_wqfd)
long long ret
Definition: iozone.c:1346
long long resident
Definition: papi.h:874
long long pagesize
Definition: papi.h:882
#define PAPI_ESYS
Definition: papi.h:255
long long locked
Definition: papi.h:880
void PAPIERROR(char *format,...)
long long library
Definition: papi.h:878
long long shared
Definition: papi.h:876
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
#define PATH_MAX
Definition: fileop.c:68
long long text
Definition: papi.h:877
long long stack
Definition: papi.h:881
long long tmp
Definition: iozone.c:12031
long long size
Definition: papi.h:873
long long high_water_mark
Definition: papi.h:875
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 1110 of file linux-memory.c.

1111 {
1112  ( void ) cpu_type; /*unused */
1113  int retval = PAPI_OK;
1114 
1115 #if defined(__i386__)||defined(__x86_64__)
1116  x86_get_memory_info( hwinfo );
1117 #elif defined(__ia64__)
1118  ia64_get_memory_info( hwinfo );
1119 #elif defined(__powerpc__)
1120  ppc64_get_memory_info( hwinfo );
1121 #elif defined(__sparc__)
1122  sparc_get_memory_info( hwinfo );
1123 #elif defined(__arm__)
1124  #warning "WARNING! linux_get_memory_info() does nothing on ARM32!"
1125  generic_get_memory_info (hwinfo);
1126 #else
1127  generic_get_memory_info (hwinfo);
1128 #endif
1129 
1130  return retval;
1131 }
return PAPI_OK
Definition: linux-nvml.c:497
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 1134 of file linux-memory.c.

1135 {
1136 
1137  char fname[PAPI_HUGE_STR_LEN];
1138  unsigned long t_index = 0, d_index = 0, b_index = 0, counting = 1;
1139  char buf[PAPI_HUGE_STR_LEN + PAPI_HUGE_STR_LEN], perm[5], dev[16];
1140  char mapname[PAPI_HUGE_STR_LEN], lastmapname[PAPI_HUGE_STR_LEN];
1141  unsigned long begin = 0, end = 0, size = 0, inode = 0, foo = 0;
1142  PAPI_address_map_t *tmp = NULL;
1143  FILE *f;
1144 
1145  memset( fname, 0x0, sizeof ( fname ) );
1146  memset( buf, 0x0, sizeof ( buf ) );
1147  memset( perm, 0x0, sizeof ( perm ) );
1148  memset( dev, 0x0, sizeof ( dev ) );
1149  memset( mapname, 0x0, sizeof ( mapname ) );
1150  memset( lastmapname, 0x0, sizeof ( lastmapname ) );
1151 
1152  sprintf( fname, "/proc/%ld/maps", ( long ) mdi->pid );
1153  f = fopen( fname, "r" );
1154 
1155  if ( !f ) {
1156  PAPIERROR( "fopen(%s) returned < 0", fname );
1157  return PAPI_OK;
1158  }
1159 
1160  again:
1161  while ( !feof( f ) ) {
1162  begin = end = size = inode = foo = 0;
1163  if ( fgets( buf, sizeof ( buf ), f ) == 0 )
1164  break;
1165  /* If mapname is null in the string to be scanned, we need to detect that */
1166  if ( strlen( mapname ) )
1167  strcpy( lastmapname, mapname );
1168  else
1169  lastmapname[0] = '\0';
1170  /* If mapname is null in the string to be scanned, we need to detect that */
1171  mapname[0] = '\0';
1172  sscanf( buf, "%lx-%lx %4s %lx %s %ld %s", &begin, &end, perm, &foo, dev,
1173  &inode, mapname );
1174  size = end - begin;
1175 
1176  /* the permission string looks like "rwxp", where each character can
1177  * be either the letter, or a hyphen. The final character is either
1178  * p for private or s for shared. */
1179 
1180  if ( counting ) {
1181  if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
1182  if ( strcmp( mdi->exe_info.fullname, mapname )
1183  == 0 ) {
1185  ( caddr_t ) begin;
1187  ( caddr_t ) ( begin + size );
1188  }
1189  t_index++;
1190  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1191  ( inode != 0 )
1192  &&
1193  ( strcmp
1194  ( mdi->exe_info.fullname,
1195  mapname ) == 0 ) ) {
1197  ( caddr_t ) begin;
1199  ( caddr_t ) ( begin + size );
1200  d_index++;
1201  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1202  ( inode == 0 )
1203  &&
1204  ( strcmp
1205  ( mdi->exe_info.fullname,
1206  lastmapname ) == 0 ) ) {
1208  ( caddr_t ) begin;
1210  ( caddr_t ) ( begin + size );
1211  b_index++;
1212  }
1213  } else if ( !counting ) {
1214  if ( ( perm[2] == 'x' ) && ( perm[0] == 'r' ) && ( inode != 0 ) ) {
1215  if ( strcmp( mdi->exe_info.fullname, mapname )
1216  != 0 ) {
1217  t_index++;
1218  tmp[t_index - 1].text_start = ( caddr_t ) begin;
1219  tmp[t_index - 1].text_end = ( caddr_t ) ( begin + size );
1220  strncpy( tmp[t_index - 1].name, mapname, PAPI_MAX_STR_LEN );
1221  }
1222  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1223  ( inode != 0 ) ) {
1224  if ( ( strcmp
1225  ( mdi->exe_info.fullname,
1226  mapname ) != 0 )
1227  && ( t_index > 0 ) &&
1228  ( tmp[t_index - 1].data_start == 0 ) ) {
1229  tmp[t_index - 1].data_start = ( caddr_t ) begin;
1230  tmp[t_index - 1].data_end = ( caddr_t ) ( begin + size );
1231  }
1232  } else if ( ( perm[0] == 'r' ) && ( perm[1] == 'w' ) &&
1233  ( inode == 0 ) ) {
1234  if ( ( t_index > 0 ) && ( tmp[t_index - 1].bss_start == 0 ) ) {
1235  tmp[t_index - 1].bss_start = ( caddr_t ) begin;
1236  tmp[t_index - 1].bss_end = ( caddr_t ) ( begin + size );
1237  }
1238  }
1239  }
1240  }
1241 
1242  if ( counting ) {
1243  /* When we get here, we have counted the number of entries in the map
1244  for us to allocate */
1245 
1246  tmp =
1247  ( PAPI_address_map_t * ) papi_calloc( t_index,
1248  sizeof
1249  ( PAPI_address_map_t ) );
1250  if ( tmp == NULL ) {
1251  PAPIERROR( "Error allocating shared library address map" );
1252  fclose(f);
1253  return PAPI_ENOMEM;
1254  }
1255  t_index = 0;
1256  rewind( f );
1257  counting = 0;
1258  goto again;
1259  } else {
1260  if ( mdi->shlib_info.map )
1261  papi_free( mdi->shlib_info.map );
1262  mdi->shlib_info.map = tmp;
1263  mdi->shlib_info.count = t_index;
1264 
1265  fclose( f );
1266  }
1267 
1268  return PAPI_OK;
1269 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
double f(double a)
Definition: cpi.c:23
#define papi_free(a)
Definition: papi_memory.h:35
caddr_t text_end
Definition: papi.h:698
return PAPI_OK
Definition: linux-nvml.c:497
caddr_t bss_start
Definition: papi.h:701
PAPI_exe_info_t exe_info
fclose(thread_wqfd)
#define PAPI_HUGE_STR_LEN
Definition: papi.h:467
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:697
PAPI_address_map_t address_info
Definition: papi.h:709
pthread_attr_t foo
Definition: iozone.c:18592
get the executable&#39;s address space info
Definition: papi.h:695
void PAPIERROR(char *format,...)
#define PAPI_ENOMEM
Definition: papi.h:254
strcpy(filename, default_filename)
caddr_t data_start
Definition: papi.h:699
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
char * name
Definition: iozone.c:23648
PAPI_address_map_t * map
Definition: papi.h:714
caddr_t bss_end
Definition: papi.h:702
caddr_t data_end
Definition: papi.h:700
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
char fullname[PAPI_HUGE_STR_LEN]
Definition: papi.h:708
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: