|
PAPI
5.0.1.0
|
00001 /***************************************************************************** 00002 * This example demonstrates the usage of the high level function PAPI_ipc * 00003 * which measures the number of instructions executed per cpu cycle * 00004 *****************************************************************************/ 00005 00006 /***************************************************************************** 00007 * The first call to PAPI_ipc initializes the PAPI library, set up the * 00008 * counters to monitor PAPI_TOT_INS and PAPI_TOT_CYC events, and start the * 00009 * counters. Subsequent calls will read the counters and return total real * 00010 * time, total process time, total instructions, and the instructions per * 00011 * cycle rate since the last call to PAPI_ipc. * 00012 *****************************************************************************/ 00013 00014 00015 #include <stdio.h> 00016 #include <stdlib.h> 00017 #include "papi.h" 00018 00019 00020 main() 00021 { 00022 float real_time, proc_time,ipc; 00023 long long ins; 00024 float real_time_i, proc_time_i, ipc_i; 00025 long long ins_i; 00026 int retval; 00027 00028 if((retval=PAPI_ipc(&real_time_i,&proc_time_i,&ins_i,&ipc_i)) < PAPI_OK) 00029 { 00030 printf("Could not initialise PAPI_ipc \n"); 00031 printf("retval: %d\n", retval); 00032 exit(1); 00033 } 00034 00035 your_slow_code(); 00036 00037 00038 if((retval=PAPI_ipc( &real_time, &proc_time, &ins, &ipc))<PAPI_OK) 00039 { 00040 printf("retval: %d\n", retval); 00041 exit(1); 00042 } 00043 00044 00045 printf("Real_time: %f Proc_time: %f Total instructions: %lld IPC: %f\n", 00046 real_time, proc_time,ins,ipc); 00047 00048 /* clean up */ 00049 PAPI_shutdown(); 00050 exit(0); 00051 } 00052 00053 int your_slow_code() 00054 { 00055 int i; 00056 double tmp=1.1; 00057 00058 for(i=1; i<2000; i++) 00059 { 00060 tmp=(tmp+100)/i; 00061 } 00062 return 0; 00063 } 00064