/*----------------------------------------------------------------------------*/

/* Compile with
 *   gcc -o menu6 -O `pmc_options` menu6.c -lpmc
 *
 * Try these examples (Pentium Pro/II/III):
 *   menu6
 *   menu6 --e 192,194
 *   menu6 --e 0xc0,0xc2
 *   menu6 --e 0x28,0x2a --mesi 3,4
 *   menu6 --e 0xc0,0xc2 --mesi 3,4
 *
 * Try these examples (AMD Athlon):
 *   menu6
 *   menu6 --e 192,193
 *   menu6 --e 0xc0,0xc1
 *   menu6 --e 0x40 --mesi 0,1,2,3
 */

/*----------------------------------------------------------------------------*/

#include <pmc_lib.h>

/*----------------------------------------------------------------------------*/

int main(int argc, char * argv[])
{
  pmc_control_t Ctl = pmc_control_null;
  pmc_data_t t0, t1;
  pmc_counter_t tot;
  int k;

  if (pmc_getargs(stderr, argv[0], &argc, &argv, &Ctl) == FALSE)
    { exit(1); }

  printf("sizeof(pmc_counter_t)  = %d\n", sizeof(pmc_counter_t));
  printf("sizeof(pmc_selector_t) = %d\n", sizeof(pmc_selector_t));
  printf("sizeof(pmc_cycles_t)   = %d\n", sizeof(pmc_cycles_t));
  printf("sizeof(pmc_events_t)   = %d\n", sizeof(pmc_events_t));
  printf("pmc_cycles_bits        = %d\n", pmc_cycles_bits);
  printf("pmc_events_bits        = %d\n", pmc_events_bits);

  pmc_counter_init(&tot, &Ctl); /* initialize the accumulator */

  if (pmc_open(0) == FALSE)	/* open /dev/pmc */
    { exit(1); }

  pmc_read(&t0);		/* read the counters */

  /* do something */

  pmc_read(&t1);		/* read the counters */

  pmc_close();			/* close /dev/pmc */

  /* the selector field is almost never of direct interest */
  printf("tot.selector          =");
  for (k = 0; k < pmc_event_counters; k++)
    { printf(" %08lx", tot.selector.c[k]); }
  printf("\n");

  printf("tot.pmc_sum_cycles()  = %016llx\n", pmc_sum_cycles(&tot));
  for (k = 0; k < pmc_event_counters; k++)
    {
      printf("tot.pmc_sum_events(%d) = %016llx\n", k, pmc_sum_events(&tot,k));
    }
  printf("tot.pmc_seconds()     = %16.9f\n",  pmc_seconds(pmc_sum_cycles(&tot)));

  exit(0);
}

/*----------------------------------------------------------------------------*/
