PAPI 7.1.0.0
Loading...
Searching...
No Matches
eventstock.c File Reference
Include dependency graph for eventstock.c:

Go to the source code of this file.

Macros

#define _PAPI_CPU_COMPONENT_NAME   "perf_event"
 

Functions

int build_stock (evstock *stock)
 
void print_stock (evstock *stock)
 
int num_evts (evstock *stock)
 
int num_quals (evstock *stock, int base_evt)
 
size_t max_qual_size (evstock *stock, int base_evt)
 
char * evt_qual (evstock *stock, int base_evt, int tag)
 
char * evt_name (evstock *stock, int index)
 
void remove_stock (evstock *stock)
 

Macro Definition Documentation

◆ _PAPI_CPU_COMPONENT_NAME

#define _PAPI_CPU_COMPONENT_NAME   "perf_event"

Definition at line 10 of file eventstock.c.

Function Documentation

◆ build_stock()

int build_stock ( evstock stock)

Definition at line 13 of file eventstock.c.

14{
15 int ret;
17 int cid;
18 int ncomps = PAPI_num_components();
19 int event_counter = 0;
20 int subctr = 0;
21 int tmp_event_count;
22 int event_qual_i, event_i;
23
24 if (!stock) return 1;
25
26 event_i = 0 | PAPI_NATIVE_MASK;
27
28 // Add the names to the stock.
29 event_counter = 0;
30 for(cid = 0; cid < ncomps; ++cid)
31 {
33 if( strcmp(cmp_info->name, _PAPI_CPU_COMPONENT_NAME) )
34 continue;
35
36 if (cmp_info->disabled == PAPI_EDELAY_INIT) {
37 int nvt_code = 0 | PAPI_NATIVE_MASK;
38 PAPI_enum_cmp_event(&nvt_code, PAPI_ENUM_FIRST, cid);
39 }
40
41 tmp_event_count = cmp_info->num_native_events;
42
43 // Set the data stock's sizes all to zero.
44 if (NULL == (stock->evtsizes = (int*)calloc( (tmp_event_count),sizeof(int) ))) {
45 fprintf(stderr, "Failed allocation of stock->evtsizes.\n");
46 goto gracious_error;
47 }
48
49 if (NULL == (stock->base_evts = (char**)malloc( (tmp_event_count)*sizeof(char*) ))) {
50 fprintf(stderr, "Failed allocation of stock->base_evts.\n");
51 goto gracious_error;
52 }
53
54 if (NULL == (stock->evts = (char***)malloc((tmp_event_count)*sizeof(char**)))) {
55 fprintf(stderr, "Failed allocation of stock->evts.\n");
56 goto gracious_error;
57 }
58
59 if (NULL == (stock->maxqualsize = (size_t *)calloc( tmp_event_count, sizeof(size_t) ))) {
60 fprintf(stderr, "Failed allocation of stock->maxqualsize.\n");
61 goto gracious_error;
62 }
63
64 break;
65 }
66
67 if( 0 == tmp_event_count ){
68 fprintf(stderr,"ERROR: CPU component (%s) not found. Exiting.",_PAPI_CPU_COMPONENT_NAME);
69 goto gracious_error;
70 }
71
72 // At this point "cid" contains the id of the perf_event (CPU) component.
73
74 ret=PAPI_enum_cmp_event(&event_i,PAPI_ENUM_FIRST,cid);
75 if(ret!=PAPI_OK){
76 fprintf(stderr,"ERROR: CPU component does not contain any events. Exiting");
77 goto gracious_error;
78 }
79
80 do{
81 int i, max_qual_count = 32;
82 size_t max_qual_len, tmp_qual_len;
83 memset(&info,0,sizeof(info));
84 event_qual_i = event_i;
85
86 // Resize the arrays if needed.
87 if( event_counter >= tmp_event_count ){
88 tmp_event_count *= 2;
89 stock->evts = (char ***)realloc( stock->evts, tmp_event_count*sizeof(char **) );
90 stock->evtsizes = (int *)realloc( stock->evtsizes, tmp_event_count*sizeof(int) );
91 stock->base_evts = (char **)realloc( stock->base_evts, tmp_event_count*sizeof(char *) );
92 stock->maxqualsize = (size_t *)realloc( stock->maxqualsize, tmp_event_count*sizeof(size_t) );
93 }
94
95 if (NULL == (stock->evts[event_counter] = (char**)malloc( max_qual_count*sizeof(char*) )) ) {
96 fprintf(stderr, "Failed allocation of stock->evts[i].\n");
97 goto gracious_error;
98 }
99
100 max_qual_len = 0;
101 subctr = 0;
102 i = 0;
103
104 do
105 {
106 char *col_pos;
107 ret=PAPI_get_event_info(event_qual_i,&info);
108 if(ret != PAPI_OK)
109 continue;
110
111 if( 0 == i ){
112 // The first iteration of the inner do loop will give us
113 // the base event, without qualifiers.
114 stock->base_evts[event_counter] = strdup(info.symbol);
115 i++;
116 continue;
117 }
118
119 // TODO: For the CPU component, we skip qualifiers that
120 // contain the string "=". This assumption should be
121 // removed when working with other components.
122 if( NULL != strstr(info.symbol, "=") )
123 continue;
124
125 col_pos = rindex(info.symbol, ':');
126 if ( NULL == col_pos ){
127 continue;
128 }
129
130 // Resize the array of qualifiers as needed.
131 if( subctr >= max_qual_count ){
132 max_qual_count *= 2;
133 stock->evts[event_counter] = (char **)realloc( stock->evts[event_counter], max_qual_count*sizeof(char *) );
134 }
135
136 // Copy the qualifier name into the array.
137 stock->evts[event_counter][subctr] = strdup(col_pos+1);
138 tmp_qual_len = strlen( stock->evts[event_counter][subctr] ) + 1;
139 if( tmp_qual_len > max_qual_len )
140 max_qual_len = tmp_qual_len;
141 subctr++;
142
143 } while(PAPI_enum_cmp_event(&event_qual_i,PAPI_NTV_ENUM_UMASKS,cid)==PAPI_OK);
144 stock->evtsizes[event_counter] = subctr;
145 stock->maxqualsize[event_counter] = max_qual_len;
146 event_counter++;
147 } while( PAPI_enum_cmp_event(&event_i,PAPI_ENUM_EVENTS,cid)==PAPI_OK );
148
149 stock->size = event_counter;
150 return 0;
151
152gracious_error:
153 // Frees only the successfully allocated arrays
154 remove_stock(stock);
155 return 1;
156}
int i
Enumerate PAPI preset or native events for a given component.
get information about a specific software component
Get the event's name and description info.
Get the number of components available on the system.
#define _PAPI_CPU_COMPONENT_NAME
Definition: eventstock.c:10
void remove_stock(evstock *stock)
Definition: eventstock.c:198
#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_EDELAY_INIT
Definition: f90papi.h:271
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
#define PAPI_NATIVE_MASK
FILE * stderr
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
int size
Definition: eventstock.h:6
int * evtsizes
Definition: eventstock.h:7
char *** evts
Definition: eventstock.h:10
size_t * maxqualsize
Definition: eventstock.h:8
char ** base_evts
Definition: eventstock.h:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ evt_name()

char * evt_name ( evstock stock,
int  index 
)

Definition at line 193 of file eventstock.c.

194{
195 return stock->base_evts[index];
196}
Here is the caller graph for this function:

◆ evt_qual()

char * evt_qual ( evstock stock,
int  base_evt,
int  tag 
)

Definition at line 188 of file eventstock.c.

189{
190 return stock->evts[base_evt][tag];
191}

◆ max_qual_size()

size_t max_qual_size ( evstock stock,
int  base_evt 
)

Definition at line 183 of file eventstock.c.

184{
185 return stock->maxqualsize[base_evt];
186}

◆ num_evts()

int num_evts ( evstock stock)

Definition at line 173 of file eventstock.c.

174{
175 return stock->size;
176}
Here is the caller graph for this function:

◆ num_quals()

int num_quals ( evstock stock,
int  base_evt 
)

Definition at line 178 of file eventstock.c.

179{
180 return stock->evtsizes[base_evt];
181}
Here is the caller graph for this function:

◆ print_stock()

void print_stock ( evstock stock)

Definition at line 158 of file eventstock.c.

159{
160 int i, j;
161 for(i = 0; i < stock->size; ++i)
162 {
163 fprintf(stdout, "BASE EVENT <%s>\n", stock->base_evts[i]);
164 for(j = 0; j < stock->evtsizes[i]; ++j)
165 {
166 fprintf(stdout, "%s\n", stock->evts[i][j]);
167 }
168 }
169
170 return;
171}
FILE * stdout

◆ remove_stock()

void remove_stock ( evstock stock)

Definition at line 198 of file eventstock.c.

199{
200 if (!stock) return;
201
202 int i, j;
203 for(i = 0; i < stock->size; ++i)
204 {
205 if (!stock->evtsizes)
206 for(j = 0; j < stock->evtsizes[i]; ++j)
207 {
208 if (stock->evts[i][j])
209 free(stock->evts[i][j]);
210 }
211 if (stock->evts[i])
212 free(stock->evts[i]);
213 if (stock->base_evts[i])
214 free(stock->base_evts[i]);
215 }
216 if (stock->evts)
217 free(stock->evts);
218 if (stock->base_evts)
219 free(stock->base_evts);
220 if (stock->evtsizes)
221 free(stock->evtsizes);
222 if (stock->maxqualsize)
223 free(stock->maxqualsize);
224 free(stock);
225
226 return;
227}
Here is the caller graph for this function: