linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 12/13] perf tools: replace on_exit with atexit
@ 2012-08-28 22:06 Irina Tirdea
  2012-08-29 16:59 ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Irina Tirdea @ 2012-08-28 22:06 UTC (permalink / raw)
  To: Steven Rostedt, Arnaldo Carvalho de Melo, Ingo Molnar
  Cc: LKML, Namhyung Kim, Peter Zijlstra, Frederic Weisbecker

on_exit() is only available in new versions of glibc.
Using on_exit on Android leads to errors at compile time.

Replacing on_exit with its more portable version atexit.
This leads to using a global variable since on_exit supports
sending a parameters while atexit does not.

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
 tools/perf/builtin-record.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3fc9bf9..f5daedf 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -66,6 +66,9 @@ struct perf_record {
     off_t            post_processing_offset;
 };

+/* for atexit */
+static struct perf_record *saved_rec;
+
 static void advance_output(struct perf_record *rec, size_t size)
 {
     rec->bytes_written += size;
@@ -143,9 +146,9 @@ static void sig_handler(int sig)
     signr = sig;
 }

-static void perf_record__sig_exit(int exit_status __maybe_unused, void *arg)
+static void perf_record__sig_exit(void)
 {
-    struct perf_record *rec = arg;
+    struct perf_record *rec = saved_rec;
     int status;

     if (rec->evlist->workload.pid > 0) {
@@ -335,9 +338,9 @@ static int process_buildids(struct perf_record *rec)
                           size, &build_id__mark_dso_hit_ops);
 }

-static void perf_record__exit(int status __maybe_unused, void *arg)
+static void perf_record__exit(void)
 {
-    struct perf_record *rec = arg;
+    struct perf_record *rec = saved_rec;

     if (!rec->opts.pipe_output) {
         rec->session->header.data_size += rec->bytes_written;
@@ -424,7 +427,8 @@ static int __cmd_record(struct perf_record *rec,
int argc, const char **argv)

     rec->page_size = sysconf(_SC_PAGE_SIZE);

-    on_exit(perf_record__sig_exit, rec);
+    saved_rec = rec;
+    atexit(perf_record__sig_exit);
     signal(SIGCHLD, sig_handler);
     signal(SIGINT, sig_handler);
     signal(SIGUSR1, sig_handler);
@@ -508,7 +512,7 @@ static int __cmd_record(struct perf_record *rec,
int argc, const char **argv)
     /*
      * perf_session__delete(session) will be called at perf_record__exit()
      */
-    on_exit(perf_record__exit, rec);
+    atexit(perf_record__exit);

     if (opts->pipe_output) {
         err = perf_header__write_pipe(output);
--
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 12/13] perf tools: replace on_exit with atexit
  2012-08-28 22:06 [PATCH 12/13] perf tools: replace on_exit with atexit Irina Tirdea
@ 2012-08-29 16:59 ` David Ahern
  2012-09-02 20:30   ` Irina Tirdea
  0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2012-08-29 16:59 UTC (permalink / raw)
  To: Irina Tirdea
  Cc: Steven Rostedt, Arnaldo Carvalho de Melo, Ingo Molnar, LKML,
	Namhyung Kim, Peter Zijlstra, Frederic Weisbecker

On 8/28/12 4:06 PM, Irina Tirdea wrote:
> on_exit() is only available in new versions of glibc.
> Using on_exit on Android leads to errors at compile time.
>
> Replacing on_exit with its more portable version atexit.
> This leads to using a global variable since on_exit supports
> sending a parameters while atexit does not.

Bernhard's patch implements on_exit. Why not go that route?

The exit functions need the commands status to know whether to attempt 
to process records. See: https://lkml.org/lkml/2012/8/26/123

Processing records on non-0 exit causes a segfault as the session has 
been deleted.

David


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 12/13] perf tools: replace on_exit with atexit
  2012-08-29 16:59 ` David Ahern
@ 2012-09-02 20:30   ` Irina Tirdea
  0 siblings, 0 replies; 3+ messages in thread
From: Irina Tirdea @ 2012-09-02 20:30 UTC (permalink / raw)
  To: David Ahern
  Cc: Steven Rostedt, Arnaldo Carvalho de Melo, Ingo Molnar, LKML,
	Namhyung Kim, Peter Zijlstra, Frederic Weisbecker

> Bernhard's patch implements on_exit. Why not go that route?
>
> The exit functions need the commands status to know whether to attempt to
> process records. See: https://lkml.org/lkml/2012/8/26/123
>
> Processing records on non-0 exit causes a segfault as the session has been
> deleted.

I was trying to avoid as much as possible adding implementations for
functions in perf. Considering the patch you mentioned and the need to
know the exit status, looks like Bernhard's solution is the best
approach in this case. I will use his on_exit wrapper and drop this
patch.

Thanks,
Irina

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-09-02 20:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-28 22:06 [PATCH 12/13] perf tools: replace on_exit with atexit Irina Tirdea
2012-08-29 16:59 ` David Ahern
2012-09-02 20:30   ` Irina Tirdea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).