Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4256752pxk; Tue, 22 Sep 2020 14:43:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXi9dzeQnVZD39LQgALdkYwdrXZhd8uzzWhHYVc2JbUBfsRmlpZo+2mCxMkM3/WlkPrumf X-Received: by 2002:aa7:dc18:: with SMTP id b24mr6391722edu.285.1600810989316; Tue, 22 Sep 2020 14:43:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600810989; cv=none; d=google.com; s=arc-20160816; b=RzLaeIBvb80lYxiquknBMpf74/wPP6L0cqkGxaTPVo1Di4eF4CqEz1tlEYQ0JRMcrt +wmruez6WL33e2cYAuMyjOI/g1OW/+bs3+ozk5WdmgfLmb1GL27yrXAuHUt8kNCrrf3b 9CWoJHQNm8wZJBaU1tHjsA/AaN+0KHNOA4mZlweo9DN7ExFuUHhHBljGqphYIfcgwXJC fkW7eENsyArvImD378GlCyjYOzc0F+3BuXeDzkdjgE/weuznITykUMAoOGr7i++YPtNZ nA7CQ20sgmN3GTP8s2kXje5lTwhdN8LqDXMHfOdnhfk4ogAkDfw6CrUSlogp62lnIIzV HYuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wvKLK45f+pV+aZpx2RncLiRV10TEdFA1YgHDgtiks7E=; b=U+GIVa8JV70pvp4u9h5DFlNDCXcf/ZyqFgaeKV4ksdDsMmh+jpKBXGyx9CAvgc2P4Z 7IZCG5IjZL9kQIbsTkgavHC2M9ifGllxvIp474yg8gRfCADO6rgxN2lgL+eO6kw4uD2O 9SbdKjOvz6JeX7ifvvZN1pBi7qF/yBvcXoSLv2Ek94gYCFjo9BCnoB0WQY5LM38d5MgL ONItb+eXNsQFLYvVOSPOlfpYxPV0KZ3VFD3Mg8DTATtOOO7gcGReGsPz2bXWrwHsv6g7 s68OUp/C9a2SQ4IXBjDkuTgLL7jn1pt8ElJ9fztFQT2Wxzdp5yV44ExUt+U6HmTgN7xN 7efQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UOz4kyop; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si11059837edr.606.2020.09.22.14.42.03; Tue, 22 Sep 2020 14:43:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UOz4kyop; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726615AbgIVVkm (ORCPT + 99 others); Tue, 22 Sep 2020 17:40:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37611 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbgIVVkm (ORCPT ); Tue, 22 Sep 2020 17:40:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600810841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wvKLK45f+pV+aZpx2RncLiRV10TEdFA1YgHDgtiks7E=; b=UOz4kyopzxWcuCgaGctR4lrf+6REmhAepLicHTdRpZC16iFQxninSLfJvrV5CS36XzuCNt pLFSdhf3YUTpzyyh0O/GakB34qdZzUthUG0MlAtL7iQUWYqnffg8KdWfwin33UAenPnktw AgBSm52n9MW9q+r4gghWH8uZDzCAZvA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-jKa5IYJEOQqvVwTebOPlGQ-1; Tue, 22 Sep 2020 17:40:39 -0400 X-MC-Unique: jKa5IYJEOQqvVwTebOPlGQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21AFD186DD2C; Tue, 22 Sep 2020 21:40:37 +0000 (UTC) Received: from krava (ovpn-112-28.ams2.redhat.com [10.36.112.28]) by smtp.corp.redhat.com (Postfix) with SMTP id 874C073689; Tue, 22 Sep 2020 21:40:34 +0000 (UTC) Date: Tue, 22 Sep 2020 23:40:33 +0200 From: Jiri Olsa To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Andi Kleen , Ian Rogers Subject: Re: [PATCH 2/5] perf stat: Add --for-each-cgroup option Message-ID: <20200922214033.GD2893484@krava> References: <20200921094610.83736-1-namhyung@kernel.org> <20200921094610.83736-3-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921094610.83736-3-namhyung@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 06:46:07PM +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) > + goto out_err; > + > + cgrp = cgroup__new(name); > + free(name); > + if (cgrp == NULL) > + goto out_err; > + } else { > + cgrp = NULL; > + } > + > + leader = NULL; > + evlist__for_each_entry(orig_list, pos) { > + evsel = evsel__clone(pos); > + if (evsel == NULL) > + goto out_err; > + > + cgroup__put(evsel->cgrp); > + evsel->cgrp = cgroup__get(cgrp); > + > + if (evsel__is_group_leader(pos)) > + leader = evsel; > + evsel->leader = leader; hum, will this work if there's standalone event after group? like: {cycles,instructions},cache-misses cache-misses will get cycles as group leader no? jirka > + > + evlist__add(tmp_list, evsel); > + } > + /* cgroup__new() has a refcount, release it here */ > + cgroup__put(cgrp); > + nr_cgroups++; SNIP