All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH RFC 1/2] perf tools: Support single perf.data file directory
Date: Mon, 16 Sep 2019 11:56:45 +0300	[thread overview]
Message-ID: <20190916085646.6199-2-adrian.hunter@intel.com> (raw)
In-Reply-To: <20190916085646.6199-1-adrian.hunter@intel.com>

Support directory output that contains a regular perf.data file. This is
preparation for adding support for putting a copy of /proc/kcore in that
directory.

Distinguish the multiple file case from the regular (single) perf.data file
case by adding data->is_multi_file.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-record.c |  2 +-
 tools/perf/util/data.c      | 37 +++++++++++++++++++++++++++----------
 tools/perf/util/data.h      |  6 ++++++
 tools/perf/util/header.h    |  1 +
 tools/perf/util/session.c   |  2 +-
 tools/perf/util/util.c      |  1 +
 6 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1447004eee8a..4c356a046dd3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -534,7 +534,7 @@ static int record__process_auxtrace(struct perf_tool *tool,
 	size_t padding;
 	u8 pad[8] = {0};
 
-	if (!perf_data__is_pipe(data) && !perf_data__is_dir(data)) {
+	if (!perf_data__is_pipe(data) && !perf_data__is_multi_file(data)) {
 		off_t file_offset;
 		int fd = perf_data__fd(data);
 		int err;
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 88fba2ba549f..2fd3114d1167 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -37,7 +37,7 @@ int perf_data__create_dir(struct perf_data *data, int nr)
 	struct perf_data_file *files = NULL;
 	int i, ret = -1;
 
-	if (WARN_ON(!data->is_dir))
+	if (WARN_ON(!data->is_multi_file))
 		return -EINVAL;
 
 	files = zalloc(nr * sizeof(*files));
@@ -76,7 +76,7 @@ int perf_data__open_dir(struct perf_data *data)
 	DIR *dir;
 	int nr = 0;
 
-	if (WARN_ON(!data->is_dir))
+	if (WARN_ON(!data->is_multi_file))
 		return -EINVAL;
 
 	/* The version is provided by DIR_FORMAT feature. */
@@ -217,6 +217,16 @@ static bool is_dir(struct perf_data *data)
 	return (st.st_mode & S_IFMT) == S_IFDIR;
 }
 
+static bool is_multi_file(struct perf_data *data)
+{
+	char path[PATH_MAX];
+	struct stat st;
+
+	snprintf(path, sizeof(path), "%s/header", data->path);
+
+	return !stat(path, &st);
+}
+
 static int open_file_read(struct perf_data *data)
 {
 	struct stat st;
@@ -302,12 +312,17 @@ static int open_dir(struct perf_data *data)
 {
 	int ret;
 
-	/*
-	 * So far we open only the header, so we can read the data version and
-	 * layout.
-	 */
-	if (asprintf(&data->file.path, "%s/header", data->path) < 0)
-		return -1;
+	if (perf_data__is_multi_file(data)) {
+		/*
+		 * So far we open only the header, so we can read the data version and
+		 * layout.
+		 */
+		if (asprintf(&data->file.path, "%s/header", data->path) < 0)
+			return -1;
+	} else {
+		if (asprintf(&data->file.path, "%s/perf.data", data->path) < 0)
+			return -1;
+	}
 
 	if (perf_data__is_write(data) &&
 	    mkdir(data->path, S_IRWXU) < 0)
@@ -333,8 +348,10 @@ int perf_data__open(struct perf_data *data)
 	if (check_backup(data))
 		return -1;
 
-	if (perf_data__is_read(data))
+	if (perf_data__is_read(data)) {
 		data->is_dir = is_dir(data);
+		data->is_multi_file = is_multi_file(data);
+	}
 
 	return perf_data__is_dir(data) ?
 	       open_dir(data) : open_file_dup(data);
@@ -406,7 +423,7 @@ unsigned long perf_data__size(struct perf_data *data)
 	u64 size = data->file.size;
 	int i;
 
-	if (!data->is_dir)
+	if (!data->is_multi_file)
 		return size;
 
 	for (i = 0; i < data->dir.nr; i++) {
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 259868a39019..0c5994d969c7 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -20,6 +20,7 @@ struct perf_data {
 	struct perf_data_file	 file;
 	bool			 is_pipe;
 	bool			 is_dir;
+	bool			 is_multi_file;
 	bool			 force;
 	enum perf_data_mode	 mode;
 
@@ -50,6 +51,11 @@ static inline bool perf_data__is_dir(struct perf_data *data)
 	return data->is_dir;
 }
 
+static inline bool perf_data__is_multi_file(struct perf_data *data)
+{
+	return data->is_multi_file;
+}
+
 static inline int perf_data__fd(struct perf_data *data)
 {
 	return data->file.fd;
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 999dac41871e..73ad217958b8 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -53,6 +53,7 @@ enum perf_header_version {
 };
 
 enum perf_dir_version {
+	PERF_DIR_SINGLE_FILE	= 0,
 	PERF_DIR_VERSION	= 1,
 };
 
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 2b583e6adb49..6dd04bd092d1 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -222,7 +222,7 @@ struct perf_session *perf_session__new(struct perf_data *data,
 			perf_evlist__init_trace_event_sample_raw(session->evlist);
 
 			/* Open the directory data. */
-			if (data->is_dir && perf_data__open_dir(data))
+			if (data->is_multi_file && perf_data__open_dir(data))
 				goto out_delete;
 		}
 	} else  {
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 32322a20a68b..5ca7490afdd1 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -189,6 +189,7 @@ int rm_rf_perf_data(const char *path)
 	const char *pat[] = {
 		"header",
 		"data.*",
+		"perf.data",
 		NULL,
 	};
 
-- 
2.17.1


  reply	other threads:[~2019-09-16  8:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16  8:56 [PATCH RFC 0/2] perf record: Put a copy of kcore into the perf.data directory Adrian Hunter
2019-09-16  8:56 ` Adrian Hunter [this message]
2019-09-23 21:34   ` [PATCH RFC 1/2] perf tools: Support single perf.data file directory Jiri Olsa
2019-09-24  9:12     ` Adrian Hunter
2019-09-24 11:12       ` Jiri Olsa
2019-09-24 11:51         ` Adrian Hunter
2019-09-24 12:03           ` Jiri Olsa
2019-09-16  8:56 ` [PATCH RFC 2/2] perf record: Put a copy of kcore into the perf.data directory Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190916085646.6199-2-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.