From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A71A4C2D0E2 for ; Tue, 22 Sep 2020 22:51:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60A07221EB for ; Tue, 22 Sep 2020 22:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600815107; bh=qq+DUN542aiFcb+N1NsHMIqkDy3BEsej7CqLonsoQ+c=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=HZ1g3xNuuIkp+wWAOU4wS7KdQRgvOgWO0Fq47Sdn7LDH13+SRoP4Ehx0MvTIo8ME5 pQNXYfvEIW4xO+I0O1gnUFvIASIfgJTrnKzC3FEpDktTWnzcGz9R47TTYmh4nHMjUW uxKOJFmUVI/BoDbaHmFjTBedQtkKCdr3BZjEIKqs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726863AbgIVWvq (ORCPT ); Tue, 22 Sep 2020 18:51:46 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35587 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbgIVWvp (ORCPT ); Tue, 22 Sep 2020 18:51:45 -0400 Received: by mail-wm1-f66.google.com with SMTP id y15so5000047wmi.0 for ; Tue, 22 Sep 2020 15:51:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bM4FuUUThgGr/nHgvLB12fnWHlJG+spkwb3OFZY6Qa0=; b=oUi0ZLJNHyQxQI9tA2ZYqBD831EATmC8AU7JBlhFY2E+1RJTxGT4xaPHpXDrxS0x5K rFHXOqL9JjhOTX/Kkx12ht8UjvQ35kqeZB6nkhCPouo/k9ZO8GcRIJCLSs+F38vd8z26 6K3aRIOg1BicBeaajVa8I+n2Oi0MpjDMejNtNJNI3+JVwh2Ja+gRqqQQ3DnLn8LHV57F CS3TUT3TW67rO0P3pwo1MK9WVVjonQGQfTBywm45cpTaMXUqpDGWoCi6NuKgFeHw+yqT iNaZ8MZjxF6akWmoLcQNbEb7CDoUXpsj06REv6+5MQQRWJ1Fud5sSQWcHoWrZeffBHMO rABg== X-Gm-Message-State: AOAM531rHDEUjuQ9vl7dmEsEXJ+tDvZeEzx+5snTvQfuPbi/vmpW1Pmd 8KvRwmJSSoLEWRoWo3eNIwNWQuciU2kHtTlu+is= X-Google-Smtp-Source: ABdhPJyudrv5/Mhq8Ed18r1aqmKDvGf3tRaOR0WUlvXswyDhqG5r2+bMjbR9hPp9oOSOKkjxDCjP8LYNsJ7p/ywr3Tg= X-Received: by 2002:a1c:6341:: with SMTP id x62mr3282156wmb.70.1600815104011; Tue, 22 Sep 2020 15:51:44 -0700 (PDT) MIME-Version: 1.0 References: <20200921094610.83736-1-namhyung@kernel.org> <20200921094610.83736-3-namhyung@kernel.org> <20200922214033.GD2893484@krava> In-Reply-To: <20200922214033.GD2893484@krava> From: Namhyung Kim Date: Wed, 23 Sep 2020 07:51:33 +0900 Message-ID: Subject: Re: [PATCH 2/5] perf stat: Add --for-each-cgroup option To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra , Mark Rutland , Alexander Shishkin , LKML , Stephane Eranian , Andi Kleen , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 23, 2020 at 6:40 AM Jiri Olsa wrote: > > 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? AFAIK non-group events are treated as a leader of its own group. So evsel__is_group_leader() will return true for cache-misses. Thanks Namhyung > > > + > > + evlist__add(tmp_list, evsel); > > + } > > + /* cgroup__new() has a refcount, release it here */ > > + cgroup__put(cgrp); > > + nr_cgroups++; > > SNIP >