perf report: Generalize perf_session__fprintf_hists()

Pull it out of builtin-report - further changes will be made and it
will then be reusable in 'perf diff' as well.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260914682-29652-4-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index bf491fd..bb0fd6d 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -189,13 +189,41 @@
 	closedir(proc);
 }
 
+static void thread__comm_adjust(struct thread *self)
+{
+	char *comm = self->comm;
+
+	if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
+	    (!symbol_conf.comm_list ||
+	     strlist__has_entry(symbol_conf.comm_list, comm))) {
+		unsigned int slen = strlen(comm);
+
+		if (slen > comms__col_width) {
+			comms__col_width = slen;
+			threads__col_width = slen + 6;
+		}
+	}
+}
+
+static int thread__set_comm_adjust(struct thread *self, const char *comm)
+{
+	int ret = thread__set_comm(self, comm);
+
+	if (ret)
+		return ret;
+
+	thread__comm_adjust(self);
+
+	return 0;
+}
+
 int event__process_comm(event_t *self, struct perf_session *session)
 {
 	struct thread *thread = perf_session__findnew(session, self->comm.pid);
 
 	dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid);
 
-	if (thread == NULL || thread__set_comm(thread, self->comm.comm)) {
+	if (thread == NULL || thread__set_comm_adjust(thread, self->comm.comm)) {
 		dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
 		return -1;
 	}
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index b9828fc..d9a5a193 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -156,8 +156,7 @@
  * reverse the map, sort on count.
  */
 
-static void perf_session__insert_output_hist_entry(struct perf_session *self,
-						   struct rb_root *root,
+static void perf_session__insert_output_hist_entry(struct rb_root *root,
 						   struct hist_entry *he,
 						   u64 min_callchain_hits)
 {
@@ -165,7 +164,7 @@
 	struct rb_node *parent = NULL;
 	struct hist_entry *iter;
 
-	if (self->use_callchain)
+	if (symbol_conf.use_callchain)
 		callchain_param.sort(&he->sorted_chain, &he->callchain,
 				      min_callchain_hits, &callchain_param);
 
@@ -201,7 +200,7 @@
 		next = rb_next(&n->rb_node);
 
 		rb_erase(&n->rb_node, &self->hists);
-		perf_session__insert_output_hist_entry(self, &tmp, n,
+		perf_session__insert_output_hist_entry(&tmp, n,
 						       min_callchain_hits);
 	}
 
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index bceaa09..ce3a6c8 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -108,7 +108,7 @@
 	struct symbol **syms = NULL;
 	unsigned int i;
 
-	if (self->use_callchain) {
+	if (symbol_conf.use_callchain) {
 		syms = calloc(chain->nr, sizeof(*syms));
 		if (!syms) {
 			fprintf(stderr, "Can't allocate memory for symbols\n");
@@ -140,7 +140,7 @@
 			if (sort__has_parent && !*parent &&
 			    symbol__match_parent_regex(al.sym))
 				*parent = al.sym;
-			if (!self->use_callchain)
+			if (!symbol_conf.use_callchain)
 				break;
 			syms[i] = al.sym;
 		}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index faf18a8..32eaa1b 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -25,7 +25,6 @@
 	int			fd;
 	int			cwdlen;
 	char			*cwd;
-	bool			use_callchain;
 	char filename[0];
 };
 
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 7707897..ab92763 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -38,6 +38,7 @@
 static char **vmlinux_path;
 
 struct symbol_conf symbol_conf = {
+	.exclude_other	  = true,
 	.use_modules	  = true,
 	.try_vmlinux_path = true,
 };
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 6015152..8aded23 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -55,7 +55,10 @@
 	unsigned short	priv_size;
 	bool		try_vmlinux_path,
 			use_modules,
-			sort_by_name;
+			sort_by_name,
+			show_nr_samples,
+			use_callchain,
+			exclude_other;
 	const char	*vmlinux_name,
 			*field_sep;
 	char            *dso_list_str,