2 #define _XOPEN_SOURCE 600
19 #define STR(x) _STR(x)
21 #define MARKER(str) write(marker_fd, str, strlen(str));
23 static const char *find_debugfs(void)
25 static char debugfs[MAX_PATH+1];
26 static int debugfs_found;
33 if ((fp = fopen("/proc/mounts","r")) == NULL)
36 while (fscanf(fp, "%*s %"
38 "s %99s %*s %*d %*d\n",
39 debugfs, type) == 2) {
40 if (strcmp(type, "debugfs") == 0)
45 if (strcmp(type, "debugfs") != 0)
56 char path[256], pid[10];
59 debugfs = find_debugfs();
61 strcpy(path, debugfs);
62 strcat(path,"/tracing/trace_marker");
63 marker_fd = open(path, O_WRONLY);
65 strcpy(path, debugfs);
66 strcat(path,"/tracing/set_ftrace_pid");
67 pid_fd = open(path, O_WRONLY);
68 sprintf(pid, "%d", getpid());
70 write(pid_fd, pid, strlen(pid));
72 strcpy(path, debugfs);
73 strcat(path,"/tracing/tracing_on");
74 trace_fd = open(path, O_WRONLY);
76 write(trace_fd, "1", 1);
84 size_t pagesize = sysconf(_SC_PAGESIZE);
86 buf = memalign(pagesize, pagesize);
88 error(1, errno, "memalign");
93 MARKER("Without O_DIRECT");
95 fd = open("file", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
97 error(1, errno, "open");
98 ret = write(fd, buf, 512);
100 error(1, errno, "write");
104 MARKER("With O_DIRECT");
106 fd = open("file", O_CREAT | O_TRUNC | O_WRONLY | O_DIRECT, S_IRUSR | S_IWUSR);
108 error(1, errno, "open");
109 ret = write(fd, buf, 512);
111 error(1, errno, "write");
115 MARKER("Without O_DIRECT and with posix_fadvise");
117 fd = open("file", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
119 error(1, errno, "open");
120 ret = write(fd, buf, 512);
122 error(1, errno, "write");
123 ret = posix_fadvise(fd, 0, 512, POSIX_FADV_DONTNEED);
125 error(1, ret, "posix_fadvise");
132 write(trace_fd, "0", 1);