[PATCH 30/37] perf tools: Fix progress ui to support multi thread

2014-12-23 Thread Namhyung Kim
Split ui_progress struct into global and local one.  Each thread
updates local struct without lock and only updates global one if
meaningful progress is done (with lock).

To do that, pass struct ui_progress to __perf_session__process_event()
and set it for the total size of multi-file storage.

Signed-off-by: Namhyung Kim 
---
 tools/perf/util/data.c|  22 +
 tools/perf/util/data.h|   3 ++
 tools/perf/util/hist.c|   5 +-
 tools/perf/util/hist.h|   3 +-
 tools/perf/util/session.c | 117 ++
 tools/perf/util/tool.h|   3 ++
 6 files changed, 121 insertions(+), 32 deletions(-)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index b6f7cdc4a39f..37f75f231c4d 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -290,3 +290,25 @@ ssize_t perf_data_file__write_multi(struct perf_data_file 
*file,
 
return writen(file->multi_fd[idx], buf, size);
 }
+
+s64 perf_data_file__multi_size(struct perf_data_file *file)
+{
+   int i;
+   s64 total_size = perf_data_file__size(file);
+
+   if (!file->is_multi)
+   return total_size;
+
+   for (i = 0; i < file->nr_multi; i++) {
+   int fd = perf_data_file__multi_fd(file, i);
+   long size;
+
+   size = lseek(fd, 0, SEEK_END);
+   if (size < 0)
+   return (s64) -1;
+
+   total_size += size;
+   }
+
+   return total_size;
+}
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index f5c229166614..0f0013ac9e30 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -2,6 +2,7 @@
 #define __PERF_DATA_H
 
 #include 
+#include "perf.h"
 
 enum perf_data_mode {
PERF_DATA_MODE_WRITE,
@@ -61,4 +62,6 @@ int perf_data_file__prepare_write(struct perf_data_file 
*file, int nr);
 ssize_t perf_data_file__write_multi(struct perf_data_file *file,
void *buf, size_t size, int idx);
 
+s64 perf_data_file__multi_size(struct perf_data_file *file);
+
 #endif /* __PERF_DATA_H */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index f3b39b45f2ec..60b55a92f23e 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1065,12 +1065,13 @@ void hists__collapse_resort(struct hists *hists, struct 
ui_progress *prog)
__hists__collapse_resort(hists, root, prog);
 }
 
-void hists__multi_resort(struct hists *dst, struct hists *src)
+void hists__multi_resort(struct hists *dst, struct hists *src,
+struct ui_progress *prog)
 {
struct rb_root *root = src->entries_in;
 
sort__need_collapse = 1;
-   __hists__collapse_resort(dst, root, NULL);
+   __hists__collapse_resort(dst, root, prog);
 }
 
 static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b)
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 4d975f5501ed..e2abc4c75158 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -124,7 +124,8 @@ int hist_entry__sort_snprintf(struct hist_entry *he, char 
*bf, size_t size,
 void hist_entry__free(struct hist_entry *);
 
 void hists__output_resort(struct hists *hists, struct ui_progress *prog);
-void hists__multi_resort(struct hists *dst, struct hists *src);
+void hists__multi_resort(struct hists *dst, struct hists *src,
+struct ui_progress *prog);
 void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
 
 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 34956983ae8e..6d1dfbc650ba 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1258,14 +1258,14 @@ fetch_mmaped_event(struct perf_session *session,
 static int __perf_session__process_events(struct perf_session *session,
  struct events_stats *stats, int fd,
  u64 data_offset, u64 data_size,
- u64 file_size, struct perf_tool *tool)
+ u64 file_size, struct perf_tool *tool,
+ struct ui_progress *prog)
 {
u64 head, page_offset, file_offset, file_pos, size;
int err, mmap_prot, mmap_flags, map_idx = 0;
size_t  mmap_size;
char *buf, *mmaps[NUM_MMAPS];
union perf_event *event;
-   struct ui_progress prog;
s64 skip;
 
perf_tool__fill_defaults(tool);
@@ -1277,8 +1277,6 @@ static int __perf_session__process_events(struct 
perf_session *session,
if (data_size && (data_offset + data_size < file_size))
file_size = data_offset + data_size;
 
-   ui_progress__init(, file_size, "Processing events...");
-
mmap_size = MMAP_SIZE;
if (mmap_size > file_size) {
mmap_size = file_size;
@@ -1344,7 +1342,7 @@ 

[PATCH 30/37] perf tools: Fix progress ui to support multi thread

2014-12-23 Thread Namhyung Kim
Split ui_progress struct into global and local one.  Each thread
updates local struct without lock and only updates global one if
meaningful progress is done (with lock).

To do that, pass struct ui_progress to __perf_session__process_event()
and set it for the total size of multi-file storage.

Signed-off-by: Namhyung Kim namhy...@kernel.org
---
 tools/perf/util/data.c|  22 +
 tools/perf/util/data.h|   3 ++
 tools/perf/util/hist.c|   5 +-
 tools/perf/util/hist.h|   3 +-
 tools/perf/util/session.c | 117 ++
 tools/perf/util/tool.h|   3 ++
 6 files changed, 121 insertions(+), 32 deletions(-)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index b6f7cdc4a39f..37f75f231c4d 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -290,3 +290,25 @@ ssize_t perf_data_file__write_multi(struct perf_data_file 
*file,
 
return writen(file-multi_fd[idx], buf, size);
 }
+
+s64 perf_data_file__multi_size(struct perf_data_file *file)
+{
+   int i;
+   s64 total_size = perf_data_file__size(file);
+
+   if (!file-is_multi)
+   return total_size;
+
+   for (i = 0; i  file-nr_multi; i++) {
+   int fd = perf_data_file__multi_fd(file, i);
+   long size;
+
+   size = lseek(fd, 0, SEEK_END);
+   if (size  0)
+   return (s64) -1;
+
+   total_size += size;
+   }
+
+   return total_size;
+}
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index f5c229166614..0f0013ac9e30 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -2,6 +2,7 @@
 #define __PERF_DATA_H
 
 #include stdbool.h
+#include perf.h
 
 enum perf_data_mode {
PERF_DATA_MODE_WRITE,
@@ -61,4 +62,6 @@ int perf_data_file__prepare_write(struct perf_data_file 
*file, int nr);
 ssize_t perf_data_file__write_multi(struct perf_data_file *file,
void *buf, size_t size, int idx);
 
+s64 perf_data_file__multi_size(struct perf_data_file *file);
+
 #endif /* __PERF_DATA_H */
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index f3b39b45f2ec..60b55a92f23e 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1065,12 +1065,13 @@ void hists__collapse_resort(struct hists *hists, struct 
ui_progress *prog)
__hists__collapse_resort(hists, root, prog);
 }
 
-void hists__multi_resort(struct hists *dst, struct hists *src)
+void hists__multi_resort(struct hists *dst, struct hists *src,
+struct ui_progress *prog)
 {
struct rb_root *root = src-entries_in;
 
sort__need_collapse = 1;
-   __hists__collapse_resort(dst, root, NULL);
+   __hists__collapse_resort(dst, root, prog);
 }
 
 static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b)
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 4d975f5501ed..e2abc4c75158 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -124,7 +124,8 @@ int hist_entry__sort_snprintf(struct hist_entry *he, char 
*bf, size_t size,
 void hist_entry__free(struct hist_entry *);
 
 void hists__output_resort(struct hists *hists, struct ui_progress *prog);
-void hists__multi_resort(struct hists *dst, struct hists *src);
+void hists__multi_resort(struct hists *dst, struct hists *src,
+struct ui_progress *prog);
 void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
 
 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 34956983ae8e..6d1dfbc650ba 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1258,14 +1258,14 @@ fetch_mmaped_event(struct perf_session *session,
 static int __perf_session__process_events(struct perf_session *session,
  struct events_stats *stats, int fd,
  u64 data_offset, u64 data_size,
- u64 file_size, struct perf_tool *tool)
+ u64 file_size, struct perf_tool *tool,
+ struct ui_progress *prog)
 {
u64 head, page_offset, file_offset, file_pos, size;
int err, mmap_prot, mmap_flags, map_idx = 0;
size_t  mmap_size;
char *buf, *mmaps[NUM_MMAPS];
union perf_event *event;
-   struct ui_progress prog;
s64 skip;
 
perf_tool__fill_defaults(tool);
@@ -1277,8 +1277,6 @@ static int __perf_session__process_events(struct 
perf_session *session,
if (data_size  (data_offset + data_size  file_size))
file_size = data_offset + data_size;
 
-   ui_progress__init(prog, file_size, Processing events...);
-
mmap_size = MMAP_SIZE;
if (mmap_size  file_size) {
mmap_size = file_size;
@@