[Powertop] [PATCH 01/10] tell user if the system is running out of FDs

Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
Newsgroups dev.linux.lists.powertop
Message-ID <[email protected]>
From: Jaroslav Skarvada <jskarvad(a)redhat.com>

From: Jaroslav Skarvada <jskarvad(a)redhat.com>

complex servers can run out of FDs easily (due to perf).
In such case tell user that more FDs are needed instead
of the generic message (that kernel doesn't support
the perf).
---
 src/perf/perf.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/perf/perf.cpp b/src/perf/perf.cpp
index e919741..b176256 100644
--- a/src/perf/perf.cpp
+++ b/src/perf/perf.cpp
@@ -26,6 +26,7 @@
 #include <iostream>
 #include <fstream>
 
+#include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -72,6 +73,7 @@ void perf_event::create_perf_event(char *eventname, int _cpu)
 {
 	struct perf_event_attr attr;
 	int ret;
+	int err;
 
 	struct {
 		__u64 count;
@@ -107,10 +109,15 @@ void perf_event::create_perf_event(char *eventname, int _cpu)
 	perf_fd = sys_perf_event_open(&attr, -1, _cpu, -1, 0);
 
 	if (perf_fd < 0) {
+		err = errno;
 		reset_display();
-		fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION);
-		fprintf(stderr, _("as well as support for trace points in the kernel:\n"));
-		fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n");
+		if (err == EMFILE)
+			fprintf(stderr, _("Too many open files, please increase the limit of open file descriptors.\n"));
+		else {
+			fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION);
+			fprintf(stderr, _("as well as support for trace points in the kernel:\n"));
+			fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n");
+		}
 		exit(EXIT_FAILURE);
 	}
 	if (read(perf_fd, &read_data, sizeof(read_data)) == -1) {
-- 
1.8.4.679.g0a1a803
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.