4 * Copyright (C) 2013 Hitachi, Ltd.
5 * Created by Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com>
7 * This work is licensed under the terms of the GNU GPL, version 2. See
8 * the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "trace/control.h"
14 #include "trace/ftrace.h"
18 static int find_mount(char *mount_point
, const char *fstype
)
24 fp
= fopen("/proc/mounts", "r");
29 while (fscanf(fp
, "%*s %" STR(PATH_MAX
) "s %99s %*s %*d %*d\n",
30 mount_point
, type
) == 2) {
31 if (strcmp(type
, fstype
) == 0) {
41 bool ftrace_init(void)
43 char mount_point
[PATH_MAX
];
48 debugfs_found
= find_mount(mount_point
, "debugfs");
50 snprintf(path
, PATH_MAX
, "%s/tracing/tracing_on", mount_point
);
51 trace_fd
= open(path
, O_WRONLY
);
53 if (errno
== EACCES
) {
54 trace_marker_fd
= open("/dev/null", O_WRONLY
);
55 if (trace_marker_fd
!= -1) {
59 perror("Could not open ftrace 'tracing_on' file");
62 if (write(trace_fd
, "1", 1) < 0) {
63 perror("Could not write to 'tracing_on' file");
69 snprintf(path
, PATH_MAX
, "%s/tracing/trace_marker", mount_point
);
70 trace_marker_fd
= open(path
, O_WRONLY
);
71 if (trace_marker_fd
< 0) {
72 perror("Could not open ftrace 'trace_marker' file");
76 fprintf(stderr
, "debugfs is not mounted\n");