[PATCH 07/38] perf tools: Handle indexed data file properly

From: Namhyung Kim
Date: Mon Mar 02 2015 - 22:21:40 EST


When perf detects data file has index table, process header part first
and then rest data files in a row. Note that the indexed sample data is
recorded for each cpu/thread separately, it's already ordered with
respect to themselves so no need to use the ordered event queue
interface.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/session.c | 62 ++++++++++++++++++++++++++++++++++++++---------
tools/perf/util/session.h | 5 ++++
2 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index e4f166981ff0..00cd1ad427be 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1300,11 +1300,10 @@ fetch_mmaped_event(struct perf_session *session,
#define NUM_MMAPS 128
#endif

-static int __perf_session__process_events(struct perf_session *session,
+static int __perf_session__process_events(struct perf_session *session, int fd,
u64 data_offset, u64 data_size,
u64 file_size, struct perf_tool *tool)
{
- int fd = perf_data_file__fd(session->file);
u64 head, page_offset, file_offset, file_pos, size;
int err, mmap_prot, mmap_flags, map_idx = 0;
size_t mmap_size;
@@ -1327,7 +1326,9 @@ static int __perf_session__process_events(struct perf_session *session,
mmap_size = MMAP_SIZE;
if (mmap_size > file_size) {
mmap_size = file_size;
- session->one_mmap = true;
+
+ if (!perf_session__has_index(session))
+ session->one_mmap = true;
}

memset(mmaps, 0, sizeof(mmaps));
@@ -1400,29 +1401,66 @@ static int __perf_session__process_events(struct perf_session *session,
err = ordered_events__flush(session, tool, OE_FLUSH__FINAL);
out_err:
ui_progress__finish();
- perf_tool__warn_about_errors(tool, &session->evlist->stats);
ordered_events__free(&session->ordered_events);
session->one_mmap = false;
return err;
}

+static int __perf_session__process_indexed_events(struct perf_session *session,
+ struct perf_tool *tool)
+{
+ struct perf_data_file *file = session->file;
+ u64 size = perf_data_file__size(file);
+ int err = 0, i;
+
+ for (i = 0; i < (int)session->header.nr_index; i++) {
+ struct perf_file_section *index = &session->header.index[i];
+
+ if (!index->size)
+ continue;
+
+ /*
+ * For indexed data file, samples are processed for
+ * each cpu/thread so it's already ordered. However
+ * meta-events at index 0 should be processed in order.
+ */
+ if (i > 0)
+ tool->ordered_events = false;
+
+ err = __perf_session__process_events(session,
+ perf_data_file__fd(file),
+ index->offset, index->size,
+ size, tool);
+ if (err < 0)
+ break;
+ }
+
+ perf_tool__warn_about_errors(tool, &session->evlist->stats);
+ return err;
+}
+
int perf_session__process_events(struct perf_session *session,
struct perf_tool *tool)
{
- u64 size = perf_data_file__size(session->file);
+ struct perf_data_file *file = session->file;
+ u64 size = perf_data_file__size(file);
int err;

if (perf_session__register_idle_thread(session) == NULL)
return -ENOMEM;

- if (!perf_data_file__is_pipe(session->file))
- err = __perf_session__process_events(session,
- session->header.data_offset,
- session->header.data_size,
- size, tool);
- else
- err = __perf_session__process_pipe_events(session, tool);
+ if (perf_data_file__is_pipe(file))
+ return __perf_session__process_pipe_events(session, tool);
+ if (perf_session__has_index(session))
+ return __perf_session__process_indexed_events(session, tool);
+
+ err = __perf_session__process_events(session,
+ perf_data_file__fd(file),
+ session->header.data_offset,
+ session->header.data_size,
+ size, tool);

+ perf_tool__warn_about_errors(tool, &session->evlist->stats);
return err;
}

diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index fe859f379ca7..aff0d2b4cc0b 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -137,4 +137,9 @@ int perf_event__synthesize_id_index(struct perf_tool *tool,
struct perf_evlist *evlist,
struct machine *machine);

+static inline bool perf_session__has_index(struct perf_session *session)
+{
+ return perf_header__has_feat(&session->header, HEADER_DATA_INDEX);
+}
+
#endif /* __PERF_SESSION_H */
--
2.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/