]> git.proxmox.com Git - mirror_qemu.git/blame - trace/ftrace.c
rbd: Clean up after the previous commit
[mirror_qemu.git] / trace / ftrace.c
CommitLineData
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
16int trace_marker_fd;
17
18static int find_debugfs(char *debugfs)
19{
20 char type[100];
21 FILE *fp;
22
23 fp = fopen("/proc/mounts", "r");
24 if (fp == NULL) {
25 return 0;
26 }
27
28 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
29 debugfs, type) == 2) {
30 if (strcmp(type, "debugfs") == 0) {
31 break;
32 }
33 }
34 fclose(fp);
35
36 if (strcmp(type, "debugfs") != 0) {
37 return 0;
38 }
39 return 1;
40}
41
5b808275 42bool ftrace_init(void)
781e9545
ET
43{
44 char debugfs[PATH_MAX];
45 char path[PATH_MAX];
46 int debugfs_found;
47 int trace_fd = -1;
48
781e9545
ET
49 debugfs_found = find_debugfs(debugfs);
50 if (debugfs_found) {
51 snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs);
52 trace_fd = open(path, O_WRONLY);
53 if (trace_fd < 0) {
8ed53728
DB
54 if (errno == EACCES) {
55 trace_marker_fd = open("/dev/null", O_WRONLY);
56 if (trace_marker_fd != -1) {
57 return true;
58 }
59 }
781e9545
ET
60 perror("Could not open ftrace 'tracing_on' file");
61 return false;
62 } else {
63 if (write(trace_fd, "1", 1) < 0) {
64 perror("Could not write to 'tracing_on' file");
65 close(trace_fd);
66 return false;
67 }
68 close(trace_fd);
69 }
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");
74 return false;
75 }
76 } else {
77 fprintf(stderr, "debugfs is not mounted\n");
78 return false;
79 }
80
781e9545
ET
81 return true;
82}