Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib api fs: Move tracing_path interface into api/fs/tracing_path.c

Moving tracing_path interface into api/fs/tracing_path.c out of util.c.
It seems generic enough to be used by others, and I couldn't think of
better place.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Matt Fleming <matt.fleming@intel.com>
Reviewed-by: Raphael Beamonte <raphael.beamonte@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1441180605-24737-5-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
592d5a6b 65d4b265

+101 -79
+1
tools/lib/api/fs/Build
··· 1 1 libapi-y += fs.o 2 + libapi-y += tracing_path.o 2 3 libapi-y += debugfs.o 3 4 libapi-y += findfs.o 4 5 libapi-y += tracefs.o
+83
tools/lib/api/fs/tracing_path.c
··· 1 + #ifndef _GNU_SOURCE 2 + # define _GNU_SOURCE 3 + #endif 4 + 5 + #include <stdio.h> 6 + #include <stdlib.h> 7 + #include <string.h> 8 + #include "debugfs.h" 9 + #include "tracefs.h" 10 + 11 + #include "tracing_path.h" 12 + 13 + 14 + char tracing_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing"; 15 + char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; 16 + 17 + 18 + static void __tracing_path_set(const char *tracing, const char *mountpoint) 19 + { 20 + snprintf(tracing_path, sizeof(tracing_path), "%s/%s", 21 + mountpoint, tracing); 22 + snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s", 23 + mountpoint, tracing, "events"); 24 + } 25 + 26 + static const char *tracing_path_tracefs_mount(void) 27 + { 28 + const char *mnt; 29 + 30 + mnt = tracefs_mount(NULL); 31 + if (!mnt) 32 + return NULL; 33 + 34 + __tracing_path_set("", mnt); 35 + 36 + return mnt; 37 + } 38 + 39 + static const char *tracing_path_debugfs_mount(void) 40 + { 41 + const char *mnt; 42 + 43 + mnt = debugfs_mount(NULL); 44 + if (!mnt) 45 + return NULL; 46 + 47 + __tracing_path_set("tracing/", mnt); 48 + 49 + return mnt; 50 + } 51 + 52 + const char *tracing_path_mount(void) 53 + { 54 + const char *mnt; 55 + 56 + mnt = tracing_path_tracefs_mount(); 57 + if (mnt) 58 + return mnt; 59 + 60 + mnt = tracing_path_debugfs_mount(); 61 + 62 + return mnt; 63 + } 64 + 65 + void tracing_path_set(const char *mntpt) 66 + { 67 + __tracing_path_set("tracing/", mntpt); 68 + } 69 + 70 + char *get_tracing_file(const char *name) 71 + { 72 + char *file; 73 + 74 + if (asprintf(&file, "%s/%s", tracing_path, name) < 0) 75 + return NULL; 76 + 77 + return file; 78 + } 79 + 80 + void put_tracing_file(char *file) 81 + { 82 + free(file); 83 + }
+13
tools/lib/api/fs/tracing_path.h
··· 1 + #ifndef __API_FS_TRACING_PATH_H 2 + #define __API_FS_TRACING_PATH_H 3 + 4 + extern char tracing_path[]; 5 + extern char tracing_events_path[]; 6 + 7 + void tracing_path_set(const char *mountpoint); 8 + const char *tracing_path_mount(void); 9 + 10 + char *get_tracing_file(const char *name); 11 + void put_tracing_file(char *file); 12 + 13 + #endif /* __API_FS_TRACING_PATH_H */
+1 -1
tools/perf/perf.c
··· 15 15 #include "util/parse-events.h" 16 16 #include "util/parse-options.h" 17 17 #include "util/debug.h" 18 - #include <api/fs/debugfs.h> 18 + #include <api/fs/tracing_path.h> 19 19 #include <pthread.h> 20 20 21 21 const char perf_usage_string[] =
+1 -1
tools/perf/util/parse-events.c
··· 11 11 #include "cache.h" 12 12 #include "header.h" 13 13 #include "debug.h" 14 - #include <api/fs/debugfs.h> 14 + #include <api/fs/tracing_path.h> 15 15 #include "parse-events-bison.h" 16 16 #define YY_EXTRA_TYPE int 17 17 #include "parse-events-flex.h"
+1 -1
tools/perf/util/trace-event-info.c
··· 38 38 39 39 #include "../perf.h" 40 40 #include "trace-event.h" 41 - #include <api/fs/debugfs.h> 41 + #include <api/fs/tracing_path.h> 42 42 #include "evsel.h" 43 43 #include "debug.h" 44 44
+1
tools/perf/util/trace-event.c
··· 8 8 #include <fcntl.h> 9 9 #include <linux/kernel.h> 10 10 #include <traceevent/event-parse.h> 11 + #include <api/fs/tracing_path.h> 11 12 #include "trace-event.h" 12 13 #include "machine.h" 13 14 #include "util.h"
-70
tools/perf/util/util.c
··· 34 34 bool perf_host = true; 35 35 bool perf_guest = false; 36 36 37 - char tracing_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing"; 38 - char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; 39 - 40 37 void event_attr_init(struct perf_event_attr *attr) 41 38 { 42 39 if (!perf_host) ··· 385 388 tc.c_cc[VMIN] = 0; 386 389 tc.c_cc[VTIME] = 0; 387 390 tcsetattr(0, TCSANOW, &tc); 388 - } 389 - 390 - static void __tracing_path_set(const char *tracing, const char *mountpoint) 391 - { 392 - snprintf(tracing_path, sizeof(tracing_path), "%s/%s", 393 - mountpoint, tracing); 394 - snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s", 395 - mountpoint, tracing, "events"); 396 - } 397 - 398 - static const char *tracing_path_tracefs_mount(void) 399 - { 400 - const char *mnt; 401 - 402 - mnt = tracefs_mount(NULL); 403 - if (!mnt) 404 - return NULL; 405 - 406 - __tracing_path_set("", mnt); 407 - 408 - return mnt; 409 - } 410 - 411 - static const char *tracing_path_debugfs_mount(void) 412 - { 413 - const char *mnt; 414 - 415 - mnt = debugfs_mount(NULL); 416 - if (!mnt) 417 - return NULL; 418 - 419 - __tracing_path_set("tracing/", mnt); 420 - 421 - return mnt; 422 - } 423 - 424 - const char *tracing_path_mount(void) 425 - { 426 - const char *mnt; 427 - 428 - mnt = tracing_path_tracefs_mount(); 429 - if (mnt) 430 - return mnt; 431 - 432 - mnt = tracing_path_debugfs_mount(); 433 - 434 - return mnt; 435 - } 436 - 437 - void tracing_path_set(const char *mntpt) 438 - { 439 - __tracing_path_set("tracing/", mntpt); 440 - } 441 - 442 - char *get_tracing_file(const char *name) 443 - { 444 - char *file; 445 - 446 - if (asprintf(&file, "%s/%s", tracing_path, name) < 0) 447 - return NULL; 448 - 449 - return file; 450 - } 451 - 452 - void put_tracing_file(char *file) 453 - { 454 - free(file); 455 391 } 456 392 457 393 int parse_nsec_time(const char *str, u64 *ptime)
-6
tools/perf/util/util.h
··· 83 83 extern const char *graph_line; 84 84 extern const char *graph_dotted_line; 85 85 extern char buildid_dir[]; 86 - extern char tracing_path[]; 87 - extern char tracing_events_path[]; 88 - extern void tracing_path_set(const char *mountpoint); 89 - const char *tracing_path_mount(void); 90 - char *get_tracing_file(const char *name); 91 - void put_tracing_file(char *file); 92 86 93 87 /* On most systems <limits.h> would have given us this, but 94 88 * not on some systems (e.g. GNU/Hurd).