lkml.org 
[lkml]   [2017]   [Oct]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V3 4/6] perf tools: add perf_data_file__open_tmp
On Fri, Oct 20, 2017 at 01:05:32PM -0700, kan.liang@intel.com wrote:
> From: Kan Liang <Kan.liang@intel.com>
>
> And an interface for perf_data_file to open tmp file.
> Automatically generate the tmp file name if it's not assigned. The name
> cannot be const char. Introduce char *tmp_path for it.
> The tmp file will be deleted after close.
>
> It will be used as per-thread file to temporarily store event synthesizd
> result in the following patch.
>
> Signed-off-by: Kan Liang <Kan.liang@intel.com>
> ---
> tools/perf/util/data.c | 26 ++++++++++++++++++++++++++
> tools/perf/util/data.h | 2 ++
> 2 files changed, 28 insertions(+)
>
> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> index 1123b30..cd6fdf9 100644
> --- a/tools/perf/util/data.c
> +++ b/tools/perf/util/data.c
> @@ -139,9 +139,35 @@ int perf_data_file__open(struct perf_data_file *file)
> return open_file(file);
> }
>
> +int perf_data_file__open_tmp(struct perf_data_file *file)
> +{
> + int fd;
> +
> + if (!file->tmp_path &&
> + (asprintf(&file->tmp_path, "perf.tmp.XXXXXX") < 0))
> + goto err;
> +
> + fd = mkstemp(file->tmp_path);
> + if (fd < 0) {
> + free(file->tmp_path);
> + goto err;
> + }
> +
> + file->fd = fd;
> + return 0;
> +err:
> + file->tmp_path = NULL;
> + return -1;
> +}
> +
> void perf_data_file__close(struct perf_data_file *file)
> {
> close(file->fd);
> + if (file->tmp_path) {
> + unlink(file->tmp_path);
> + free(file->tmp_path);
> + file->tmp_path = NULL;

we have a zfree for that

jirka

\
 
 \ /
  Last update: 2017-10-24 09:27    [W:0.109 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site