linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf record: improve error message of -p not_existing_pid
@ 2022-08-12 11:40 Martin Liška
  2022-08-12 13:27 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2022-08-12 11:40 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users; +Cc: Arnaldo Carvalho de Melo

When one uses -p $not_existing_pid, the output of --help is printed:

$ perf record -p 123456789 2>&1 | head -n3

 Usage: perf record [<options>] [<command>]
    or: perf record [<options>] -- <command> [<options>]

Let's change it something similar what perf top -p $not_existing_pid
prints:

$ ./perf top -p 123456789 --stdio
Error:
Couldn't create thread/CPU maps: No such process

Newly suggested error message:

$ ./perf record -p 123456789
Couldn't create thread/CPU maps: No such process

Signed-off-by: Martin Liska <mliska@suse.cz>
---
 tools/perf/builtin-record.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index cf5c5379ceaa..4713f0f3a6cf 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -3996,8 +3996,15 @@ int cmd_record(int argc, const char **argv)
 		arch__add_leaf_frame_record_opts(&rec->opts);
 
 	err = -ENOMEM;
-	if (evlist__create_maps(rec->evlist, &rec->opts.target) < 0)
-		usage_with_options(record_usage, record_options);
+	if (evlist__create_maps(rec->evlist, &rec->opts.target) < 0) {
+		if (rec->opts.target.pid != NULL) {
+			pr_err("Couldn't create thread/CPU maps: %s\n",
+				errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
+			goto out;
+		}
+		else
+			usage_with_options(record_usage, record_options);
+	}
 
 	err = auxtrace_record__options(rec->itr, rec->evlist, &rec->opts);
 	if (err)
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf record: improve error message of -p not_existing_pid
  2022-08-12 11:40 [PATCH] perf record: improve error message of -p not_existing_pid Martin Liška
@ 2022-08-12 13:27 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-08-12 13:27 UTC (permalink / raw)
  To: Martin Liška; +Cc: linux-kernel, linux-perf-users

Em Fri, Aug 12, 2022 at 01:40:49PM +0200, Martin Liška escreveu:
> When one uses -p $not_existing_pid, the output of --help is printed:
> 
> $ perf record -p 123456789 2>&1 | head -n3
> 
>  Usage: perf record [<options>] [<command>]
>     or: perf record [<options>] -- <command> [<options>]
> 
> Let's change it something similar what perf top -p $not_existing_pid
> prints:
> 
> $ ./perf top -p 123456789 --stdio
> Error:
> Couldn't create thread/CPU maps: No such process
> 
> Newly suggested error message:
> 
> $ ./perf record -p 123456789
> Couldn't create thread/CPU maps: No such process

Thanks, tested and applied.

- Arnaldo

 
> Signed-off-by: Martin Liska <mliska@suse.cz>
> ---
>  tools/perf/builtin-record.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index cf5c5379ceaa..4713f0f3a6cf 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -3996,8 +3996,15 @@ int cmd_record(int argc, const char **argv)
>  		arch__add_leaf_frame_record_opts(&rec->opts);
>  
>  	err = -ENOMEM;
> -	if (evlist__create_maps(rec->evlist, &rec->opts.target) < 0)
> -		usage_with_options(record_usage, record_options);
> +	if (evlist__create_maps(rec->evlist, &rec->opts.target) < 0) {
> +		if (rec->opts.target.pid != NULL) {
> +			pr_err("Couldn't create thread/CPU maps: %s\n",
> +				errno == ENOENT ? "No such process" : str_error_r(errno, errbuf, sizeof(errbuf)));
> +			goto out;
> +		}
> +		else
> +			usage_with_options(record_usage, record_options);
> +	}
>  
>  	err = auxtrace_record__options(rec->itr, rec->evlist, &rec->opts);
>  	if (err)
> -- 
> 2.37.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-12 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-12 11:40 [PATCH] perf record: improve error message of -p not_existing_pid Martin Liška
2022-08-12 13:27 ` Arnaldo Carvalho de Melo

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).