linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Alexey Budankov <alexey.budankov@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 25/37] perf data: Add perf_data__open_dir_data function
Date: Mon, 25 Feb 2019 18:20:23 -0300	[thread overview]
Message-ID: <20190225212035.24781-26-acme@kernel.org> (raw)
In-Reply-To: <20190225212035.24781-1-acme@kernel.org>

From: Jiri Olsa <jolsa@kernel.org>

Add perf_data__open_dir_data to open files inside 'struct perf_data'
path directory:

   static int perf_data__open_dir(struct perf_data *data);

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190224190656.30163-10-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/data.c | 59 ++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/data.h |  1 +
 2 files changed, 60 insertions(+)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 005b3909d1dc..7bd5ddeb7a41 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -8,6 +8,8 @@
 #include <unistd.h>
 #include <string.h>
 #include <asm/bug.h>
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "data.h"
 #include "util.h"
@@ -59,6 +61,63 @@ int perf_data__create_dir(struct perf_data *data, int nr)
 	return ret;
 }
 
+int perf_data__open_dir(struct perf_data *data)
+{
+	struct perf_data_file *files = NULL;
+	struct dirent *dent;
+	int ret = -1;
+	DIR *dir;
+	int nr = 0;
+
+	dir = opendir(data->path);
+	if (!dir)
+		return -EINVAL;
+
+	while ((dent = readdir(dir)) != NULL) {
+		struct perf_data_file *file;
+		char path[PATH_MAX];
+		struct stat st;
+
+		snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name);
+		if (stat(path, &st))
+			continue;
+
+		if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data", 4))
+			continue;
+
+		ret = -ENOMEM;
+
+		file = realloc(files, (nr + 1) * sizeof(*files));
+		if (!file)
+			goto out_err;
+
+		files = file;
+		file = &files[nr++];
+
+		file->path = strdup(path);
+		if (!file->path)
+			goto out_err;
+
+		ret = open(file->path, O_RDONLY);
+		if (ret < 0)
+			goto out_err;
+
+		file->fd = ret;
+		file->size = st.st_size;
+	}
+
+	if (!files)
+		return -EINVAL;
+
+	data->dir.files = files;
+	data->dir.nr    = nr;
+	return 0;
+
+out_err:
+	close_dir(files, nr);
+	return ret;
+}
+
 static bool check_pipe(struct perf_data *data)
 {
 	struct stat st;
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 2d0d015a7d4d..14b47be2bd69 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -71,5 +71,6 @@ int perf_data__switch(struct perf_data *data,
 			   size_t pos, bool at_exit);
 
 int perf_data__create_dir(struct perf_data *data, int nr);
+int perf_data__open_dir(struct perf_data *data);
 void perf_data__close_dir(struct perf_data *data);
 #endif /* __PERF_DATA_H */
-- 
2.20.1


  parent reply	other threads:[~2019-02-25 21:53 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 21:19 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-02-25 21:19 ` [PATCH 01/37] perf annotate: Fix getting source line failure Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 02/37] perf thread-stack: Improve thread_stack__no_call_return() Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 03/37] perf thread-stack: Hide x86 retpolines Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 04/37] perf scripts python: exported-sql-viewer.py: Fix missing shebang Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 05/37] perf scripts python: exported-sql-viewer.py: Remove leftover debugging prints Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 06/37] perf scripts python: exported-sql-viewer.py: Hide Call Graph option if no calls table Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 07/37] perf scripts python: exported-sql-viewer.py: Move column headers Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 08/37] perf scripts python: exported-sql-viewer.py: Factor out ReportDialogBase Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 09/37] perf scripts python: exported-sql-viewer.py: Factor out ReportVars Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 10/37] perf scripts python: exported-sql-viewer.py: Move report name into ReportVars Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 11/37] perf scripts python: exported-sql-viewer.py: Create new dialog data item classes Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 12/37] perf scripts python: exported-sql-viewer.py: Remove SQLTableDialogDataItem Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 13/37] perf scripts python: exported-sql-viewer.py: Remove no selection error Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 14/37] perf scripts python: exported-sql-viewer.py: Add top calls report Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 15/37] perf: Copy parent's address filter offsets on clone Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 16/37] perf, pt, coresight: Fix address filters for vmas with non-zero offset Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 17/37] perf data: Move size to struct perf_data_file Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 18/37] perf data: Add global path holder Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 19/37] perf tools: Add depth checking to rm_rf Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 20/37] perf tools: Add pattern name " Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 21/37] perf tools: Add rm_rf_perf_data function Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 22/37] perf data: Make check_backup work over directories Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 23/37] perf data: Fail check_backup in case of error Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 24/37] perf data: Add perf_data__(create_dir|close_dir) functions Arnaldo Carvalho de Melo
2019-02-25 21:20 ` Arnaldo Carvalho de Melo [this message]
2019-02-25 21:20 ` [PATCH 26/37] perf script: Handle missing fields with -F + Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 27/37] perf tools: Add perf_exe() helper to find perf binary Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 28/37] perf script python: Add Python3 support to netdev-times.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 29/37] perf script python: Add Python3 support to failed-syscalls-by-pid.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 30/37] perf script python: Add Python3 support to mem-phys-addr.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 31/37] perf script python: Add Python3 support to net_dropmonitor.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 32/37] perf script python: Add Python3 support to powerpc-hcalls.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 33/37] perf script python: Add Python3 support to sctop.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 34/37] perf script python: Add Python3 support to stackcollapse.py Arnaldo Carvalho de Melo
2019-02-26 11:49   ` Paolo Bonzini
2019-02-25 21:20 ` [PATCH 35/37] perf script python: Add Python3 support to stat-cpi.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 36/37] perf script python: Add Python3 support to syscall-counts.py Arnaldo Carvalho de Melo
2019-02-25 21:20 ` [PATCH 37/37] perf script python: Add Python3 support to syscall-counts-by-pid.py Arnaldo Carvalho de Melo
2019-02-28  7:31 ` [GIT PULL] perf/core improvements and fixes Ingo Molnar

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=20190225212035.24781-26-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=williams@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).