diff options
author | Ingo Molnar <mingo@kernel.org> | 2014-12-12 09:09:52 +0100 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2014-12-12 09:09:52 +0100 |
commit | 41e950c033b7df997d4b38653efe6554be9b96a7 (patch) | |
tree | b8ffe779d47c768a9652ce9166f4878cee41f2ca /tools/lib | |
parent | 3459f0d78ffe27a1b341c22eb158b622eaaea3fc (diff) | |
parent | e09b18d4907992d3d615b215c1abf585721b2810 (diff) | |
download | linux-41e950c033b7df997d4b38653efe6554be9b96a7.tar.bz2 |
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
User visible changes:
- Mark events as (x86 only) in help output for 'perf kvm stat live" (Alexander Yarygin)
- Provide a better explanation when mmap fails in 'trace' (Arnaldo Carvalho de Melo)
- Add --buildid-dir option to set cache directory, i.e. use:
$ perf --buildid-dir /path/to/dir tool --tool-options
(Jiri Olsa)
- Fix memcpy/memset 'perf bench' output (Rabin Vicent)
- Fix 'perf test' attr tests size values to cope with machine state on
interrupt ABI changes (Jiri Olsa)
- Fixup callchain type parameter handling error message (Kan Liang)
Infrastructure changes and cleanups:
- calloc/xcalloc: Fix argument order (Arjun Sreedharan)
- Move filename__read_int from tools/perf/ to tools/lib, add sysctl__read_int
there and use it in place of ad-hoc copies (Arnaldo Carvalho de Melo)
- Use single strcmp call instead of two (Jiri Olsa)
- Remove extra debugdir variables in 'perf buildid-cache' (Jiri Olsa)
- Fix -a segfault related to kcore handling in 'perf buildid-cache' (Jiri Olsa)
- Move cpumode resolve code to add_callchain_ip (Kan Liang)
- Merge memset into memcpy 'perf bench' (Rabin Vincent)
- Change print format from %lu to %PRIu64 in the hists browser (Tom Huynh)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/api/fs/fs.c | 34 | ||||
-rw-r--r-- | tools/lib/api/fs/fs.h | 3 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index c1b49c36a951..65d9be3f9887 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c @@ -7,6 +7,10 @@ #include <stdlib.h> #include <string.h> #include <sys/vfs.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> #include "debugfs.h" #include "fs.h" @@ -163,3 +167,33 @@ const char *name##__mountpoint(void) \ FS__MOUNTPOINT(sysfs, FS__SYSFS); FS__MOUNTPOINT(procfs, FS__PROCFS); + +int filename__read_int(const char *filename, int *value) +{ + char line[64]; + int fd = open(filename, O_RDONLY), err = -1; + + if (fd < 0) + return -1; + + if (read(fd, line, sizeof(line)) > 0) { + *value = atoi(line); + err = 0; + } + + close(fd); + return err; +} + +int sysctl__read_int(const char *sysctl, int *value) +{ + char path[PATH_MAX]; + const char *procfs = procfs__mountpoint(); + + if (!procfs) + return -1; + + snprintf(path, sizeof(path), "%s/sys/%s", procfs, sysctl); + + return filename__read_int(path, value); +} diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h index cb7049551f33..6caa2bbc6cec 100644 --- a/tools/lib/api/fs/fs.h +++ b/tools/lib/api/fs/fs.h @@ -11,4 +11,7 @@ const char *sysfs__mountpoint(void); const char *procfs__mountpoint(void); + +int filename__read_int(const char *filename, int *value); +int sysctl__read_int(const char *sysctl, int *value); #endif /* __API_FS__ */ |