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

Go to the source code of this file.

Functions

int main (int argc, char **args)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  args 
)

Definition at line 44 of file filter_helgrind.c.

44 {
45 (void) argc;
46 (void) args;
47
48 char myLine[16384];
49 int state, size;
50 char type1, type2;
51 char fname1[256], fname2[256];
52 char *paren1, *paren2;
53
54 FILE *HELOUT = fopen("helgrind_out.txt", "r"); // Read the file.
55 if (HELOUT == NULL) {
56 fprintf(stderr, "Could not open helgrind_out.txt.\n");
57 exit(-1);
58 }
59
60 char PDRR[]="Possible data race during read";
61 char PDRW[]="Possible data race during write";
62 char TCWW[]="This conflicts with a previous write";
63 char TCWR[]="This conflicts with a previous read";
64 char atSTR[]=" at ";
65
66 // State machine:
67 // State 0: We are looking for a line with PDRR or PDRW.
68 // We don't exit until we find it, or run out of lines.
69 // if we find it, we remember which and go to state 1.
70 // State 1: Looking for " at " in column 11.
71 // When found, we extract the string betweeen '(' and ')'
72 // which is program name:line. go to state 2.
73 // State 2: We are searching for TCWW, TCWR, PDRW, PDRR.
74 // If we find the first two:
75 // Remember which, and go to state 3.
76 // If we find either of the second two, go back to State 1.
77 // State 3: Looking for " at " in column 11.
78 // When found, extract the string betweeen '(' and ')',
79 // which is program name:line.
80 // OUTPUT LINE for an investigation.
81 // Go to State 0.
82
83 state = 0; // looking for PDRR, PDRW.
84 while (fgets(myLine, 16384, HELOUT) != NULL) {
85 if (strlen(myLine) < 20) continue;
86 switch (state) {
87 case 0: // Looking for PDRR or PRDW.
88 if (strstr(myLine, PDRR) != NULL) {
89 type1='R';
90 state=1;
91 continue;
92 }
93
94 if (strstr(myLine, PDRW) != NULL) {
95 type1='W';
96 state=1;
97 continue;
98 }
99
100 continue;
101 break;
102
103 case 1: // Looking for atSTR in column 11.
104 if (strncmp(myLine+10, atSTR, 6) != 0) continue;
105 paren1=strchr(myLine, '(');
106 paren2=strchr(myLine, ')');
107 if (paren1 == NULL || paren2 == NULL ||
108 paren1 > paren2) {
109 state=0; // Abort, found something I don't understand.
110 continue;
111 }
112
113 size = paren2-paren1-1; // compute length of name.
114 strncpy(fname1, paren1+1, size); // Copy the name.
115 fname1[size]=0; // install z-terminator.
116 state=2;
117 continue;
118 break;
119
120 case 2: // Looking for TCWW, TCWR, PDRR, PDRW.
121 if (strstr(myLine, TCWR) != NULL) {
122 type2='R';
123 state=3;
124 continue;
125 }
126
127 if (strstr(myLine, TCWW) != NULL) {
128 type2='W';
129 state=3;
130 continue;
131 }
132
133 if (strstr(myLine, PDRR) != NULL) {
134 type1='R';
135 state=1;
136 continue;
137 }
138
139 if (strstr(myLine, PDRW) != NULL) {
140 type1='W';
141 state=1;
142 continue;
143 }
144
145 continue;
146 break;
147
148 case 3: // Looking for atSTR in column 11.
149 if (strncmp(myLine+10, atSTR, 6) != 0) continue;
150 paren1=strchr(myLine, '(');
151 paren2=strchr(myLine, ')');
152 if (paren1 == NULL || paren2 == NULL ||
153 paren1 > paren2) {
154 state=0; // Abort, found something I don't understand.
155 continue;
156 }
157
158 size = paren2-paren1-1; // compute length of name.
159 strncpy(fname2, paren1+1, size); // Copy the name.
160 fname2[size]=0; // install z-terminator.
161 fprintf(stdout, "%c@%-32s %c@%-32s\n", type1, fname1, type2, fname2);
162 state=0;
163 continue;
164 break;
165 } // end switch.
166 } // end while.
167
168 fclose(HELOUT);
169 exit(0);
170}
FILE * stdout
FILE * stderr
int fclose(FILE *__stream)
bool state
Definition: papi_hl.c:155
Here is the call graph for this function: