Skip to contentSkip to conversation

tools lib fs: Add sysctl__read_int helper

tip:perf/urgent tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Dec 12, 2014

lore
Share & tools
lore
#0 lore raw
Commit-ID:  42e3c4a1274d49b42e9d4306ec096b282a6e14aa
Gitweb:     http://git.kernel.org/tip/42e3c4a1274d49b42e9d4306ec096b282a6e14aa
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 11 Dec 2014 13:37:10 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 11 Dec 2014 17:53:00 -0300

tools lib fs: Add sysctl__read_int helper

Will come in handy for tools, see next patches.

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Don Zickus <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/lib/api/fs/fs.c | 13 +++++++++++++
 tools/lib/api/fs/fs.h |  1 +
 2 files changed, 14 insertions(+)
tools/lib/api/fs/fs.c +13 -0
index b8d0df8..65d9be3 100644
@@ -184,3 +184,16 @@ int filename__read_int(const char *filename, int *value)
 	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);
+}
tools/lib/api/fs/fs.h +1 -0
index 4d0aef6..6caa2bb 100644
@@ -13,4 +13,5 @@ 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__ */