4 * Copyright (C) 2013 Hitachi, Ltd.
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"
14 #include "trace/control.h"
18 static int find_debugfs(char *debugfs)
23 fp = fopen("/proc/mounts", "r");
28 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
29 debugfs, type) == 2) {
30 if (strcmp(type, "debugfs") == 0) {
36 if (strcmp(type, "debugfs") != 0) {
42 bool ftrace_init(void)
44 char debugfs[PATH_MAX];
49 debugfs_found = find_debugfs(debugfs);
51 snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs);
52 trace_fd = open(path, O_WRONLY);
54 if (errno == EACCES) {
55 trace_marker_fd = open("/dev/null", O_WRONLY);
56 if (trace_marker_fd != -1) {
60 perror("Could not open ftrace 'tracing_on' file");
63 if (write(trace_fd, "1", 1) < 0) {
64 perror("Could not write to 'tracing_on' file");
70 snprintf(path, PATH_MAX, "%s/tracing/trace_marker", debugfs);
71 trace_marker_fd = open(path, O_WRONLY);
72 if (trace_marker_fd < 0) {
73 perror("Could not open ftrace 'trace_marker' file");
77 fprintf(stderr, "debugfs is not mounted\n");