diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2017-12-19 00:15:44 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2017-12-19 00:15:44 +0000 |
| commit | 46db367db704da87e4beb29db84a0e4978d93235 (patch) | |
| tree | b1468abd0fb478cd8df32e3565948f61ede35a46 /trace/ftrace.c | |
| parent | eaefea537b476cb853e2edbdc68e969ec777e4bb (diff) | |
| parent | 5c9522b358faf9688fd83cd0a881e1990bb84516 (diff) | |
| download | focaccia-qemu-46db367db704da87e4beb29db84a0e4978d93235.tar.gz focaccia-qemu-46db367db704da87e4beb29db84a0e4978d93235.zip | |
Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging
# gpg: Signature made Mon 18 Dec 2017 14:47:53 GMT # gpg: using RSA key 0x9CA4ABB381AB73C8 # gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" # gpg: aka "Stefan Hajnoczi <stefanha@gmail.com>" # Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35 775A 9CA4 ABB3 81AB 73C8 * remotes/stefanha/tags/tracing-pull-request: gdbstub: add tracing trace: Try using tracefs first trace: Generalize searching for debugfs trace: Simplify find_debugfs() Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'trace/ftrace.c')
| -rw-r--r-- | trace/ftrace.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/trace/ftrace.c b/trace/ftrace.c index 7de104deba..61692a8682 100644 --- a/trace/ftrace.c +++ b/trace/ftrace.c @@ -15,10 +15,11 @@ int trace_marker_fd; -static int find_debugfs(char *debugfs) +static int find_mount(char *mount_point, const char *fstype) { char type[100]; FILE *fp; + int ret = 0; fp = fopen("/proc/mounts", "r"); if (fp == NULL) { @@ -26,29 +27,33 @@ static int find_debugfs(char *debugfs) } while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", - debugfs, type) == 2) { - if (strcmp(type, "debugfs") == 0) { + mount_point, type) == 2) { + if (strcmp(type, fstype) == 0) { + ret = 1; break; } } fclose(fp); - if (strcmp(type, "debugfs") != 0) { - return 0; - } - return 1; + return ret; } bool ftrace_init(void) { - char debugfs[PATH_MAX]; + char mount_point[PATH_MAX]; char path[PATH_MAX]; - int debugfs_found; + int tracefs_found; int trace_fd = -1; + const char *subdir = ""; + + tracefs_found = find_mount(mount_point, "tracefs"); + if (!tracefs_found) { + tracefs_found = find_mount(mount_point, "debugfs"); + subdir = "/tracing"; + } - debugfs_found = find_debugfs(debugfs); - if (debugfs_found) { - snprintf(path, PATH_MAX, "%s/tracing/tracing_on", debugfs); + if (tracefs_found) { + snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir); trace_fd = open(path, O_WRONLY); if (trace_fd < 0) { if (errno == EACCES) { @@ -67,14 +72,14 @@ bool ftrace_init(void) } close(trace_fd); } - snprintf(path, PATH_MAX, "%s/tracing/trace_marker", debugfs); + snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir); trace_marker_fd = open(path, O_WRONLY); if (trace_marker_fd < 0) { perror("Could not open ftrace 'trace_marker' file"); return false; } } else { - fprintf(stderr, "debugfs is not mounted\n"); + fprintf(stderr, "tracefs is not mounted\n"); return false; } |