import java.util.*; public class PAPITest { public static void main(String args[]) throws Throwable { int iters = 0; boolean verbose = true; PAPICounter [] counters = new PAPICounter[allevents.length*4]; int [] events = new int[allevents.length*4]; int cnt = 0; int numevts = 0; long seed = 0; boolean err = false; if (args.length >= 1) try { iters = Integer.parseInt(args[0]); } catch (Throwable exn) {} if (iters == 0) iters = 100; if (iters < 10) iters = 10; if (args.length >= 2) try { seed = Integer.parseInt(args[1]); } catch (Throwable exn) {} if (seed == 0) seed = System.currentTimeMillis() % 10000; Random rand = new Random(seed+Ti.thisProc()); if (verbose && Ti.thisProc() == 0) System.out.println("Starting papi test with "+iters+" iterations and seed=" + seed); Ti.barrier(); try { Ti.barrier(); /* build a random set of events that can all run together */ if (verbose) System.out.println("Gathering counters..."); int maxlen = allevents.length; for (int i = (Math.abs(rand.nextInt())%allevents.length), trycnt = 0; trycnt < maxlen; trycnt++, i = (i+1)%allevents.length) { try { int evt = allevents[i]; if (evt != PAPICounter.PAPI_FP_OPS) { /* avoid PAPI_FP_OPS, causes internal PAPI errors */ PAPICounter pc = new PAPICounter(evt); pc.start(); counters[cnt] = pc; events[cnt] = evt; cnt++; pc.stop(); if (verbose) System.out.println("Added Counter:" + pc); pc.start(); } } catch (TooManyCounterException exn) { } catch (EventNotAvailException exn) { } } Ti.barrier(); numevts = cnt; if (verbose) System.out.println("Duplicating counters..."); try { for (int i=0; i < numevts; i++) { for (int j=1; j < 4; j++) { PAPICounter pc = new PAPICounter(events[i]); counters[j*numevts+i] = pc; pc.start(); cnt++; } } } catch (TooManyCounterException exn) { if (verbose) System.out.println("Duplication failed!!!"); } if (verbose) System.out.println("Got "+cnt+" counters, stopping/clearing them..."); for (int i=0; i < cnt; i++) { PAPICounter pc = counters[i]; pc.stop(); assert pc.getCounterValue() >= 0; pc.clear(); assert pc.getCounterValue() == 0; } Ti.barrier(); Ti.barrier(); if (verbose) System.out.println("Running tester with "+iters+" iterations..."); for (int i=0; i < numevts; i++) { PAPICounter pc = counters[i]; Timer t = new Timer(); t.start(); for (int iter = 0; iter < iters; iter++) { pc.start(); pc.stop(); } t.stop(); pc.start(); System.out.println("PAPICounter start/stop time for "+i+" true events: "+ t.micros()/iters + " us"); } Ti.barrier(); for (int i=0; i < cnt; i++) { if (counters[i].running()) counters[i].stop(); } Ti.barrier(); for (int i=0; i*numevts < cnt; i++) { PAPICounter pc = counters[i*numevts]; Timer t = new Timer(); t.start(); for (int iter = 0; iter < iters; iter++) { pc.start(); pc.stop(); } t.stop(); pc.start(); System.out.println("PAPICounter start/stop time for "+i+" overload events: "+ t.micros()/iters + " us"); } Ti.barrier(); for (int i=0; i < cnt; i++) { if (counters[i].running()) counters[i].stop(); } Ti.barrier(); for (int i=0; i < cnt; i++) { PAPICounter pc = counters[i]; Timer t = new Timer(); t.start(); for (int iter = 0; iter < iters; iter++) { pc.start(); pc.stop(); } t.stop(); pc.start(); System.out.println("PAPICounter start/stop time for "+i+" mixed events: "+ t.micros()/iters + " us"); } Ti.barrier(); for (int i=0; i < cnt; i++) { if (counters[i].running()) counters[i].stop(); } Ti.barrier(); } catch (Throwable exn) { System.out.println("ERROR: (seed="+seed+") got exception that should never happen: " + exn); err = true; } Ti.barrier(); if (err) System.out.println("Test Failed."); else System.out.println("Test Passed."); } public static int[] allevents = { /* all the PAPI Counters */ PAPICounter.PAPI_L1_DCM , PAPICounter.PAPI_L1_ICM , PAPICounter.PAPI_L2_DCM , PAPICounter.PAPI_L2_ICM , PAPICounter.PAPI_L3_DCM , PAPICounter.PAPI_L3_ICM , PAPICounter.PAPI_L1_TCM , PAPICounter.PAPI_L2_TCM , PAPICounter.PAPI_L3_TCM , PAPICounter.PAPI_CA_SNP , PAPICounter.PAPI_CA_SHR , PAPICounter.PAPI_CA_CLN , PAPICounter.PAPI_CA_INV , PAPICounter.PAPI_CA_ITV , PAPICounter.PAPI_L3_LDM , PAPICounter.PAPI_L3_STM , PAPICounter.PAPI_BRU_IDL , PAPICounter.PAPI_FXU_IDL , PAPICounter.PAPI_FPU_IDL , PAPICounter.PAPI_LSU_IDL , PAPICounter.PAPI_TLB_DM , PAPICounter.PAPI_TLB_IM , PAPICounter.PAPI_TLB_TL , PAPICounter.PAPI_L1_LDM , PAPICounter.PAPI_L1_STM , PAPICounter.PAPI_L2_LDM , PAPICounter.PAPI_L2_STM , PAPICounter.PAPI_BTAC_M , PAPICounter.PAPI_PRF_DM , PAPICounter.PAPI_L3_DCH , PAPICounter.PAPI_TLB_SD , PAPICounter.PAPI_CSR_FAL , PAPICounter.PAPI_CSR_SUC , PAPICounter.PAPI_CSR_TOT , PAPICounter.PAPI_MEM_SCY , PAPICounter.PAPI_MEM_RCY , PAPICounter.PAPI_MEM_WCY , PAPICounter.PAPI_STL_ICY , PAPICounter.PAPI_FUL_ICY , PAPICounter.PAPI_STL_CCY , PAPICounter.PAPI_FUL_CCY , PAPICounter.PAPI_HW_INT , PAPICounter.PAPI_BR_UCN , PAPICounter.PAPI_BR_CN , PAPICounter.PAPI_BR_TKN , PAPICounter.PAPI_BR_NTK , PAPICounter.PAPI_BR_MSP , PAPICounter.PAPI_BR_PRC , PAPICounter.PAPI_FMA_INS , PAPICounter.PAPI_TOT_IIS , PAPICounter.PAPI_TOT_INS , PAPICounter.PAPI_INT_INS , PAPICounter.PAPI_FP_INS , PAPICounter.PAPI_LD_INS , PAPICounter.PAPI_SR_INS , PAPICounter.PAPI_BR_INS , PAPICounter.PAPI_VEC_INS , PAPICounter.PAPI_RES_STL , PAPICounter.PAPI_FP_STAL , PAPICounter.PAPI_TOT_CYC , PAPICounter.PAPI_LST_INS , PAPICounter.PAPI_SYC_INS , PAPICounter.PAPI_L1_DCH , PAPICounter.PAPI_L2_DCH , PAPICounter.PAPI_L1_DCA , PAPICounter.PAPI_L2_DCA , PAPICounter.PAPI_L3_DCA , PAPICounter.PAPI_L1_DCR , PAPICounter.PAPI_L2_DCR , PAPICounter.PAPI_L3_DCR , PAPICounter.PAPI_L1_DCW , PAPICounter.PAPI_L2_DCW , PAPICounter.PAPI_L3_DCW , PAPICounter.PAPI_L1_ICH , PAPICounter.PAPI_L2_ICH , PAPICounter.PAPI_L3_ICH , PAPICounter.PAPI_L1_ICA , PAPICounter.PAPI_L2_ICA , PAPICounter.PAPI_L3_ICA , PAPICounter.PAPI_L1_ICR , PAPICounter.PAPI_L2_ICR , PAPICounter.PAPI_L3_ICR , PAPICounter.PAPI_L1_ICW , PAPICounter.PAPI_L2_ICW , PAPICounter.PAPI_L3_ICW , PAPICounter.PAPI_L1_TCH , PAPICounter.PAPI_L2_TCH , PAPICounter.PAPI_L3_TCH , PAPICounter.PAPI_L1_TCA , PAPICounter.PAPI_L2_TCA , PAPICounter.PAPI_L3_TCA , PAPICounter.PAPI_L1_TCR , PAPICounter.PAPI_L2_TCR , PAPICounter.PAPI_L3_TCR , PAPICounter.PAPI_L1_TCW , PAPICounter.PAPI_L2_TCW , PAPICounter.PAPI_L3_TCW , PAPICounter.PAPI_FML_INS , PAPICounter.PAPI_FAD_INS , PAPICounter.PAPI_FDV_INS , PAPICounter.PAPI_FSQ_INS , PAPICounter.PAPI_FNV_INS , PAPICounter.PAPI_FP_OPS }; }