mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2] perf: Speed up thread map generation
@ 2014-03-14 14:43 Don Zickus
  2014-03-14 16:12 ` Jiri Olsa
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Don Zickus @ 2014-03-14 14:43 UTC (permalink / raw)
  To: acme; +Cc: jolsa, jmario, LKML, Don Zickus

When trying to capture perf data on a system running spejbb2013,
perf hung for about 15 minutes.  This is because it took that
long to gather about 10,000 thread maps and process them.

I don't think a user wants to wait that long.

Instead, recognize that thread maps are roughly equivalent to
pid maps and just quickly copy those instead.

To do this, I synthesize 'fork' events, this eventually calls
thread__fork() and copies the maps over.

The overhead goes from 15 minutes down to about a few seconds.

Signed-off-by: Don Zickus <dzickus@redhat.com>
--
V2: based on Jiri's comments, moved malloc up a level
    and made sure the memory was freed
---
 tools/perf/util/event.c |   59 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 55eebe9..3e580be 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -129,6 +129,28 @@ out:
 	return tgid;
 }
 
+static int perf_event__synthesize_fork(struct perf_tool *tool,
+				       union perf_event *event, pid_t pid,
+				       pid_t tgid, perf_event__handler_t process,
+				       struct machine *machine)
+{
+	memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
+
+	/* this is really a clone event but we use fork to synthesize it */
+	event->fork.ppid = tgid;
+	event->fork.ptid = tgid;
+	event->fork.pid  = tgid;
+	event->fork.tid  = pid;
+	event->fork.header.type = PERF_RECORD_FORK;
+
+	event->fork.header.size = (sizeof(event->fork) + machine->id_hdr_size);
+
+	if (process(tool, event, &synth_sample, machine) != 0)
+		return -1;
+
+	return 0;
+}
+
 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
 				       union perf_event *event,
 				       pid_t pid, pid_t tgid,
@@ -278,6 +300,7 @@ int perf_event__synthesize_modules(struct perf_tool *tool,
 
 static int __event__synthesize_thread(union perf_event *comm_event,
 				      union perf_event *mmap_event,
+				      union perf_event *fork_event,
 				      pid_t pid, int full,
 					  perf_event__handler_t process,
 				      struct perf_tool *tool,
@@ -326,9 +349,15 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 		if (tgid == -1)
 			return -1;
 
-		/* process the thread's maps too */
-		rc = perf_event__synthesize_mmap_events(tool, mmap_event, _pid, tgid,
-							process, machine, mmap_data);
+		if (_pid == pid) {
+			/* process the parent's maps too */
+			rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
+						process, machine, mmap_data);
+		} else {
+			/* only fork the tid's map, to save time */
+			rc = perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
+						 process, machine);
+		}
 
 		if (rc)
 			return rc;
@@ -344,7 +373,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 				      struct machine *machine,
 				      bool mmap_data)
 {
-	union perf_event *comm_event, *mmap_event;
+	union perf_event *comm_event, *mmap_event, *fork_event;
 	int err = -1, thread, j;
 
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
@@ -355,9 +384,14 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 	if (mmap_event == NULL)
 		goto out_free_comm;
 
+	fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
+	if (fork_event == NULL)
+		goto out_free_mmap;
+
 	err = 0;
 	for (thread = 0; thread < threads->nr; ++thread) {
 		if (__event__synthesize_thread(comm_event, mmap_event,
+					       fork_event,
 					       threads->map[thread], 0,
 					       process, tool, machine,
 					       mmap_data)) {
@@ -383,6 +417,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 			/* if not, generate events for it */
 			if (need_leader &&
 			    __event__synthesize_thread(comm_event, mmap_event,
+						       fork_event,
 						       comm_event->comm.pid, 0,
 						       process, tool, machine,
 						       mmap_data)) {
@@ -391,6 +426,8 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 			}
 		}
 	}
+	free(fork_event);
+out_free_mmap:
 	free(mmap_event);
 out_free_comm:
 	free(comm_event);
@@ -405,7 +442,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	DIR *proc;
 	char proc_path[PATH_MAX];
 	struct dirent dirent, *next;
-	union perf_event *comm_event, *mmap_event;
+	union perf_event *comm_event, *mmap_event, *fork_event;
 	int err = -1;
 
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
@@ -416,6 +453,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	if (mmap_event == NULL)
 		goto out_free_comm;
 
+	fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
+	if (fork_event == NULL)
+		goto out_free_mmap;
+
 	if (machine__is_default_guest(machine))
 		return 0;
 
@@ -423,7 +464,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	proc = opendir(proc_path);
 
 	if (proc == NULL)
-		goto out_free_mmap;
+		goto out_free_fork;
 
 	while (!readdir_r(proc, &dirent, &next) && next) {
 		char *end;
@@ -435,12 +476,14 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
  		 * We may race with exiting thread, so don't stop just because
  		 * one thread couldn't be synthesized.
  		 */
-		__event__synthesize_thread(comm_event, mmap_event, pid, 1,
-					   process, tool, machine, mmap_data);
+		__event__synthesize_thread(comm_event, mmap_event, fork_event, pid,
+					   1, process, tool, machine, mmap_data);
 	}
 
 	err = 0;
 	closedir(proc);
+out_free_fork:
+	free(fork_event);
 out_free_mmap:
 	free(mmap_event);
 out_free_comm:
-- 
1.7.1


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

* Re: [PATCH V2] perf: Speed up thread map generation
  2014-03-14 14:43 [PATCH V2] perf: Speed up thread map generation Don Zickus
@ 2014-03-14 16:12 ` Jiri Olsa
  2014-03-17  1:45 ` Namhyung Kim
  2014-03-18  8:31 ` [tip:perf/core] perf tools: Speed up thread map generation tip-bot for Don Zickus
  2 siblings, 0 replies; 7+ messages in thread
From: Jiri Olsa @ 2014-03-14 16:12 UTC (permalink / raw)
  To: Don Zickus; +Cc: acme, jmario, LKML

On Fri, Mar 14, 2014 at 10:43:44AM -0400, Don Zickus wrote:
> When trying to capture perf data on a system running spejbb2013,
> perf hung for about 15 minutes.  This is because it took that
> long to gather about 10,000 thread maps and process them.
> 
> I don't think a user wants to wait that long.
> 
> Instead, recognize that thread maps are roughly equivalent to
> pid maps and just quickly copy those instead.
> 
> To do this, I synthesize 'fork' events, this eventually calls
> thread__fork() and copies the maps over.
> 
> The overhead goes from 15 minutes down to about a few seconds.
> 
> Signed-off-by: Don Zickus <dzickus@redhat.com>
> --
> V2: based on Jiri's comments, moved malloc up a level
>     and made sure the memory was freed

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

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

* Re: [PATCH V2] perf: Speed up thread map generation
  2014-03-14 14:43 [PATCH V2] perf: Speed up thread map generation Don Zickus
  2014-03-14 16:12 ` Jiri Olsa
@ 2014-03-17  1:45 ` Namhyung Kim
  2014-03-18 13:43   ` Arnaldo Carvalho de Melo
  2014-03-19 13:07   ` [tip:perf/core] perf tools: Fix memory leak when synthesizing thread records tip-bot for Namhyung Kim
  2014-03-18  8:31 ` [tip:perf/core] perf tools: Speed up thread map generation tip-bot for Don Zickus
  2 siblings, 2 replies; 7+ messages in thread
From: Namhyung Kim @ 2014-03-17  1:45 UTC (permalink / raw)
  To: Don Zickus; +Cc: acme, jolsa, jmario, LKML

Hi Don,

On Fri, 14 Mar 2014 10:43:44 -0400, Don Zickus wrote:
> When trying to capture perf data on a system running spejbb2013,
> perf hung for about 15 minutes.  This is because it took that
> long to gather about 10,000 thread maps and process them.
>
> I don't think a user wants to wait that long.
>
> Instead, recognize that thread maps are roughly equivalent to
> pid maps and just quickly copy those instead.
>
> To do this, I synthesize 'fork' events, this eventually calls
> thread__fork() and copies the maps over.
>
> The overhead goes from 15 minutes down to about a few seconds.

[SNIP]
> @@ -416,6 +453,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
>  	if (mmap_event == NULL)
>  		goto out_free_comm;
>  
> +	fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
> +	if (fork_event == NULL)
> +		goto out_free_mmap;
> +
>  	if (machine__is_default_guest(machine))
>  		return 0;

Not related to this patch, but this will causes a memory leak..
So I think below patch is needed on top (not sure it's also needed for
perf_event__synthesize_thread_map() too).


>From 3c4b49b4f540c7d49ee78364b02faa0bfce59c67 Mon Sep 17 00:00:00 2001
From: Namhyung Kim <namhyung@kernel.org>
Date: Mon, 17 Mar 2014 10:23:06 +0900
Subject: [PATCH] perf tools: Fix a possible memory leak

Checking default guest machine should be done before allocating event
structures otherwise it'll leak memory.

Cc: Don Zickus <dzickus@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/event.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 3e580be0f6fb..eab930d28159 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -445,6 +445,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	union perf_event *comm_event, *mmap_event, *fork_event;
 	int err = -1;
 
+	if (machine__is_default_guest(machine))
+		return 0;
+
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
 	if (comm_event == NULL)
 		goto out;
@@ -457,9 +460,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	if (fork_event == NULL)
 		goto out_free_mmap;
 
-	if (machine__is_default_guest(machine))
-		return 0;
-
 	snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
 	proc = opendir(proc_path);
 
-- 
1.7.11.7


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

* [tip:perf/core] perf tools: Speed up thread map generation
  2014-03-14 14:43 [PATCH V2] perf: Speed up thread map generation Don Zickus
  2014-03-14 16:12 ` Jiri Olsa
  2014-03-17  1:45 ` Namhyung Kim
@ 2014-03-18  8:31 ` tip-bot for Don Zickus
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Don Zickus @ 2014-03-18  8:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, jmario, jolsa, tglx, dzickus

Commit-ID:  363b785f3805a2632eb09a8b430842461c21a640
Gitweb:     http://git.kernel.org/tip/363b785f3805a2632eb09a8b430842461c21a640
Author:     Don Zickus <dzickus@redhat.com>
AuthorDate: Fri, 14 Mar 2014 10:43:44 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 14 Mar 2014 18:08:41 -0300

perf tools: Speed up thread map generation

When trying to capture perf data on a system running spejbb2013, perf
hung for about 15 minutes.  This is because it took that long to gather
about 10,000 thread maps and process them.

I don't think a user wants to wait that long.

Instead, recognize that thread maps are roughly equivalent to pid maps
and just quickly copy those instead.

To do this, I synthesize 'fork' events, this eventually calls
thread__fork() and copies the maps over.

The overhead goes from 15 minutes down to about a few seconds.

--
V2: based on Jiri's comments, moved malloc up a level
    and made sure the memory was freed

Signed-off-by: Don Zickus <dzickus@redhat.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Link: http://lkml.kernel.org/r/1394808224-113774-1-git-send-email-dzickus@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/event.c | 59 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 51 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 55eebe9..3e580be 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -129,6 +129,28 @@ out:
 	return tgid;
 }
 
+static int perf_event__synthesize_fork(struct perf_tool *tool,
+				       union perf_event *event, pid_t pid,
+				       pid_t tgid, perf_event__handler_t process,
+				       struct machine *machine)
+{
+	memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
+
+	/* this is really a clone event but we use fork to synthesize it */
+	event->fork.ppid = tgid;
+	event->fork.ptid = tgid;
+	event->fork.pid  = tgid;
+	event->fork.tid  = pid;
+	event->fork.header.type = PERF_RECORD_FORK;
+
+	event->fork.header.size = (sizeof(event->fork) + machine->id_hdr_size);
+
+	if (process(tool, event, &synth_sample, machine) != 0)
+		return -1;
+
+	return 0;
+}
+
 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
 				       union perf_event *event,
 				       pid_t pid, pid_t tgid,
@@ -278,6 +300,7 @@ int perf_event__synthesize_modules(struct perf_tool *tool,
 
 static int __event__synthesize_thread(union perf_event *comm_event,
 				      union perf_event *mmap_event,
+				      union perf_event *fork_event,
 				      pid_t pid, int full,
 					  perf_event__handler_t process,
 				      struct perf_tool *tool,
@@ -326,9 +349,15 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 		if (tgid == -1)
 			return -1;
 
-		/* process the thread's maps too */
-		rc = perf_event__synthesize_mmap_events(tool, mmap_event, _pid, tgid,
-							process, machine, mmap_data);
+		if (_pid == pid) {
+			/* process the parent's maps too */
+			rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
+						process, machine, mmap_data);
+		} else {
+			/* only fork the tid's map, to save time */
+			rc = perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
+						 process, machine);
+		}
 
 		if (rc)
 			return rc;
@@ -344,7 +373,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 				      struct machine *machine,
 				      bool mmap_data)
 {
-	union perf_event *comm_event, *mmap_event;
+	union perf_event *comm_event, *mmap_event, *fork_event;
 	int err = -1, thread, j;
 
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
@@ -355,9 +384,14 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 	if (mmap_event == NULL)
 		goto out_free_comm;
 
+	fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
+	if (fork_event == NULL)
+		goto out_free_mmap;
+
 	err = 0;
 	for (thread = 0; thread < threads->nr; ++thread) {
 		if (__event__synthesize_thread(comm_event, mmap_event,
+					       fork_event,
 					       threads->map[thread], 0,
 					       process, tool, machine,
 					       mmap_data)) {
@@ -383,6 +417,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 			/* if not, generate events for it */
 			if (need_leader &&
 			    __event__synthesize_thread(comm_event, mmap_event,
+						       fork_event,
 						       comm_event->comm.pid, 0,
 						       process, tool, machine,
 						       mmap_data)) {
@@ -391,6 +426,8 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
 			}
 		}
 	}
+	free(fork_event);
+out_free_mmap:
 	free(mmap_event);
 out_free_comm:
 	free(comm_event);
@@ -405,7 +442,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	DIR *proc;
 	char proc_path[PATH_MAX];
 	struct dirent dirent, *next;
-	union perf_event *comm_event, *mmap_event;
+	union perf_event *comm_event, *mmap_event, *fork_event;
 	int err = -1;
 
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
@@ -416,6 +453,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	if (mmap_event == NULL)
 		goto out_free_comm;
 
+	fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
+	if (fork_event == NULL)
+		goto out_free_mmap;
+
 	if (machine__is_default_guest(machine))
 		return 0;
 
@@ -423,7 +464,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	proc = opendir(proc_path);
 
 	if (proc == NULL)
-		goto out_free_mmap;
+		goto out_free_fork;
 
 	while (!readdir_r(proc, &dirent, &next) && next) {
 		char *end;
@@ -435,12 +476,14 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
  		 * We may race with exiting thread, so don't stop just because
  		 * one thread couldn't be synthesized.
  		 */
-		__event__synthesize_thread(comm_event, mmap_event, pid, 1,
-					   process, tool, machine, mmap_data);
+		__event__synthesize_thread(comm_event, mmap_event, fork_event, pid,
+					   1, process, tool, machine, mmap_data);
 	}
 
 	err = 0;
 	closedir(proc);
+out_free_fork:
+	free(fork_event);
 out_free_mmap:
 	free(mmap_event);
 out_free_comm:

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

* Re: [PATCH V2] perf: Speed up thread map generation
  2014-03-17  1:45 ` Namhyung Kim
@ 2014-03-18 13:43   ` Arnaldo Carvalho de Melo
  2014-03-18 14:20     ` Namhyung Kim
  2014-03-19 13:07   ` [tip:perf/core] perf tools: Fix memory leak when synthesizing thread records tip-bot for Namhyung Kim
  1 sibling, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-03-18 13:43 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Don Zickus, jolsa, jmario, LKML

Em Mon, Mar 17, 2014 at 10:45:49AM +0900, Namhyung Kim escreveu:
> Hi Don,
> 
> On Fri, 14 Mar 2014 10:43:44 -0400, Don Zickus wrote:
> > When trying to capture perf data on a system running spejbb2013,
> > perf hung for about 15 minutes.  This is because it took that
> > long to gather about 10,000 thread maps and process them.
> >
> > I don't think a user wants to wait that long.
> >
> > Instead, recognize that thread maps are roughly equivalent to
> > pid maps and just quickly copy those instead.
> >
> > To do this, I synthesize 'fork' events, this eventually calls
> > thread__fork() and copies the maps over.
> >
> > The overhead goes from 15 minutes down to about a few seconds.
> 
> [SNIP]
> > @@ -416,6 +453,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
> >  	if (mmap_event == NULL)
> >  		goto out_free_comm;
> >  
> > +	fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
> > +	if (fork_event == NULL)
> > +		goto out_free_mmap;
> > +
> >  	if (machine__is_default_guest(machine))
> >  		return 0;
> 
> Not related to this patch, but this will causes a memory leak..
> So I think below patch is needed on top (not sure it's also needed for
> perf_event__synthesize_thread_map() too).

Good catch, applying it, please next time send it under separate cover,
i.e. not inside another thread.

- Arnaldo
 
> 
> >From 3c4b49b4f540c7d49ee78364b02faa0bfce59c67 Mon Sep 17 00:00:00 2001
> From: Namhyung Kim <namhyung@kernel.org>
> Date: Mon, 17 Mar 2014 10:23:06 +0900
> Subject: [PATCH] perf tools: Fix a possible memory leak
> 
> Checking default guest machine should be done before allocating event
> structures otherwise it'll leak memory.
> 
> Cc: Don Zickus <dzickus@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/util/event.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index 3e580be0f6fb..eab930d28159 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -445,6 +445,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
>  	union perf_event *comm_event, *mmap_event, *fork_event;
>  	int err = -1;
>  
> +	if (machine__is_default_guest(machine))
> +		return 0;
> +
>  	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
>  	if (comm_event == NULL)
>  		goto out;
> @@ -457,9 +460,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
>  	if (fork_event == NULL)
>  		goto out_free_mmap;
>  
> -	if (machine__is_default_guest(machine))
> -		return 0;
> -
>  	snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
>  	proc = opendir(proc_path);
>  
> -- 
> 1.7.11.7

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

* Re: [PATCH V2] perf: Speed up thread map generation
  2014-03-18 13:43   ` Arnaldo Carvalho de Melo
@ 2014-03-18 14:20     ` Namhyung Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Namhyung Kim @ 2014-03-18 14:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Don Zickus, Jiri Olsa, jmario, LKML

On Tue, Mar 18, 2014 at 10:43 PM, Arnaldo Carvalho de Melo
<acme@redhat.com> wrote:
> Em Mon, Mar 17, 2014 at 10:45:49AM +0900, Namhyung Kim escreveu:
>> Hi Don,
>>
>> On Fri, 14 Mar 2014 10:43:44 -0400, Don Zickus wrote:
>> > When trying to capture perf data on a system running spejbb2013,
>> > perf hung for about 15 minutes.  This is because it took that
>> > long to gather about 10,000 thread maps and process them.
>> >
>> > I don't think a user wants to wait that long.
>> >
>> > Instead, recognize that thread maps are roughly equivalent to
>> > pid maps and just quickly copy those instead.
>> >
>> > To do this, I synthesize 'fork' events, this eventually calls
>> > thread__fork() and copies the maps over.
>> >
>> > The overhead goes from 15 minutes down to about a few seconds.
>>
>> [SNIP]
>> > @@ -416,6 +453,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
>> >     if (mmap_event == NULL)
>> >             goto out_free_comm;
>> >
>> > +   fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
>> > +   if (fork_event == NULL)
>> > +           goto out_free_mmap;
>> > +
>> >     if (machine__is_default_guest(machine))
>> >             return 0;
>>
>> Not related to this patch, but this will causes a memory leak..
>> So I think below patch is needed on top (not sure it's also needed for
>> perf_event__synthesize_thread_map() too).
>
> Good catch, applying it, please next time send it under separate cover,
> i.e. not inside another thread.

Okay.  I'll send this kind of patch in a separate thread next time.

Thanks,
Namhyung

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

* [tip:perf/core] perf tools: Fix memory leak when synthesizing thread records
  2014-03-17  1:45 ` Namhyung Kim
  2014-03-18 13:43   ` Arnaldo Carvalho de Melo
@ 2014-03-19 13:07   ` tip-bot for Namhyung Kim
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Namhyung Kim @ 2014-03-19 13:07 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, jmario, namhyung, jolsa, tglx, dzickus

Commit-ID:  574799bfdbc3a13e0b5e2f6af34b761bde743a9a
Gitweb:     http://git.kernel.org/tip/574799bfdbc3a13e0b5e2f6af34b761bde743a9a
Author:     Namhyung Kim <namhyung@kernel.org>
AuthorDate: Mon, 17 Mar 2014 10:45:49 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 18 Mar 2014 18:17:01 -0300

perf tools: Fix memory leak when synthesizing thread records

Checking default guest machine should be done before allocating event
structures otherwise it'll leak memory.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joe Mario <jmario@redhat.com>
Link: http://lkml.kernel.org/r/87ob15tx6a.fsf@sejong.aot.lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/event.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ebb48a6..9d12aa6 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -446,6 +446,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	union perf_event *comm_event, *mmap_event, *fork_event;
 	int err = -1;
 
+	if (machine__is_default_guest(machine))
+		return 0;
+
 	comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
 	if (comm_event == NULL)
 		goto out;
@@ -458,9 +461,6 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 	if (fork_event == NULL)
 		goto out_free_mmap;
 
-	if (machine__is_default_guest(machine))
-		return 0;
-
 	snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
 	proc = opendir(proc_path);
 

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

end of thread, other threads:[~2014-03-19 13:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-14 14:43 [PATCH V2] perf: Speed up thread map generation Don Zickus
2014-03-14 16:12 ` Jiri Olsa
2014-03-17  1:45 ` Namhyung Kim
2014-03-18 13:43   ` Arnaldo Carvalho de Melo
2014-03-18 14:20     ` Namhyung Kim
2014-03-19 13:07   ` [tip:perf/core] perf tools: Fix memory leak when synthesizing thread records tip-bot for Namhyung Kim
2014-03-18  8:31 ` [tip:perf/core] perf tools: Speed up thread map generation tip-bot for Don Zickus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome