PAPI 7.1.0.0
Loading...
Searching...
No Matches
describe.c
Go to the documentation of this file.
1/* From Paul Drongowski at HP. Thanks. */
2
3/* I have not been able to call PAPI_describe_event without
4 incurring a segv, including the sample code on the man page.
5 I noticed that PAPI_describe_event is not exercised by the
6 PAPI test programs, so I haven't been able to check the
7 function call using known good code. (Or steal your code
8 for that matter. :-)
9*/
10
11/* PAPI_describe_event has been deprecated in PAPI 3, since
12 its functionality exists in other API calls. Below shows
13 several ways that this call was used, with replacement
14 code compatible with PAPI 3.
15*/
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include "papi.h"
22#include "papi_test.h"
23
24int
25main( int argc, char **argv )
26{
27 int EventSet = PAPI_NULL;
28 int retval;
29 long long g1[2];
30 int eventcode = PAPI_TOT_INS;
31 PAPI_event_info_t info, info1, info2;
32 int quiet;
33
34 /* Set TESTS_QUIET variable */
35 quiet=tests_quiet( argc, argv );
36
37
39 if (retval != PAPI_VER_CURRENT ) {
40 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
41 }
42
43 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) {
44 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
45 }
46
47 if ( ( retval = PAPI_query_event( eventcode ) ) != PAPI_OK ) {
48 if (!quiet) printf("Trouble checking event\n");
49 test_skip( __FILE__, __LINE__, "PAPI_query_event(PAPI_TOT_INS)",
50 retval );
51 }
52
53 if ( ( retval = PAPI_add_event( EventSet, eventcode ) ) != PAPI_OK )
54 test_fail( __FILE__, __LINE__, "PAPI_add_event(PAPI_TOT_INS)", retval );
55
56 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
57 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
58
59 if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
60 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
61
62 /* Case 0, no info, should fail */
63 eventcode = 0;
64/*
65 if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) == PAPI_OK)
66 test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
67*/
68 if (!quiet) {
69 printf("This test expects a 'PAPI Error' to be returned from this PAPI call.\n");
70 }
71 if ( ( retval = PAPI_get_event_info( eventcode, &info ) ) == PAPI_OK )
72 test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
73
74 /* Case 1, fill in name field. */
75 eventcode = PAPI_TOT_INS;
76/*
77 if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
78 test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
79*/
80 if ( ( retval = PAPI_get_event_info( eventcode, &info1 ) ) != PAPI_OK )
81 test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
82
83 if ( strcmp( info1.symbol, "PAPI_TOT_INS" ) != 0 )
84 test_fail( __FILE__, __LINE__,
85 "PAPI_get_event_info symbol value is bogus", retval );
86 if ( strlen( info1.long_descr ) == 0 )
87 test_fail( __FILE__, __LINE__,
88 "PAPI_get_event_info long_descr value is bogus", retval );
89
90 eventcode = 0;
91
92 /* Case 2, fill in code field. */
93/*
94 if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
95 test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);
96*/
97 if ( ( retval = PAPI_event_name_to_code( info1.symbol, ( int * ) &eventcode ) ) != PAPI_OK ) {
98 test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
99 }
100
101 if ( eventcode != PAPI_TOT_INS )
102 test_fail( __FILE__, __LINE__,
103 "PAPI_event_name_to_code code value is bogus", retval );
104
105 if ( ( retval = PAPI_get_event_info( eventcode, &info2 ) ) != PAPI_OK )
106 test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
107
108 if ( strcmp( info2.symbol, "PAPI_TOT_INS" ) != 0 )
109 test_fail( __FILE__, __LINE__,
110 "PAPI_get_event_info symbol value is bogus", retval );
111 if ( strlen( info2.long_descr ) == 0 )
112 test_fail( __FILE__, __LINE__,
113 "PAPI_get_event_info long_descr value is bogus", retval );
114
115 test_pass( __FILE__ );
116
117 return 0;
118}
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
Get the event's name and description info.
initialize the PAPI library.
Query if PAPI event exists.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_INS
Definition: f90papi.h:317
static int EventSet
Definition: init_fini.c:8
Return codes and api definitions.
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
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
int retval
Definition: zero_fork.c:53