From: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Jiri Olsa <jolsa@redhat.com>,
Stephane Eranian <eranian@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Namhyung Kim <namhyung.kim@lge.com>
Subject: Re: [PATCH 02/12] perf header: Add HEADER_GROUP_DESC feature
Date: Mon, 12 Nov 2012 14:45:34 -0300 [thread overview]
Message-ID: <20121112174534.GF18978@ghostprotocols.net> (raw)
In-Reply-To: <1352479414-2324-3-git-send-email-namhyung@kernel.org>
Em Sat, Nov 10, 2012 at 01:43:24AM +0900, Namhyung Kim escreveu:
> From: Namhyung Kim <namhyung.kim@lge.com>
>
> Save group relationship information so that it can be restored when
> perf report is running.
>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Stephane Eranian <eranian@google.com>
> Acked-by: Jiri Olsa <jolsa@redhat.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
<SNIP>
> +static int process_group_desc(struct perf_file_section *section __maybe_unused,
> + struct perf_header *ph, int fd,
> + void *data __maybe_unused)
> +{
> + size_t ret = -1;
why initialize ret if the first thing you do with it is...
> + u32 i, nr, nr_groups;
> + struct perf_session *session;
> + struct perf_evsel *evsel, *leader = NULL;
> + struct group_desc {
> + char *name;
> + u32 leader_idx;
> + u32 nr_members;
> + } *desc;
> +
> + ret = read(fd, &nr_groups, sizeof(nr_groups));
assign another value?
We need to use readn instead of read, and not use ret here, just do
if (read(fd, &nr_groups, sizeof(nr_groups)) != sizeof(nr_groups))
> + if (ret != sizeof(nr_groups))
> + return -1;
> +
> + if (ph->needs_swap)
> + nr_groups = bswap_32(nr_groups);
> +
> + ph->env.nr_groups = nr_groups;
> + if (!nr_groups) {
> + pr_debug("group desc not available\n");
> + return 0;
> + }
> +
> + desc = calloc(nr_groups, sizeof(*desc));
> + if (!desc)
> + return -1;
> +
> + for (i = 0; i < nr_groups; i++) {
> + desc[i].name = do_read_string(fd, ph);
> + if (!desc[i].name)
> + goto out_free;
> +
> + ret = read(fd, &desc[i].leader_idx, sizeof(u32));
> + if (ret != sizeof(u32))
> + goto out_free;
ditto
> +
> + ret = read(fd, &desc[i].nr_members, sizeof(u32));
> + if (ret != sizeof(u32))
> + goto out_free;
ditto
> +
> + if (ph->needs_swap) {
> + desc[i].leader_idx = bswap_32(desc[i].leader_idx);
> + desc[i].nr_members = bswap_32(desc[i].nr_members);
> + }
> + }
> +
> + /*
> + * Rebuild group relationship based on the group_desc
> + */
> + session = container_of(ph, struct perf_session, header);
> + session->evlist->nr_groups = nr_groups;
> +
> + i = nr = 0;
> + list_for_each_entry(evsel, &session->evlist->entries, node) {
> + if (evsel->idx == (int) desc[i].leader_idx) {
> + evsel->leader = NULL;
Humm, isn't it better to set evsel->leader to evsel, that way all
members in a group have its evsel->leader pointing to the leader and for
things like the group idx we can do just:
evsel->idx - evsel->leader->idx
avoiding the need to special case the leader, will do that.
> + /* {anon_group} is a dummy name */
> + if (strcmp(desc[i].name, "{anon_group}"))
> + evsel->group_name = desc[i].name;
> + evsel->nr_members = desc[i].nr_members;
> +
> + BUG_ON(i >= nr_groups);
> + BUG_ON(nr > 0);
BUG_ON here is way too extreme, we should just bail out, testing and if
the problem is found, goto out_free
> + leader = evsel;
> + nr = evsel->nr_members;
> + i++;
> + } else if (nr) {
Humm, do we really need to test against nr? Or even use nr at all?
> + /* This is a group member */
> + evsel->leader = leader;
> + /* group_idx starts from 0 */
> + evsel->group_idx = leader->nr_members - nr;
> + nr--;
> + }
> + }
> +
> + BUG_ON(i != nr_groups);
> + BUG_ON(nr != 0);
Too extreme, goto out_free.
And just before out_free we need to set ret = 0, otherwise we will
return...
> +out_free:
> + while ((int) --i >= 0)
> + free(desc[i].name);
> + free(desc);
here, whatever value was in ret, in this patch it will be, if all goes
well, sizeof(u32) :-)
> + return ret;
> +}
> +
> struct feature_ops {
> int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
> void (*print)(struct perf_header *h, int fd, FILE *fp);
> @@ -1986,6 +2137,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
> FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology),
> FEAT_OPA(HEADER_BRANCH_STACK, branch_stack),
> FEAT_OPP(HEADER_PMU_MAPPINGS, pmu_mappings),
> + FEAT_OPP(HEADER_GROUP_DESC, group_desc),
> };
>
> struct header_print_data {
> diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
> index 5f1cd6884f37..e3e7fb490310 100644
> --- a/tools/perf/util/header.h
> +++ b/tools/perf/util/header.h
> @@ -29,6 +29,7 @@ enum {
> HEADER_NUMA_TOPOLOGY,
> HEADER_BRANCH_STACK,
> HEADER_PMU_MAPPINGS,
> + HEADER_GROUP_DESC,
> HEADER_LAST_FEATURE,
> HEADER_FEAT_BITS = 256,
> };
Here we're adding holes to the struct:
> @@ -79,6 +80,7 @@ struct perf_session_env {
> char *numa_nodes;
> int nr_pmu_mappings;
4 byte hole
> char *pmu_mappings;
4 byte hole
> + int nr_groups;
I'm working on a patch implementing my suggestions.
> };
>
> struct perf_header {
> --
> 1.7.9.2
next prev parent reply other threads:[~2012-11-12 17:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-09 16:43 [PATCHSET 00/12] perf report: Add support for event group view (v5) Namhyung Kim
2012-11-09 16:43 ` [PATCH 01/12] perf tools: Keep group information Namhyung Kim
2012-11-12 17:08 ` Arnaldo Carvalho de Melo
2012-11-13 1:29 ` Namhyung Kim
2012-11-09 16:43 ` [PATCH 02/12] perf header: Add HEADER_GROUP_DESC feature Namhyung Kim
2012-11-12 17:45 ` Arnaldo Carvalho de Melo [this message]
2012-11-13 1:51 ` Namhyung Kim
2012-11-09 16:43 ` [PATCH 03/12] perf hists: Collapse group hist_entries to a leader Namhyung Kim
2012-11-09 16:43 ` [PATCH 04/12] perf hists: Maintain total periods of group members in the leader Namhyung Kim
2012-11-09 16:43 ` [PATCH 05/12] perf report: Make another loop for output resorting Namhyung Kim
2012-11-09 16:43 ` [PATCH 06/12] perf ui/hist: Add support for event group view Namhyung Kim
2012-11-09 16:43 ` [PATCH 07/12] perf ui/browser: " Namhyung Kim
2012-11-09 16:43 ` [PATCH 08/12] perf ui/gtk: " Namhyung Kim
2012-11-09 16:43 ` [PATCH 09/12] perf report: Bypass non-leader events when event group is enabled Namhyung Kim
2012-11-09 16:43 ` [PATCH 10/12] perf report: Show group description " Namhyung Kim
2012-11-09 16:43 ` [PATCH 11/12] perf report: Add --group option Namhyung Kim
2012-11-09 16:43 ` [PATCH 12/12] perf report: Add report.group config option Namhyung Kim
-- strict thread matches above, loose matches on Subject: below --
2012-10-23 7:43 [PATCH 00/12] perf report: Add support for event group view (v4) Namhyung Kim
2012-10-23 7:43 ` [PATCH 02/12] perf header: Add HEADER_GROUP_DESC feature Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121112174534.GF18978@ghostprotocols.net \
--to=acme@ghostprotocols.net \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).