mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
	Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 01/25] perf top: Stop using exit()
Date: Thu, 31 Jan 2013 14:25:04 -0300	[thread overview]
Message-ID: <1359653128-10433-2-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1359653128-10433-1-git-send-email-acme@infradead.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Just return to the perf main() routine so that an unified exit path can
be followed and resources released, helping in finding memory leaks.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ro8oeodo96490nrhcph57atr@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-top.c | 56 ++++++++++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 23 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 7978c81..903e4f4 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -68,6 +68,8 @@
 #include <linux/unistd.h>
 #include <linux/types.h>
 
+static volatile int done;
+
 static void perf_top__update_print_entries(struct perf_top *top)
 {
 	if (top->print_entries > 9)
@@ -431,8 +433,10 @@ static int perf_top__key_mapped(struct perf_top *top, int c)
 	return 0;
 }
 
-static void perf_top__handle_keypress(struct perf_top *top, int c)
+static bool perf_top__handle_keypress(struct perf_top *top, int c)
 {
+	bool ret = true;
+
 	if (!perf_top__key_mapped(top, c)) {
 		struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
 		struct termios tc, save;
@@ -453,7 +457,7 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
 
 		tcsetattr(0, TCSAFLUSH, &save);
 		if (!perf_top__key_mapped(top, c))
-			return;
+			return ret;
 	}
 
 	switch (c) {
@@ -515,7 +519,8 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
 			printf("exiting.\n");
 			if (top->dump_symtab)
 				perf_session__fprintf_dsos(top->session, stderr);
-			exit(0);
+			ret = false;
+			break;
 		case 's':
 			perf_top__prompt_symbol(top, "Enter details symbol");
 			break;
@@ -538,6 +543,8 @@ static void perf_top__handle_keypress(struct perf_top *top, int c)
 		default:
 			break;
 	}
+
+	return ret;
 }
 
 static void perf_top__sort_new_samples(void *arg)
@@ -579,8 +586,7 @@ static void *display_thread_tui(void *arg)
 	perf_evlist__tui_browse_hists(top->evlist, help, &hbt,
 				      &top->session->header.env);
 
-	exit_browser(0);
-	exit(0);
+	done = 1;
 	return NULL;
 }
 
@@ -604,7 +610,7 @@ repeat:
 	/* trash return*/
 	getc(stdin);
 
-	while (1) {
+	while (!done) {
 		perf_top__print_sym_table(top);
 		/*
 		 * Either timeout expired or we got an EINTR due to SIGWINCH,
@@ -618,15 +624,14 @@ repeat:
 				continue;
 			/* Fall trhu */
 		default:
-			goto process_hotkey;
+			c = getc(stdin);
+			tcsetattr(0, TCSAFLUSH, &save);
+
+			if (perf_top__handle_keypress(top, c))
+				goto repeat;
+			done = 1;
 		}
 	}
-process_hotkey:
-	c = getc(stdin);
-	tcsetattr(0, TCSAFLUSH, &save);
-
-	perf_top__handle_keypress(top, c);
-	goto repeat;
 
 	return NULL;
 }
@@ -705,7 +710,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 	}
 
 	if (!machine) {
-		pr_err("%u unprocessable samples recorded.\n",
+		pr_err("%u unprocessable samples recorded.\r",
 		       top->session->stats.nr_unprocessable_samples++);
 		return;
 	}
@@ -868,7 +873,7 @@ static void perf_top__mmap_read(struct perf_top *top)
 		perf_top__mmap_read_idx(top, i);
 }
 
-static void perf_top__start_counters(struct perf_top *top)
+static int perf_top__start_counters(struct perf_top *top)
 {
 	char msg[512];
 	struct perf_evsel *counter;
@@ -900,11 +905,10 @@ try_again:
 		goto out_err;
 	}
 
-	return;
+	return 0;
 
 out_err:
-	exit_browser(0);
-	exit(0);
+	return -1;
 }
 
 static int perf_top__setup_sample_type(struct perf_top *top)
@@ -948,7 +952,11 @@ static int __cmd_top(struct perf_top *top)
 	else
 		perf_event__synthesize_threads(&top->tool, perf_event__process,
 					       &top->session->machines.host);
-	perf_top__start_counters(top);
+
+	ret = perf_top__start_counters(top);
+	if (ret)
+		goto out_delete;
+
 	top->session->evlist = top->evlist;
 	perf_session__set_id_hdr_size(top->session);
 
@@ -968,10 +976,11 @@ static int __cmd_top(struct perf_top *top)
 
 	perf_top__mmap_read(top);
 
+	ret = -1;
 	if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui :
 							    display_thread), top)) {
 		ui__error("Could not create display thread.\n");
-		exit(-1);
+		goto out_delete;
 	}
 
 	if (top->realtime_prio) {
@@ -980,11 +989,11 @@ static int __cmd_top(struct perf_top *top)
 		param.sched_priority = top->realtime_prio;
 		if (sched_setscheduler(0, SCHED_FIFO, &param)) {
 			ui__error("Could not set realtime priority.\n");
-			exit(-1);
+			goto out_delete;
 		}
 	}
 
-	while (1) {
+	while (!done) {
 		u64 hits = top->samples;
 
 		perf_top__mmap_read(top);
@@ -993,11 +1002,12 @@ static int __cmd_top(struct perf_top *top)
 			ret = poll(top->evlist->pollfd, top->evlist->nr_fds, 100);
 	}
 
+	ret = 0;
 out_delete:
 	perf_session__delete(top->session);
 	top->session = NULL;
 
-	return 0;
+	return ret;
 }
 
 static int
-- 
1.8.1.1.361.gec3ae6e


  reply	other threads:[~2013-01-31 17:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-31 17:25 [GIT PULL 00/25] perf/core improvements and fixes Arnaldo Carvalho de Melo
2013-01-31 17:25 ` Arnaldo Carvalho de Melo [this message]
2013-01-31 17:25 ` [PATCH 02/25] perf top: Delete maps on exit Arnaldo Carvalho de Melo
2013-01-31 18:14   ` David Ahern
2013-01-31 19:05     ` Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 03/25] perf tools: Keep group information Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 04/25] perf tests: Add group test conditions Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 05/25] perf header: Add HEADER_GROUP_DESC feature Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 06/25] perf report: Make another loop for linking group hists Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 07/25] perf hists: Resort hist entries using group members for output Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 08/25] perf ui/hist: Consolidate hpp helpers Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 09/25] perf hists browser: Convert hpp helpers to a function Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 10/25] perf gtk/browser: " Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 11/25] perf ui/hist: Add support for event group view Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 12/25] perf hists browser: Move coloring logic to hpp functions Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 13/25] perf hists browser: Add suppport for event group view Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 14/25] perf gtk/browser: Add support " Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 15/25] perf gtk/browser: Trim column header string when event group enabled Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 16/25] perf report: Bypass non-leader events when event group is enabled Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 17/25] perf report: Show group description " Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 18/25] perf report: Add --group option Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 19/25] perf report: Add report.group config option Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 20/25] perf evlist: Add --group option Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 21/25] perf/Power7: Use macros to identify perf events Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 22/25] perf: Make EVENT_ATTR global Arnaldo Carvalho de Melo
2013-02-01 10:26   ` Ingo Molnar
2013-01-31 17:25 ` [PATCH 23/25] perf/POWER7: Make generic event translations available in sysfs Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 24/25] perf/POWER7: Make some POWER7 events " Arnaldo Carvalho de Melo
2013-01-31 17:25 ` [PATCH 25/25] perf: Document the ABI of perf sysfs entries Arnaldo Carvalho de Melo
2013-02-01 10:18 ` [GIT PULL 00/25] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1359653128-10433-2-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=efault@gmx.de \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®