PAPI  5.6.0.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 21 of file coretemp_pretty.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file coretemp_pretty.c.

24 {
25 
26  int retval,cid,coretemp_cid=-1,numcmp;
27  int EventSet = PAPI_NULL;
28  long long values[NUM_EVENTS];
29  int code;
31  int r;
32  const PAPI_component_info_t *cmpinfo = NULL;
33  PAPI_event_info_t evinfo;
34  double temperature;
35 
36  /* Set TESTS_QUIET variable */
37  tests_quiet( argc, argv );
38 
39  /* PAPI Initialization */
41  if ( retval != PAPI_VER_CURRENT ) {
42  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
43  }
44 
45  if (!TESTS_QUIET) {
46  printf("Trying all coretemp events\n");
47  }
48 
49  numcmp = PAPI_num_components();
50 
51  for(cid=0; cid<numcmp; cid++) {
52 
53  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
54  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
55  }
56 
57  if (strstr(cmpinfo->name,"coretemp")) {
58  coretemp_cid=cid;
59  if (!TESTS_QUIET) printf("Found coretemp component at cid %d\n",
60  coretemp_cid);
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  if (cmpinfo->num_native_events==0) {
68  test_skip(__FILE__,__LINE__,"No coretemp events found",0);
69  }
70  break;
71  }
72  }
73 
74 
75 
76 
77  code = PAPI_NATIVE_MASK;
78 
79  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid );
80 
81  while ( r == PAPI_OK ) {
82 
83  retval = PAPI_event_code_to_name( code, event_name );
84  if ( retval != PAPI_OK ) {
85  printf("Error translating %#x\n",code);
86  test_fail( __FILE__, __LINE__,
87  "PAPI_event_code_to_name", retval );
88  }
89 
90  retval = PAPI_get_event_info(code,&evinfo);
91  if (retval != PAPI_OK) {
92  test_fail( __FILE__, __LINE__,
93  "Error getting event info\n",retval);
94  }
95 
96  /****************************/
97  /* Print Temperature Inputs */
98  /****************************/
99  if (strstr(event_name,"temp")) {
100 
101  /* Only print inputs */
102  if (strstr(event_name,"_input")) {
103 
104  if (!TESTS_QUIET) printf("%s ",event_name);
105 
106  EventSet = PAPI_NULL;
107 
108  retval = PAPI_create_eventset( &EventSet );
109  if (retval != PAPI_OK) {
110  test_fail(__FILE__, __LINE__,
111  "PAPI_create_eventset()",retval);
112  }
113 
114  retval = PAPI_add_event( EventSet, code );
115  if (retval != PAPI_OK) {
116  test_fail(__FILE__, __LINE__,
117  "PAPI_add_event()",retval);
118  }
119 
120  retval = PAPI_start( EventSet);
121  if (retval != PAPI_OK) {
122  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
123  }
124 
125  retval = PAPI_stop( EventSet, values);
126  if (retval != PAPI_OK) {
127  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
128  }
129 
130  temperature=(values[0]/1000.0);
131 
132  if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
133  temperature,
134  evinfo.long_descr
135  );
136 
137  retval = PAPI_cleanup_eventset( EventSet );
138  if (retval != PAPI_OK) {
139  test_fail(__FILE__, __LINE__,
140  "PAPI_cleanup_eventset()",retval);
141  }
142 
143  retval = PAPI_destroy_eventset( &EventSet );
144  if (retval != PAPI_OK) {
145  test_fail(__FILE__, __LINE__,
146  "PAPI_destroy_eventset()",retval);
147  }
148  }
149  }
150 
151  /****************************/
152  /* Print Voltage Inputs */
153  /****************************/
154  if (strstr(event_name,".in")) {
155 
156  /* Only print inputs */
157  if (strstr(event_name,"_input")) {
158 
159  if (!TESTS_QUIET) printf("%s ",event_name);
160 
161  EventSet = PAPI_NULL;
162 
163  retval = PAPI_create_eventset( &EventSet );
164  if (retval != PAPI_OK) {
165  test_fail(__FILE__, __LINE__,
166  "PAPI_create_eventset()",retval);
167  }
168 
169  retval = PAPI_add_event( EventSet, code );
170  if (retval != PAPI_OK) {
171  test_fail(__FILE__, __LINE__,
172  "PAPI_add_event()",retval);
173  }
174 
175  retval = PAPI_start( EventSet);
176  if (retval != PAPI_OK) {
177  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
178  }
179 
180  retval = PAPI_stop( EventSet, values);
181  if (retval != PAPI_OK) {
182  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
183  }
184 
185  temperature=(values[0]/1000.0);
186 
187  if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
188  temperature,
189  evinfo.long_descr
190  );
191 
192  retval = PAPI_cleanup_eventset( EventSet );
193  if (retval != PAPI_OK) {
194  test_fail(__FILE__, __LINE__,
195  "PAPI_cleanup_eventset()",retval);
196  }
197 
198  retval = PAPI_destroy_eventset( &EventSet );
199  if (retval != PAPI_OK) {
200  test_fail(__FILE__, __LINE__,
201  "PAPI_destroy_eventset()",retval);
202  }
203  }
204  }
205  /********************/
206  /* Print Fan Inputs */
207  /********************/
208  else if (strstr(event_name,"fan")) {
209 
210  /* Only print inputs */
211  if (strstr(event_name,"_input")) {
212 
213  if (!TESTS_QUIET) printf("%s ",event_name);
214 
215  EventSet = PAPI_NULL;
216 
217  retval = PAPI_create_eventset( &EventSet );
218  if (retval != PAPI_OK) {
219  test_fail(__FILE__, __LINE__,
220  "PAPI_create_eventset()",retval);
221  }
222 
223  retval = PAPI_add_event( EventSet, code );
224  if (retval != PAPI_OK) {
225  test_fail(__FILE__, __LINE__,
226  "PAPI_add_event()",retval);
227  }
228 
229  retval = PAPI_start( EventSet);
230  if (retval != PAPI_OK) {
231  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
232  }
233 
234  retval = PAPI_stop( EventSet, values);
235  if (retval != PAPI_OK) {
236  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
237  }
238 
239  if (!TESTS_QUIET) printf("\tvalue: %lld %s\n",values[0],
240  evinfo.long_descr);
241 
242  retval = PAPI_cleanup_eventset( EventSet );
243  if (retval != PAPI_OK) {
244  test_fail(__FILE__, __LINE__,
245  "PAPI_cleanup_eventset()",retval);
246  }
247 
248  retval = PAPI_destroy_eventset( &EventSet );
249  if (retval != PAPI_OK) {
250  test_fail(__FILE__, __LINE__,
251  "PAPI_destroy_eventset()",retval);
252  }
253  }
254 
255  }
256  else {
257  /* Skip unknown */
258  }
259 
260  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid );
261  }
262 
263  test_pass( __FILE__ );
264 
265  return 0;
266 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_NULL
Definition: papi.h:292
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:969
int PAPI_num_components(void)
Definition: papi.c:4387
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:636
int PAPI_library_init(int version)
Definition: papi.c:500
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1357
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
#define NUM_EVENTS
Shows &quot;pretty&quot; coretemp output.

Here is the call graph for this function: