Skip to content

Commit 1f19712

Browse files
committed
core-ftrace: optimize ftrace parsing
parsing ftrace output is time consuming, so add -O3 and add likely branch hints based on Intel VTune profiling data. Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent 589aad1 commit 1f19712

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

core-ftrace.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void stress_ftrace_sig_handler(int sig)
206206
tracing_run = false;
207207
}
208208

209-
static void stress_ftrace_child(FILE *fp)
209+
static void OPTIMIZE3 stress_ftrace_child(FILE *fp)
210210
{
211211
char buf[1024];
212212
const pid_t my_pid = getpid();
@@ -237,7 +237,7 @@ static void stress_ftrace_child(FILE *fp)
237237

238238
/* skip over any leading spaces */
239239
ptr = buf;
240-
while (*ptr == ' ')
240+
while (LIKELY(*ptr == ' '))
241241
ptr++;
242242
if (!*ptr)
243243
continue;
@@ -249,10 +249,10 @@ static void stress_ftrace_child(FILE *fp)
249249
hyphen = NULL;
250250
while (*ptr == ' ')
251251
ptr++;
252-
if (!*ptr)
252+
if (UNLIKELY(!*ptr))
253253
continue;
254-
while ((ch = *ptr) && ch != ' ') {
255-
if (ch == '-')
254+
while ((ch = *ptr) && (LIKELY(ch != ' '))) {
255+
if (UNLIKELY(ch == '-'))
256256
hyphen = ptr;
257257
ptr++;
258258
}
@@ -268,21 +268,21 @@ static void stress_ftrace_child(FILE *fp)
268268
/* skip over [cpu] field */
269269
while (*ptr == ' ')
270270
ptr++;
271-
if (!*ptr)
271+
if (UNLIKELY(!*ptr))
272272
continue;
273-
while (*ptr != ' ')
273+
while (LIKELY(*ptr != ' '))
274274
ptr++;
275-
if (!*ptr)
275+
if (UNLIKELY(!*ptr))
276276
continue;
277277

278278
/* skip over ..... field */
279279
while (*ptr == ' ')
280280
ptr++;
281-
if (!*ptr)
281+
if (UNLIKELY(!*ptr))
282282
continue;
283-
while (*ptr != ' ')
283+
while (LIKELY(*ptr != ' '))
284284
ptr++;
285-
if (!*ptr)
285+
if (UNLIKELY(!*ptr))
286286
continue;
287287

288288
time_stamp = 0.0;
@@ -292,24 +292,24 @@ static void stress_ftrace_child(FILE *fp)
292292
/* skip over time stamp field */
293293
while (*ptr == ' ')
294294
ptr++;
295-
if (!*ptr)
295+
if (UNLIKELY(!*ptr))
296296
continue;
297-
while (*ptr != ' ')
297+
while (LIKELY(*ptr != ' '))
298298
ptr++;
299-
if (!*ptr)
299+
if (UNLIKELY(!*ptr))
300300
continue;
301301

302302
/* find syscall */
303-
while (*ptr == ' ')
303+
while (LIKELY(*ptr == ' '))
304304
ptr++;
305-
if (!*ptr)
305+
if (UNLIKELY(!*ptr))
306306
continue;
307307

308308
syscall_name = ptr;
309-
while ((ch = *ptr) && (ch != '(') && (ch != ' '))
309+
while ((ch = *ptr) && LIKELY(ch != '(') && LIKELY(ch != ' '))
310310
ptr++;
311311

312-
if (!ch)
312+
if (UNLIKELY(!ch))
313313
continue;
314314

315315
*ptr = '\0';

0 commit comments

Comments
 (0)