PAPI 7.1.0.0
Loading...
Searching...
No Matches
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.
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ NUM_EVENTS

#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

◆ main()

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
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
107
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
121 if (retval != PAPI_OK) {
122 test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
123 }
124
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
138 if (retval != PAPI_OK) {
139 test_fail(__FILE__, __LINE__,
140 "PAPI_cleanup_eventset()",retval);
141 }
142
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
162
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
176 if (retval != PAPI_OK) {
177 test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
178 }
179
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
193 if (retval != PAPI_OK) {
194 test_fail(__FILE__, __LINE__,
195 "PAPI_cleanup_eventset()",retval);
196 }
197
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
216
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
230 if (retval != PAPI_OK) {
231 test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
232 }
233
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
243 if (retval != PAPI_OK) {
244 test_fail(__FILE__, __LINE__,
245 "PAPI_cleanup_eventset()",retval);
246 }
247
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}
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
Get the event's name and description info.
initialize the PAPI library.
Get the number of components available on the system.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define NUM_EVENTS
Shows "pretty" coretemp output.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_MASK
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: