Re: [PATCH 5/7] perf tools: Introduce perf_target__strerror()

From: David Ahern
Date: Mon May 07 2012 - 13:43:10 EST


On 5/7/12 11:29 AM, Arnaldo Carvalho de Melo wrote:
Em Mon, May 07, 2012 at 02:09:02PM +0900, Namhyung Kim escreveu:
The perf_target__strerror() sets @buf to a string that
describes the (perf_target-specific) error condition
that is passed via @errnum.

This is similar to strerror_r() and does same thing if
@errnum has a standard errno value.

This has a problem: why should I be warned when I do, as root:

# perf top -u acme

It warns me that "UID switch overriding SYSTEM", yeah, right that is
what I asked, no need to tell me that :-)

So what is missing in this case is that top starts with system_wide set,
not from the command line.

I.e. if I had asked for:

# perf top --system_wide --user acme

Ok, the warning would make sense.

So just special case this in the top case, I think, like the patch
below, ack?

I'll fold this into this patch and add a [ committer note: ... ]

Ack?

- Arnaldo

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index a2518fc..780791f 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1257,7 +1257,16 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
setup_browser(false);

status = perf_target__validate(&top.target);
- if (status != PERF_ERRNO_TARGET__SUCCESS) {
+ if (status != PERF_ERRNO_TARGET__SUCCESS&&
+ status != PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM&&
+ status != PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM) {
+ /*
+ * Top doesn't provide an explicit way to ask for system wide
+ * profiling, it is the default.
+ *
+ * So we shouldn't warn the user when he/she asks for --pid or
+ * --uid.
+ */
perf_target__strerror(&top.target, status, errbuf, BUFSIZ);
ui__warning("%s", errbuf);
}

Seems like we should avoid the propagation of the errnos beyond the depths of the library part. For perf-top why not default to nothing set and if the user does not request one, set system wide. i.e, following Patch 6 in this set do:

if (perf_target__none(&top.target)
top.target.system_wide = true;

David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/