]>
Commit | Line | Data |
---|---|---|
781e9545 ET |
1 | /* |
2 | * Ftrace trace backend | |
3 | * | |
4 | * Copyright (C) 2013 Hitachi, Ltd. | |
5 | * Created by Eiichi Tsukata <eiichi.tsukata.xh@hitachi.com> | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
8 | * the COPYING file in the top-level directory. | |
9 | * | |
10 | */ | |
11 | ||
d38ea87a | 12 | #include "qemu/osdep.h" |
781e9545 | 13 | #include "trace/control.h" |
0ab8ed18 | 14 | #include "trace/ftrace.h" |
781e9545 ET |
15 | |
16 | int trace_marker_fd; | |
17 | ||
18 | static int find_debugfs(char *debugfs) | |
19 | { | |
20 | char type[100]; | |
21 | FILE *fp; | |
5070570c | 22 | int ret = 0; |
781e9545 ET |
23 | |
24 | fp = fopen("/proc/mounts", "r"); | |
25 | if (fp == NULL) { | |
26 | return 0; | |
27 | } | |
28 | ||
29 | while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", | |
30 | debugfs, type) == 2) { | |
31 | if (strcmp(type, "debugfs") == 0) { | |
5070570c | 32 | ret = 1; |
781e9545 ET |
33 | break; |
34 | } | |
35 | } | |
36 | fclose(fp); | |
37 | ||
5070570c | 38 | return ret; |
781e9545 ET |
39 | } |
40 | ||
5b808275 | 41 | bool ftrace_init(void) |
781e9545 ET |
42 | { |
43 | char debugfs[PATH_MAX]; | |
44 | char path[PATH_MAX]; | |
45 | int debugfs_found; | |
46 | int trace_fd = -1; | |
47 | ||
781e9545 ET |
48 | debugfs_found = find_debugfs(debugfs); |
49 | if (debugfs_found) { | |
50 | snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs); | |
51 | trace_fd = open(path, O_WRONLY); | |
52 | if (trace_fd < 0) { | |
8ed53728 DB |
53 | if (errno == EACCES) { |
54 | trace_marker_fd = open("/dev/null", O_WRONLY); | |
55 | if (trace_marker_fd != -1) { | |
56 | return true; | |
57 | } | |
58 | } | |
781e9545 ET |
59 | perror("Could not open ftrace 'tracing_on' file"); |
60 | return false; | |
61 | } else { | |
62 | if (write(trace_fd, "1", 1) < 0) { | |
63 | perror("Could not write to 'tracing_on' file"); | |
64 | close(trace_fd); | |
65 | return false; | |
66 | } | |
67 | close(trace_fd); | |
68 | } | |
69 | snprintf(path, PATH_MAX, "%s/tracing/trace_marker", debugfs); | |
70 | trace_marker_fd = open(path, O_WRONLY); | |
71 | if (trace_marker_fd < 0) { | |
72 | perror("Could not open ftrace 'trace_marker' file"); | |
73 | return false; | |
74 | } | |
75 | } else { | |
76 | fprintf(stderr, "debugfs is not mounted\n"); | |
77 | return false; | |
78 | } | |
79 | ||
781e9545 ET |
80 | return true; |
81 | } |