Skip to content

Instantly share code, notes, and snippets.

@gchavez2
Last active October 30, 2017 23:57
Show Gist options
  • Save gchavez2/0e9259e810f644acb1418dc5137a3155 to your computer and use it in GitHub Desktop.
Save gchavez2/0e9259e810f644acb1418dc5137a3155 to your computer and use it in GitHub Desktop.
Papi memory counters
#include <stdio.h>
#include <stdlib.h>
#include "papi.h"
#include <unistd.h>
static void
dump_memory_info_all( PAPI_dmem_info_t * d )
{
PAPI_get_dmem_info(d);
printf( "\n--------\n" );
printf( "Mem Size:\t\t%lld\n", d->size/1000 );
// printf( "Mem Peak Size:\t\t%lld\n", d->peak/1000 );
printf( "Mem Resident:\t\t%lld\n", d->resident/1000 );
printf( "Mem High Water Mark:\t%lld\n", d->high_water_mark/1000 );
// printf( "Mem High Water Mark:\t%1.2f\n", (double) d->high_water_mark/1000 );
printf( "Mem Shared:\t\t%lld\n", d->shared/1000 );
printf( "Mem Text:\t\t%lld\n", d->text/1000 );
printf( "Mem Library:\t\t%lld\n", d->library/1000 );
printf( "Mem Heap:\t\t%lld\n", d->heap/1000 );
printf( "Mem Locked:\t\t%lld\n", d->locked/1000 );
printf( "Mem Stack:\t\t%lld\n", d->stack/1000 );
printf( "Mem Pagesize:\t\t%lld\n", d->pagesize/1000 );
printf( "MemPage Tab.:\t\t%lld\n", d->pte/1000 );
printf( "--------\n\n" );
}
static void
dump_memory_info( PAPI_dmem_info_t * d )
{
PAPI_get_dmem_info(d);
printf( "\n--------\n" );
printf( "Mem Size (of the executable):\t\t%lld\n", d->size/1000 );
printf( "Mem Resident (with libs):\t\t%lld\n", d->resident/1000 );
printf( "Mem High Water Mark:\t%lld\n", d->high_water_mark/1000 );
printf( "Mem Heap(must be zero):\t\t%lld\n", d->heap/1000 );
printf( "--------\n\n" );
}
void
touch_dummy( double *array, int size )
{
int i;
double *tmp = array;
for ( i = 0; i < size; i++, tmp++ )
*tmp = ( double ) rand( );
}
// 10 MB
# define SIZE 10000000
int
main( int argc, char **argv )
{
int retval;
double *m1,*m2,*m3;
if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) exit(1);
PAPI_dmem_info_t dmem;
m1 = ( double * ) malloc( SIZE * sizeof ( double ) );
touch_dummy(m1, SIZE);
free(m1);
m2 = ( double * ) malloc( SIZE * sizeof ( double ) );
touch_dummy(m2, SIZE);
free(m2);
m3 = ( double * ) malloc( SIZE * sizeof ( double ) );
touch_dummy(m3, SIZE);
free(m3);
dump_memory_info( &dmem );
printf("Sleeping 25s...\n");
sleep(25);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment