diff options
author | Taeung Song <treeze.taeung@gmail.com> | 2017-01-31 06:38:28 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-01-31 14:20:08 -0500 |
commit | 43d41deb71fe1850264e5dd8109211683954ea14 (patch) | |
tree | 7f1ce9c0a9c8e5e635a1fc880db331d4d1a59b61 | |
parent | a26305363d4b3a586a2d3554c22705538aa4e926 (diff) |
perf tools: Create for_each_event macro for tracepoints iteration
Similar to for_each_subsystem and for_each_event in util/parse-events.c,
add new macro 'for_each_event' for easy iteration over the tracepoints
in order to be more compact and readable.
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1485862711-20216-2-git-send-email-treeze.taeung@gmail.com
[ Slight change to keep existing style for checking strcmp() return ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/trace-event-info.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index ceb0e2720223..e7d60d05596d 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
@@ -170,6 +170,12 @@ static bool name_in_tp_list(char *sys, struct tracepoint_path *tps) | |||
170 | return false; | 170 | return false; |
171 | } | 171 | } |
172 | 172 | ||
173 | #define for_each_event(dir, dent, tps) \ | ||
174 | while ((dent = readdir(dir))) \ | ||
175 | if (dent->d_type == DT_DIR && \ | ||
176 | (strcmp(dent->d_name, ".")) && \ | ||
177 | (strcmp(dent->d_name, ".."))) \ | ||
178 | |||
173 | static int copy_event_system(const char *sys, struct tracepoint_path *tps) | 179 | static int copy_event_system(const char *sys, struct tracepoint_path *tps) |
174 | { | 180 | { |
175 | struct dirent *dent; | 181 | struct dirent *dent; |
@@ -186,12 +192,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps) | |||
186 | return -errno; | 192 | return -errno; |
187 | } | 193 | } |
188 | 194 | ||
189 | while ((dent = readdir(dir))) { | 195 | for_each_event(dir, dent, tps) { |
190 | if (dent->d_type != DT_DIR || | 196 | if (!name_in_tp_list(dent->d_name, tps)) |
191 | strcmp(dent->d_name, ".") == 0 || | ||
192 | strcmp(dent->d_name, "..") == 0 || | ||
193 | !name_in_tp_list(dent->d_name, tps)) | ||
194 | continue; | 197 | continue; |
198 | |||
195 | if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) { | 199 | if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) { |
196 | err = -ENOMEM; | 200 | err = -ENOMEM; |
197 | goto out; | 201 | goto out; |
@@ -210,12 +214,10 @@ static int copy_event_system(const char *sys, struct tracepoint_path *tps) | |||
210 | } | 214 | } |
211 | 215 | ||
212 | rewinddir(dir); | 216 | rewinddir(dir); |
213 | while ((dent = readdir(dir))) { | 217 | for_each_event(dir, dent, tps) { |
214 | if (dent->d_type != DT_DIR || | 218 | if (!name_in_tp_list(dent->d_name, tps)) |
215 | strcmp(dent->d_name, ".") == 0 || | ||
216 | strcmp(dent->d_name, "..") == 0 || | ||
217 | !name_in_tp_list(dent->d_name, tps)) | ||
218 | continue; | 219 | continue; |
220 | |||
219 | if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) { | 221 | if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) { |
220 | err = -ENOMEM; | 222 | err = -ENOMEM; |
221 | goto out; | 223 | goto out; |
@@ -290,13 +292,11 @@ static int record_event_files(struct tracepoint_path *tps) | |||
290 | goto out; | 292 | goto out; |
291 | } | 293 | } |
292 | 294 | ||
293 | while ((dent = readdir(dir))) { | 295 | for_each_event(dir, dent, tps) { |
294 | if (dent->d_type != DT_DIR || | 296 | if (strcmp(dent->d_name, "ftrace") == 0 || |
295 | strcmp(dent->d_name, ".") == 0 || | ||
296 | strcmp(dent->d_name, "..") == 0 || | ||
297 | strcmp(dent->d_name, "ftrace") == 0 || | ||
298 | !system_in_tp_list(dent->d_name, tps)) | 297 | !system_in_tp_list(dent->d_name, tps)) |
299 | continue; | 298 | continue; |
299 | |||
300 | count++; | 300 | count++; |
301 | } | 301 | } |
302 | 302 | ||
@@ -307,13 +307,11 @@ static int record_event_files(struct tracepoint_path *tps) | |||
307 | } | 307 | } |
308 | 308 | ||
309 | rewinddir(dir); | 309 | rewinddir(dir); |
310 | while ((dent = readdir(dir))) { | 310 | for_each_event(dir, dent, tps) { |
311 | if (dent->d_type != DT_DIR || | 311 | if (strcmp(dent->d_name, "ftrace") == 0 || |
312 | strcmp(dent->d_name, ".") == 0 || | ||
313 | strcmp(dent->d_name, "..") == 0 || | ||
314 | strcmp(dent->d_name, "ftrace") == 0 || | ||
315 | !system_in_tp_list(dent->d_name, tps)) | 312 | !system_in_tp_list(dent->d_name, tps)) |
316 | continue; | 313 | continue; |
314 | |||
317 | if (asprintf(&sys, "%s/%s", path, dent->d_name) < 0) { | 315 | if (asprintf(&sys, "%s/%s", path, dent->d_name) < 0) { |
318 | err = -ENOMEM; | 316 | err = -ENOMEM; |
319 | goto out; | 317 | goto out; |