PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
coretemp_pretty.c File Reference
Include dependency graph for coretemp_pretty.c:

Go to the source code of this file.

Macros

#define NUM_EVENTS   1
 Shows "pretty" coretemp output. More...
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define NUM_EVENTS   1
Author
Vince Weaver

test case that displays "pretty" coretemp output

Definition at line 18 of file coretemp_pretty.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file coretemp_pretty.c.

21 {
22 
23  int retval,cid,coretemp_cid=-1,numcmp;
24  int EventSet = PAPI_NULL;
25  long long values[NUM_EVENTS];
26  int code;
28  int r;
29  const PAPI_component_info_t *cmpinfo = NULL;
30  PAPI_event_info_t evinfo;
31  double temperature;
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__,"PAPI_get_component_info failed\n", 0);
52  }
53 
54  if (strstr(cmpinfo->name,"coretemp")) {
55  coretemp_cid=cid;
56  if (!TESTS_QUIET) printf("Found coretemp component at cid %d\n",
57  coretemp_cid);
58  if (cmpinfo->disabled) {
59  if (!TESTS_QUIET) fprintf(stderr,"Coretemp component disabled: %s\n",
60  cmpinfo->disabled_reason);
61  test_skip(__FILE__, __LINE__,
62  "Component disabled\n", 0);
63  }
64  if (cmpinfo->num_native_events==0) {
65  test_skip(__FILE__,__LINE__,"No coretemp events found",0);
66  }
67  break;
68  }
69  }
70 
71 
72 
73 
74  code = PAPI_NATIVE_MASK;
75 
76  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid );
77 
78  while ( r == PAPI_OK ) {
79 
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  retval = PAPI_get_event_info(code,&evinfo);
88  if (retval != PAPI_OK) {
89  test_fail( __FILE__, __LINE__,
90  "Error getting event info\n",retval);
91  }
92 
93  /****************************/
94  /* Print Temperature Inputs */
95  /****************************/
96  if (strstr(event_name,"temp")) {
97 
98  /* Only print inputs */
99  if (strstr(event_name,"_input")) {
100 
101  if (!TESTS_QUIET) printf("%s ",event_name);
102 
103  EventSet = PAPI_NULL;
104 
105  retval = PAPI_create_eventset( &EventSet );
106  if (retval != PAPI_OK) {
107  test_fail(__FILE__, __LINE__,
108  "PAPI_create_eventset()",retval);
109  }
110 
111  retval = PAPI_add_event( EventSet, code );
112  if (retval != PAPI_OK) {
113  test_fail(__FILE__, __LINE__,
114  "PAPI_add_event()",retval);
115  }
116 
117  retval = PAPI_start( EventSet);
118  if (retval != PAPI_OK) {
119  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
120  }
121 
122  retval = PAPI_stop( EventSet, values);
123  if (retval != PAPI_OK) {
124  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
125  }
126 
127  temperature=(values[0]/1000.0);
128 
129  if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
130  temperature,
131  evinfo.long_descr
132  );
133 
134  retval = PAPI_cleanup_eventset( EventSet );
135  if (retval != PAPI_OK) {
136  test_fail(__FILE__, __LINE__,
137  "PAPI_cleanup_eventset()",retval);
138  }
139 
140  retval = PAPI_destroy_eventset( &EventSet );
141  if (retval != PAPI_OK) {
142  test_fail(__FILE__, __LINE__,
143  "PAPI_destroy_eventset()",retval);
144  }
145  }
146  }
147 
148  /****************************/
149  /* Print Voltage Inputs */
150  /****************************/
151  if (strstr(event_name,".in")) {
152 
153  /* Only print inputs */
154  if (strstr(event_name,"_input")) {
155 
156  if (!TESTS_QUIET) printf("%s ",event_name);
157 
158  EventSet = PAPI_NULL;
159 
160  retval = PAPI_create_eventset( &EventSet );
161  if (retval != PAPI_OK) {
162  test_fail(__FILE__, __LINE__,
163  "PAPI_create_eventset()",retval);
164  }
165 
166  retval = PAPI_add_event( EventSet, code );
167  if (retval != PAPI_OK) {
168  test_fail(__FILE__, __LINE__,
169  "PAPI_add_event()",retval);
170  }
171 
172  retval = PAPI_start( EventSet);
173  if (retval != PAPI_OK) {
174  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
175  }
176 
177  retval = PAPI_stop( EventSet, values);
178  if (retval != PAPI_OK) {
179  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
180  }
181 
182  temperature=(values[0]/1000.0);
183 
184  if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
185  temperature,
186  evinfo.long_descr
187  );
188 
189  retval = PAPI_cleanup_eventset( EventSet );
190  if (retval != PAPI_OK) {
191  test_fail(__FILE__, __LINE__,
192  "PAPI_cleanup_eventset()",retval);
193  }
194 
195  retval = PAPI_destroy_eventset( &EventSet );
196  if (retval != PAPI_OK) {
197  test_fail(__FILE__, __LINE__,
198  "PAPI_destroy_eventset()",retval);
199  }
200  }
201  }
202  /********************/
203  /* Print Fan Inputs */
204  /********************/
205  else if (strstr(event_name,"fan")) {
206 
207  /* Only print inputs */
208  if (strstr(event_name,"_input")) {
209 
210  if (!TESTS_QUIET) printf("%s ",event_name);
211 
212  EventSet = PAPI_NULL;
213 
214  retval = PAPI_create_eventset( &EventSet );
215  if (retval != PAPI_OK) {
216  test_fail(__FILE__, __LINE__,
217  "PAPI_create_eventset()",retval);
218  }
219 
220  retval = PAPI_add_event( EventSet, code );
221  if (retval != PAPI_OK) {
222  test_fail(__FILE__, __LINE__,
223  "PAPI_add_event()",retval);
224  }
225 
226  retval = PAPI_start( EventSet);
227  if (retval != PAPI_OK) {
228  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
229  }
230 
231  retval = PAPI_stop( EventSet, values);
232  if (retval != PAPI_OK) {
233  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
234  }
235 
236  if (!TESTS_QUIET) printf("\tvalue: %lld %s\n",values[0],
237  evinfo.long_descr);
238 
239  retval = PAPI_cleanup_eventset( EventSet );
240  if (retval != PAPI_OK) {
241  test_fail(__FILE__, __LINE__,
242  "PAPI_cleanup_eventset()",retval);
243  }
244 
245  retval = PAPI_destroy_eventset( &EventSet );
246  if (retval != PAPI_OK) {
247  test_fail(__FILE__, __LINE__,
248  "PAPI_destroy_eventset()",retval);
249  }
250  }
251 
252  }
253  else {
254  /* Skip unknown */
255  }
256 
257  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid );
258  }
259 
260  test_pass( __FILE__, NULL, 0 );
261 
262  return 0;
263 }
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:2232
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#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
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
int PAPI_num_components(void)
Definition: papi.c:4285
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 PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
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 PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int EventSet
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define NUM_EVENTS
Shows &quot;pretty&quot; coretemp output.

Here is the call graph for this function: