Skip to content

Commit 40c3c0c

Browse files
committed
tools lib api fs tracing_path: Introduce get/put_events_file() helpers
To make reading events files a tad more compact than with get_tracing_files("events/foo"). Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-do6xgtwpmfl8zjs1euxsd2du@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 17c257e commit 40c3c0c

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎tools/lib/api/fs/tracing_path.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ void put_tracing_file(char *file)
8686
free(file);
8787
}
8888

89+
char *get_events_file(const char *name)
90+
{
91+
char *file;
92+
93+
if (asprintf(&file, "%s/events/%s", tracing_path_mount(), name) < 0)
94+
return NULL;
95+
96+
return file;
97+
}
98+
99+
void put_events_file(char *file)
100+
{
101+
free(file);
102+
}
103+
89104
int tracing_path__strerror_open_tp(int err, char *buf, size_t size,
90105
const char *sys, const char *name)
91106
{

‎tools/lib/api/fs/tracing_path.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@ const char *tracing_path_mount(void);
1212
char *get_tracing_file(const char *name);
1313
void put_tracing_file(char *file);
1414

15+
char *get_events_file(const char *name);
16+
void put_events_file(char *file);
17+
18+
#define zput_events_file(ptr) ({ free(*ptr); *ptr = NULL; })
19+
1520
int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
1621
#endif /* __API_FS_TRACING_PATH_H */

‎tools/perf/util/trace-event-info.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ static int record_file(const char *file, ssize_t hdr_sz)
103103

104104
static int record_header_files(void)
105105
{
106-
char *path;
106+
char *path = get_events_file("header_page");
107107
struct stat st;
108108
int err = -EIO;
109109

110-
path = get_tracing_file("events/header_page");
111110
if (!path) {
112111
pr_debug("can't get tracing/events/header_page");
113112
return -ENOMEM;
@@ -128,9 +127,9 @@ static int record_header_files(void)
128127
goto out;
129128
}
130129

131-
put_tracing_file(path);
130+
put_events_file(path);
132131

133-
path = get_tracing_file("events/header_event");
132+
path = get_events_file("header_event");
134133
if (!path) {
135134
pr_debug("can't get tracing/events/header_event");
136135
err = -ENOMEM;
@@ -154,7 +153,7 @@ static int record_header_files(void)
154153

155154
err = 0;
156155
out:
157-
put_tracing_file(path);
156+
put_events_file(path);
158157
return err;
159158
}
160159

@@ -243,7 +242,7 @@ static int record_ftrace_files(struct tracepoint_path *tps)
243242
char *path;
244243
int ret;
245244

246-
path = get_tracing_file("events/ftrace");
245+
path = get_events_file("ftrace");
247246
if (!path) {
248247
pr_debug("can't get tracing/events/ftrace");
249248
return -ENOMEM;

0 commit comments

Comments
 (0)