28 #include <sys/types.h> 35 #include <linux/list.h> 36 #include <linux/kernel.h> 40 #include <api/fs/tracing_path.h> 51 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
54 ptr = (
unsigned int *)(
void *)
str;
55 return *ptr == 0x01020304;
61 unsigned long long size = 0;
62 char buf[BUFSIZ], *sizep;
63 off_t hdr_pos = lseek(
output_fd, 0, SEEK_CUR);
67 fd = open(file, O_RDONLY);
75 if (write(
output_fd, &size, hdr_sz) != hdr_sz)
80 r = read(fd, buf, BUFSIZ);
91 sizep +=
sizeof(u64) - hdr_sz;
93 if (hdr_sz && pwrite(
output_fd, sizep, hdr_sz, hdr_pos) < 0) {
94 pr_debug(
"writing file size failed\n");
106 char *path = get_events_file(
"header_page");
111 pr_debug(
"can't get tracing/events/header_page");
115 if (stat(path, &st) < 0) {
120 if (write(
output_fd,
"header_page", 12) != 12) {
121 pr_debug(
"can't write header_page\n");
126 pr_debug(
"can't record header_page file\n");
130 put_events_file(path);
132 path = get_events_file(
"header_event");
134 pr_debug(
"can't get tracing/events/header_event");
139 if (stat(path, &st) < 0) {
144 if (write(
output_fd,
"header_event", 13) != 13) {
145 pr_debug(
"can't write header_event\n");
150 pr_debug(
"can't record header_event file\n");
156 put_events_file(path);
163 if (!strcmp(sys, tps->
name))
171 #define for_each_event(dir, dent, tps) \ 172 while ((dent = readdir(dir))) \ 173 if (dent->d_type == DT_DIR && \ 174 (strcmp(dent->d_name, ".")) && \ 175 (strcmp(dent->d_name, ".."))) \ 189 pr_debug(
"can't read directory '%s'", sys);
197 if (asprintf(&format,
"%s/%s/format", sys, dent->d_name) < 0) {
201 ret = stat(format, &st);
219 if (asprintf(&format,
"%s/%s/format", sys, dent->d_name) < 0) {
223 ret = stat(format, &st);
245 path = get_events_file(
"ftrace");
247 pr_debug(
"can't get tracing/events/ftrace");
253 put_tracing_file(path);
261 if (!strcmp(sys, tps->
system))
280 path = get_tracing_file(
"events");
282 pr_debug(
"can't get tracing/events");
289 pr_debug(
"can't read directory '%s'", path);
294 if (strcmp(dent->d_name,
"ftrace") == 0 ||
309 if (strcmp(dent->d_name,
"ftrace") == 0 ||
313 if (asprintf(&sys,
"%s/%s", path, dent->d_name) < 0) {
317 ret = stat(sys, &st);
319 ssize_t
size = strlen(dent->d_name) + 1;
321 if (write(
output_fd, dent->d_name, size) != size ||
333 put_tracing_file(path);
340 unsigned long long size = 0;
347 return write(
output_fd, &size, 4) != 4 ? -EIO : 0;
357 path = get_tracing_file(
"printk_formats");
359 pr_debug(
"can't get tracing/printk_formats");
363 ret = stat(path, &st);
374 put_tracing_file(path);
385 path = get_tracing_file(
"saved_cmdlines");
387 pr_debug(
"can't get tracing/saved_cmdline");
391 ret = stat(path, &st);
402 put_tracing_file(path);
424 int nr_tracepoints = 0;
426 list_for_each_entry(pos, pattrs,
node) {
427 if (pos->
attr.type != PERF_TYPE_TRACEPOINT)
436 if (strchr(pos->
name,
':') == NULL)
446 pr_debug(
"No memory to alloc tracepoints list\n");
454 return nr_tracepoints > 0 ? path.
next : NULL;
461 list_for_each_entry(pos, pattrs,
node)
462 if (pos->
attr.type == PERF_TYPE_TRACEPOINT)
477 memcpy(buf + 3,
"tracing", 7);
496 buf[0] =
sizeof(long);
520 tdata =
malloc(
sizeof(*tdata));
537 temp_fd = open(tdata->
temp_file, O_RDWR);
static int record_ftrace_files(struct tracepoint_path *tps)
int read_tracing_data(int fd, struct list_head *pattrs)
static struct tracepoint_path * get_tracepoints_path(struct list_head *pattrs)
static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
static int record_event_files(struct tracepoint_path *tps)
static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
static int record_ftrace_printk(void)
static int record_proc_kallsyms(void)
int tracing_data_put(struct tracing_data *tdata)
struct tracepoint_path * next
struct tracepoint_path * tracepoint_id_to_path(u64 config)
static int copy_event_system(const char *sys, struct tracepoint_path *tps)
#define pr_debug(fmt,...)
bool have_tracepoints(struct list_head *pattrs)
static void put_tracepoints_path(struct tracepoint_path *tps)
#define for_each_event(dir, dent, tps)
static int str(yyscan_t scanner, int token)
static int tracing_data_header(void)
struct tracepoint_path * tracepoint_name_to_path(const char *name)
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms
static int record_saved_cmdline(void)
struct tracing_data * tracing_data_get(struct list_head *pattrs, int fd, bool temp)
static int record_header_files(void)
struct perf_event_attr attr
static int record_file(const char *file, ssize_t hdr_sz)