PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
coretemp_basic.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "papi_test.h"
18 
19 #define NUM_EVENTS 1
20 
21 int main (int argc, char **argv)
22 {
23 
24  int retval,cid,numcmp,coretemp_cid=-1;
25  int EventSet = PAPI_NULL;
26  long long values[NUM_EVENTS];
27  int code;
29  int total_events=0;
30  int r;
31  const PAPI_component_info_t *cmpinfo = NULL;
32 
33  /* Set TESTS_QUIET variable */
34  tests_quiet( argc, argv );
35 
36  /* PAPI Initialization */
38  if ( retval != PAPI_VER_CURRENT ) {
39  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
40  }
41 
42  if (!TESTS_QUIET) {
43  printf("Trying all coretemp events\n");
44  }
45 
46  numcmp = PAPI_num_components();
47 
48  for(cid=0; cid<numcmp; cid++) {
49 
50  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
51  test_fail(__FILE__, __LINE__,
52  "PAPI_get_component_info failed\n", 0);
53  }
54 
55  if (strstr(cmpinfo->name,"coretemp")) {
56  coretemp_cid=cid;
57  if (!TESTS_QUIET) {
58  printf("Found coretemp component at cid %d\n", coretemp_cid);
59  }
60 
61  if (cmpinfo->disabled) {
62  if (!TESTS_QUIET) fprintf(stderr,"Coretemp component disabled: %s\n",
63  cmpinfo->disabled_reason);
64  test_skip(__FILE__, __LINE__,
65  "Component disabled\n", 0);
66  }
67  }
68  }
69 
70  if (coretemp_cid==-1) {
71  test_skip(__FILE__,__LINE__,"No coretemp component found",0);
72  }
73 
74 
75  code = PAPI_NATIVE_MASK;
76 
77  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid );
78 
79  while ( r == PAPI_OK ) {
80  retval = PAPI_event_code_to_name( code, event_name );
81  if ( retval != PAPI_OK ) {
82  printf("Error translating %#x\n",code);
83  test_fail( __FILE__, __LINE__,
84  "PAPI_event_code_to_name", retval );
85  }
86 
87  if (!TESTS_QUIET) printf("%s ",event_name);
88 
89  EventSet = PAPI_NULL;
90 
91  retval = PAPI_create_eventset( &EventSet );
92  if (retval != PAPI_OK) {
93  test_fail(__FILE__, __LINE__,
94  "PAPI_create_eventset()",retval);
95  }
96 
97  retval = PAPI_add_event( EventSet, code );
98  if (retval != PAPI_OK) {
99  test_fail(__FILE__, __LINE__,
100  "PAPI_add_event()",retval);
101  }
102 
103  retval = PAPI_start( EventSet);
104  if (retval != PAPI_OK) {
105  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
106  }
107 
108  retval = PAPI_stop( EventSet, values);
109  if (retval != PAPI_OK) {
110  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
111  }
112 
113  if (!TESTS_QUIET) printf(" value: %lld\n",values[0]);
114 
115  retval = PAPI_cleanup_eventset( EventSet );
116  if (retval != PAPI_OK) {
117  test_fail(__FILE__, __LINE__,
118  "PAPI_cleanup_eventset()",retval);
119  }
120 
121  retval = PAPI_destroy_eventset( &EventSet );
122  if (retval != PAPI_OK) {
123  test_fail(__FILE__, __LINE__,
124  "PAPI_destroy_eventset()",retval);
125  }
126 
127  total_events++;
128  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid );
129  }
130 
131  if (total_events==0) {
132  test_skip(__FILE__,__LINE__,"No coretemp events found",0);
133  }
134 
135  test_pass( __FILE__, NULL, 0 );
136 
137  return 0;
138 }
139 
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:803
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int PAPI_num_components(void)
Definition: papi.c:4272
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
#define NUM_EVENTS
Tests basic coretemp functionality.
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1305
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
int EventSet
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
int PAPI_start(int EventSet)
Definition: papi.c:2019
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.