Commit 14552063 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf data: Add perf_data__(create_dir|close_dir) functions

Add perf_data__create_dir() to create nr files inside 'struct perf_data'
path directory:

  int perf_data__create_dir(struct perf_data *data, int nr);

and function to close that data:

  void perf_data__close_dir(struct perf_data *data);
Signed-off-by: default avatarJiri 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-9-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ccb7a71d
...@@ -7,11 +7,58 @@ ...@@ -7,11 +7,58 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <asm/bug.h>
#include "data.h" #include "data.h"
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
static void close_dir(struct perf_data_file *files, int nr)
{
while (--nr >= 1) {
close(files[nr].fd);
free(files[nr].path);
}
free(files);
}
void perf_data__close_dir(struct perf_data *data)
{
close_dir(data->dir.files, data->dir.nr);
}
int perf_data__create_dir(struct perf_data *data, int nr)
{
struct perf_data_file *files = NULL;
int i, ret = -1;
files = zalloc(nr * sizeof(*files));
if (!files)
return -ENOMEM;
data->dir.files = files;
data->dir.nr = nr;
for (i = 0; i < nr; i++) {
struct perf_data_file *file = &files[i];
if (asprintf(&file->path, "%s/data.%d", data->path, i) < 0)
goto out_err;
ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (ret < 0)
goto out_err;
file->fd = ret;
}
return 0;
out_err:
close_dir(files, i);
return ret;
}
static bool check_pipe(struct perf_data *data) static bool check_pipe(struct perf_data *data)
{ {
struct stat st; struct stat st;
......
...@@ -21,6 +21,11 @@ struct perf_data { ...@@ -21,6 +21,11 @@ struct perf_data {
bool is_pipe; bool is_pipe;
bool force; bool force;
enum perf_data_mode mode; enum perf_data_mode mode;
struct {
struct perf_data_file *files;
int nr;
} dir;
}; };
static inline bool perf_data__is_read(struct perf_data *data) static inline bool perf_data__is_read(struct perf_data *data)
...@@ -64,4 +69,7 @@ ssize_t perf_data_file__write(struct perf_data_file *file, ...@@ -64,4 +69,7 @@ ssize_t perf_data_file__write(struct perf_data_file *file,
int perf_data__switch(struct perf_data *data, int perf_data__switch(struct perf_data *data,
const char *postfix, const char *postfix,
size_t pos, bool at_exit); size_t pos, bool at_exit);
int perf_data__create_dir(struct perf_data *data, int nr);
void perf_data__close_dir(struct perf_data *data);
#endif /* __PERF_DATA_H */ #endif /* __PERF_DATA_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment