[RFC PATCH v8 2/7] perf data: Allow to use given fd in data->file.fd

weilin.wang@intel.com posted 7 patches 1 year, 9 months ago
There is a newer version of this series
[RFC PATCH v8 2/7] perf data: Allow to use given fd in data->file.fd
Posted by weilin.wang@intel.com 1 year, 9 months ago
From: Weilin Wang <weilin.wang@intel.com>

When in PIPE mode, allow to use fd dynamically opened and asigned to
data->file.fd instead of STDIN_FILENO or STDOUT_FILENO.

Signed-off-by: Weilin Wang <weilin.wang@intel.com>
---
 tools/perf/util/data.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 08c4bfbd817f..98661ede2a73 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -204,7 +204,12 @@ static bool check_pipe(struct perf_data *data)
 				data->file.fd = fd;
 				data->use_stdio = false;
 			}
-		} else {
+
+		/*
+		 * When is_pipe and data->file.fd is given, use given fd
+		 * instead of STDIN_FILENO or STDOUT_FILENO
+		 */
+		} else if (data->file.fd <= 0) {
 			data->file.fd = fd;
 		}
 	}
-- 
2.43.0
Re: [RFC PATCH v8 2/7] perf data: Allow to use given fd in data->file.fd
Posted by Ian Rogers 1 year, 9 months ago
On Tue, May 14, 2024 at 10:44 PM <weilin.wang@intel.com> wrote:
>
> From: Weilin Wang <weilin.wang@intel.com>
>
> When in PIPE mode, allow to use fd dynamically opened and asigned to
> data->file.fd instead of STDIN_FILENO or STDOUT_FILENO.
>
> Signed-off-by: Weilin Wang <weilin.wang@intel.com>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/util/data.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> index 08c4bfbd817f..98661ede2a73 100644
> --- a/tools/perf/util/data.c
> +++ b/tools/perf/util/data.c
> @@ -204,7 +204,12 @@ static bool check_pipe(struct perf_data *data)
>                                 data->file.fd = fd;
>                                 data->use_stdio = false;
>                         }
> -               } else {
> +
> +               /*
> +                * When is_pipe and data->file.fd is given, use given fd
> +                * instead of STDIN_FILENO or STDOUT_FILENO
> +                */
> +               } else if (data->file.fd <= 0) {
>                         data->file.fd = fd;
>                 }
>         }
> --
> 2.43.0
>