lkml.org 
[lkml]   [2020]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/4] perf stat: Add --for-each-cgroup option
On Wed, Sep 16, 2020 at 03:31:27PM +0900, Namhyung Kim wrote:

SNIP

> +int evlist__expand_cgroup(struct evlist *evlist, const char *str)
> +{
> + struct evlist *orig_list, *tmp_list;
> + struct evsel *pos, *evsel, *leader;
> + struct cgroup *cgrp = NULL;
> + const char *p, *e, *eos = str + strlen(str);
> + int ret = -1;
> +
> + if (evlist->core.nr_entries == 0) {
> + fprintf(stderr, "must define events before cgroups\n");
> + return -EINVAL;
> + }
> +
> + orig_list = evlist__new();
> + tmp_list = evlist__new();
> + if (orig_list == NULL || tmp_list == NULL) {
> + fprintf(stderr, "memory allocation failed\n");
> + return -ENOMEM;
> + }
> +
> + /* save original events and init evlist */
> + perf_evlist__splice_list_tail(orig_list, &evlist->core.entries);
> + evlist->core.nr_entries = 0;
> +
> + for (;;) {
> + p = strchr(str, ',');
> + e = p ? p : eos;
> +
> + /* allow empty cgroups, i.e., skip */
> + if (e - str) {
> + /* termination added */
> + char *name = strndup(str, e - str);
> + if (!name)
> + break;
> +
> + cgrp = cgroup__new(name);
> + free(name);
> + if (cgrp == NULL)
> + break;
> + } else {
> + cgrp = NULL;
> + }
> +
> + leader = NULL;
> + evlist__for_each_entry(orig_list, pos) {
> + evsel = evsel__clone(pos);

missing check on evsel == NULL

jirka

> + cgroup__put(evsel->cgrp);
> + evsel->cgrp = cgroup__get(cgrp);
> +
> + if (evsel__is_group_leader(pos))
> + leader = evsel;
> + evsel->leader = leader;
> +
> + evlist__add(tmp_list, evsel);
> + }
> + /* cgroup__new() has a refcount, release it here */
> + cgroup__put(cgrp);
> + nr_cgroups++;
> +
> + perf_evlist__splice_list_tail(evlist, &tmp_list->core.entries);
> + tmp_list->core.nr_entries = 0;
> +
> + if (!p) {
> + ret = 0;
> + break;
> + }
> + str = p+1;
> + }
> + evlist__delete(orig_list);
> + evlist__delete(tmp_list);
> +
> + return ret;
> +}

SNIP

\
 
 \ /
  Last update: 2020-09-18 15:35    [W:0.064 / U:6.836 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site