Beispiel #1
0
static int
do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh,
	    int bucket, unsigned int mask ) {

	int i, retval;
	unsigned long blength;
	int num_buckets,j=0;

	int num_bufs = num_events;
	int event = num_events;

	int events[MAX_TEST_EVENTS];
	char header[BUFSIZ];

	strncpy(header,"address\t\t",BUFSIZ);

	//= "address\t\t\tcyc\tins\tfp_ins\n";

	for(i=0;i<MAX_TEST_EVENTS;i++) {
	  if (mask & test_events[i].mask) {
	    events[j]=test_events[i].event;

	    if (events[j]==PAPI_TOT_CYC) {
	       strncat(header,"\tcyc",BUFSIZ-1);
	    }
	    if (events[j]==PAPI_TOT_INS) {
	       strncat(header,"\tins",BUFSIZ-1);
	    }
	    if (events[j]==PAPI_FP_INS) {
	       strncat(header,"\tfp_ins",BUFSIZ-1);
	    }
	    if (events[j]==PAPI_FP_OPS) {
	       strncat(header,"\tfp_ops",BUFSIZ-1);
	    }
	    if (events[j]==PAPI_L2_TCM) {
	       strncat(header,"\tl2_tcm",BUFSIZ-1);
	    }

	    j++;

	  }
	}

	strncat(header,"\n",BUFSIZ-1);



	blength = prof_size( plength, scale, bucket, &num_buckets );
	prof_alloc( num_bufs, blength );

	if ( !TESTS_QUIET )
		printf( "Overall event counts:\n" );

	for ( i = 0; i < num_events; i++ ) {
		if ( ( retval =
			   PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
							EventSet, events[i], thresh,
							PAPI_PROFIL_POSIX | bucket ) ) != PAPI_OK ) {
	           if (retval == PAPI_EINVAL) {
		      test_warn( __FILE__, __LINE__, "Trying to profile with derived event", 1);
		      num_events=i;
		      break;
		   }
                   else {
		        printf("Failed with event %d 0x%x\n",i,events[i]);
			test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
		   }
		}
	}

	if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start", retval );

	my_main(  );

	if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_stop", retval );

	if ( !TESTS_QUIET ) {
		printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[--event] );
		if ( strcmp( hw_info->model_string, "POWER6" ) != 0 ) {
			printf( TAB1, "PAPI_TOT_INS:", ( values[0] )[--event] );
		}
#if defined(__powerpc__)
		printf( TAB1, "PAPI_FP_INS", ( values[0] )[--event] );
#else
		if ( strcmp( hw_info->model_string, "Intel Pentium III" ) != 0 ) {
			printf( TAB1, "PAPI_FP_OPS:", ( values[0] )[--event] );
			printf( TAB1, "PAPI_L2_TCM:", ( values[0] )[--event] );
		}
#endif
	}

	for ( i = 0; i < num_events; i++ ) {
		if ( ( retval =
			   PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
							EventSet, events[i], 0,
							PAPI_PROFIL_POSIX ) ) != PAPI_OK )
			test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
	}

	prof_head( blength, bucket, num_buckets, header );
	prof_out( start, num_events, bucket, num_buckets, scale );
	retval = prof_check( num_bufs, bucket, num_buckets );
	for ( i = 0; i < num_bufs; i++ ) {
		free( profbuf[i] );
	}
	return retval;
}
int main(int argc, char **argv)
{
   int i, num_events, num_tests = 6, mask = 0x1;
   int EventSet = PAPI_NULL;
   unsigned short **buf = (unsigned short **)profbuf;
   unsigned long length, blength;
   int num_buckets;
   PAPI_sprofil_t sprof[3];
   int retval;
   const PAPI_hw_info_t *hw_info;
   const PAPI_exe_info_t *prginfo;
   caddr_t start, end;

   prof_init(argc, argv, &hw_info, &prginfo);

   start = prginfo->address_info.text_start;
   end = prginfo->address_info.text_end;
   if (start > end)
      test_fail(__FILE__, __LINE__, "Profile length < 0!", PAPI_ESBSTR);
   length = end - start;
   prof_print_address("Test case sprofile: POSIX compatible profiling over multiple regions.\n",prginfo);
   blength = prof_size(length, FULL_SCALE, PAPI_PROFIL_BUCKET_16, &num_buckets);
   prof_alloc(3, blength);

   /* First half */
   sprof[0].pr_base = buf[0];
   sprof[0].pr_size = blength;
   sprof[0].pr_off = (caddr_t) DO_FLOPS;
#if defined(linux) && defined(__ia64__)
   if (!TESTS_QUIET)
      fprintf(stderr, "do_flops is at %p %p\n", &do_flops, sprof[0].pr_off);
#endif
   sprof[0].pr_scale = FULL_SCALE;
   /* Second half */
   sprof[1].pr_base = buf[1];
   sprof[1].pr_size = blength;
   sprof[1].pr_off = (caddr_t) DO_READS;
#if defined(linux) && defined(__ia64__)
   if (!TESTS_QUIET)
      fprintf(stderr, "do_reads is at %p %p\n", &do_reads, sprof[1].pr_off);
#endif
   sprof[1].pr_scale = FULL_SCALE;
   /* Overflow bin */
   sprof[2].pr_base = buf[2];
   sprof[2].pr_size = 1;
   sprof[2].pr_off = 0;
   sprof[2].pr_scale = 0x2;

   EventSet = add_test_events(&num_events, &mask);

   values = allocate_test_space(num_tests, num_events);

   if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_TOT_CYC, THRESHOLD,
                              PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_sprofil", retval);

   do_stuff();

   if ((retval = PAPI_start(EventSet)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_stuff();

   if ((retval = PAPI_stop(EventSet, values[1])) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   /* clear the profile flag before removing the event */
   if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_TOT_CYC, 0,
                              PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_sprofil", retval);

   remove_test_events(&EventSet, mask);



   if (!TESTS_QUIET) {
      printf("Test case: PAPI_sprofil()\n");
      printf("---------Buffer 1--------\n");
      for (i = 0; i < length / 2; i++) {
         if (buf[0][i])
            printf("0x%lx\t%d\n", DO_FLOPS + 2 * i, buf[0][i]);
      }
      printf("---------Buffer 2--------\n");
      for (i = 0; i < length / 2; i++) {
         if (buf[1][i])
            printf("0x%lx\t%d\n", DO_READS + 2 * i, buf[1][i]);
      }
      printf("-------------------------\n");
      printf("%u samples fell outside the regions.\n", *buf[2]);
   }
   retval = prof_check(2, PAPI_PROFIL_BUCKET_16, num_buckets);

   for (i=0;i<3;i++) {
      free(profbuf[i]);
   }
   if (retval == 0)
      test_fail(__FILE__, __LINE__, "No information in buffers", 1);

   test_pass(__FILE__, values, num_tests);

   exit(1);
}
static int do_profile(caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket) {
   int i, retval;
   unsigned long blength;
   int num_buckets;

   char *profstr[5] = {"PAPI_PROFIL_POSIX",
                        "PAPI_PROFIL_RANDOM",
                        "PAPI_PROFIL_WEIGHTED",
                        "PAPI_PROFIL_COMPRESS",
                        "PAPI_PROFIL_<all>" };

   int profflags[5] = {PAPI_PROFIL_POSIX,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_RANDOM,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_WEIGHTED,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_COMPRESS,
                       PAPI_PROFIL_POSIX | PAPI_PROFIL_WEIGHTED |
                       PAPI_PROFIL_RANDOM | PAPI_PROFIL_COMPRESS };

   do_no_profile();
   blength = prof_size(plength, scale, bucket, &num_buckets);
   prof_alloc(5, blength);

   for (i=0;i<5;i++) {
      if (!TESTS_QUIET)
         printf("Test type   : \t%s\n", profstr[i]);

#ifndef SWPROFILE
      if ((retval = PAPI_profil(profbuf[i], blength, start, scale,
                              EventSet, PAPI_event, thresh,
                              profflags[i] | bucket)) != PAPI_OK) {
         test_fail(__FILE__, __LINE__, "PAPI_profil", retval);
      }
#else
      if ((retval = PAPI_profil(profbuf[i], blength, start, scale,
                              EventSet, PAPI_event, thresh,
                              profflags[i] | bucket | PAPI_PROFIL_FORCE_SW)) != PAPI_OK) {
         test_fail(__FILE__, __LINE__, "PAPI_profil", retval);
      }
#endif
      if ((retval = PAPI_start(EventSet)) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_start", retval);

      do_flops(getenv("NUM_FLOPS") ? atoi(getenv("NUM_FLOPS")) : NUM_FLOPS);

      if ((retval = PAPI_stop(EventSet, values[1])) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

      if (!TESTS_QUIET) {
         printf(TAB1, event_name, (values[1])[0]);
         printf(TAB1, "PAPI_TOT_CYC", (values[1])[1]);
      }
      if ((retval = PAPI_profil(profbuf[i], blength, start, scale,
                              EventSet, PAPI_event, 0, profflags[i])) != PAPI_OK)
         test_fail(__FILE__, __LINE__, "PAPI_profil", retval);
   }

   prof_head(blength, bucket, num_buckets, 
      "address\t\t\tflat\trandom\tweight\tcomprs\tall\n");
   prof_out(start, 5, bucket, num_buckets, scale);

   retval = prof_check(5, bucket, num_buckets);

   for (i=0;i<5;i++) {
      free(profbuf[i]);
   }

   return(retval);
}