Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp680822rdb; Thu, 8 Feb 2024 19:17:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwXvI3oUru7e8jhh0xa7B+M0f503d/iwv/I9W2EjqihKGu1bo23MHBfaMk5umf6fr7tFRS X-Received: by 2002:ac8:57ce:0:b0:42b:e5e4:a6a0 with SMTP id w14-20020ac857ce000000b0042be5e4a6a0mr502227qta.24.1707448632962; Thu, 08 Feb 2024 19:17:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707448632; cv=pass; d=google.com; s=arc-20160816; b=puPA5G52mVP79iUMg55cFbdMtpiHPAp6PMgyx/ZeuUIm86FfeR93T+a16ydaeIuyrH cOtqy4fWenf4BYMyqqj0G5XBMCTyNKsrJcHmum2jMhFxc0j8Ac2JwnspC9/zqklPmkyv /vsioCTwimqrMHM4W9PrRYvN6hAXSzuILeYdU9ITpv4VJXiu5Vg82eCSMf/ljkngSpzY /874w0tsISUWa8Gowvof1lPp72YRFlfeXU4mlsMDHMHdB453lP8G7N9EvOb1UtSUW033 g6bQKZqaVDaC/nIII+5WQASKr2/Ur4qv0Dhf22Dd6vriItNG8lAeE7t1ZzEZE7kw068X asGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dEEYxQM+NSmUkZcFZV0H8H1jBOSGl1rEVsPMJ6+VB3c=; fh=zt0plezhfOHzQNKcUhw6cbwrpiODIPpAIKwspb6AtMg=; b=G5S/04mZ6ZDMaC035crw7ZfppQE+iXg4OJrZBt/rw4ALTjJ0+gGFHgC/eBg9WOQWNJ eovalVQqBOgSk4Kiw52/KteJDGmIklJwss7/DL5W2rBK33gE4wdQ6+vmXJpXL12mFarc xNUj148eBjgAMALugmF3nmYPEkDZFKNum6Zh08vVPHglD6JftyYo8GMZcbRnjJfWS8c+ E5R1dSHOKN0BIJeyXLNamoQ6OIrSO/boj5qglXpfn49/C5yatnX9nlDniZTkpqQxIXMU xHlLl3qoNvomU4EmFyif1dh2xNjWIXX/sk45Mr2Hlu9uvntdlaW8FvmmUvQQPAfpOnYt Z8iA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GrXXwEFZ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58973-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58973-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCW+anlM4vSn7pzL+p5FtVLF4egaltyarcgYulPMAm8bKcTqwntsnVdUuyYDWjtG+HigrcjHFgUmK82tC874m89ujK+4Sdak1ql1KkXFVw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n14-20020ac85a0e000000b0042c410d4447si950806qta.312.2024.02.08.19.17.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 19:17:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58973-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GrXXwEFZ; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-58973-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58973-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 23C2F1C276B4 for ; Fri, 9 Feb 2024 03:16:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 454CB17C75; Fri, 9 Feb 2024 03:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GrXXwEFZ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10140CA7F; Fri, 9 Feb 2024 03:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448495; cv=none; b=gj5YcnWX77fYQrVD0/xSphAD0LrIvxjmkCn2I2sd46RtwA6h/Yy7N+bOnSljJhoRlKbPUptsLaRU0m34GVGYPCQkHhhSLv9RY4ThEij6WAycd7zhXvy39wxX59vvuoMvb4+9dqTSKubeoB3EzQ4FM56qVPifq5l2dOJ7OR9rkGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707448495; c=relaxed/simple; bh=nwvJ4bQEjdGfxAja5WB8p9z4vCfBey7kRZHlUv8cNoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IACxRJjXL8UqG3XOYTQKlkp697zcmjP2zaAddsG7vS36mg/BYd3n7iiJy19pzHzdEKhkqXnaFI0dbvJ7+BAf6BCynQvUcSVx0AM3Qr1Ejv6Zn85aCNhKAc98VE8tJP/DCmD0zxsVPvsvkyNCrsMM4XFx6gtA9o/Vb5y7v5HW+Pw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GrXXwEFZ; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707448493; x=1738984493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nwvJ4bQEjdGfxAja5WB8p9z4vCfBey7kRZHlUv8cNoY=; b=GrXXwEFZTCDqS++vvYT9rQFT+PP9HfnlFc2/NUPyrZgqrmyTZWGKFgIR v7gPyojPnooKFDZO8BECWc5V5A/k3qjRBt2nOvows9FjOTZSFPMIoshhA lUieFzf/5jjEwT5SmZJLnSa89lbLfw7PUdRIxrSqjaqvcqV7CZI3B8CBG SwWbFd2xGp2hlwlhP0mZ7wuMQ+8g92SDNTMa9WUFjXiMFm/xEDPCJ0lhi c8rDARPyaPr759qF1mLq1j/HeYT7FO22kNUvlkcpqpBADb+AWzSQHBIos cdmPUT09DH6a9drc8LDb7RSgIAE09WQi4yfHjTwCf/kU3v+i0q31k6MDZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1257921" X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="1257921" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2024 19:14:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,255,1701158400"; d="scan'208";a="32631435" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa002.jf.intel.com with ESMTP; 08 Feb 2024 19:14:48 -0800 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Kan Liang , Namhyung Kim , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland Subject: [RFC PATCH v4 08/15] perf stat: Add build string function and topdown events handling in hardware-grouping Date: Thu, 8 Feb 2024 19:14:34 -0800 Message-ID: <20240209031441.943012-9-weilin.wang@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240209031441.943012-1-weilin.wang@intel.com> References: <20240209031441.943012-1-weilin.wang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Weilin Wang Add the function to generate final grouping strings. This function is very similar to the existing metricgroup__build_event_string() function. The difference is that the input data includes a list of grouping lists. Reviewed-by: Ian Rogers Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 97 +++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index f86e9a0b0d65..660c6b9b5fa7 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1978,6 +1978,96 @@ static int assign_event_grouping(struct metricgroup__event_info *e, return ret; } +static int hw_aware_metricgroup__build_event_string(struct list_head *group_strs, + const char *modifier, + struct list_head *groups) +{ + struct metricgroup__pmu_group_list *p; + struct metricgroup__group *g; + struct metricgroup__group_events *ge; + bool no_group = true; + int ret = 0; + +#define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) + + list_for_each_entry(p, groups, nd) { + list_for_each_entry(g, &p->group_head, nd) { + struct strbuf *events; + struct metricgroup__group_strs *new_group_str = + malloc(sizeof(struct metricgroup__group_strs)); + + if (!new_group_str) + return -ENOMEM; + strbuf_init(&new_group_str->grouping_str, 0); + events = &new_group_str->grouping_str; + ret = strbuf_addch(events, '{'); + RETURN_IF_NON_ZERO(ret); + no_group = true; + list_for_each_entry(ge, &g->event_head, nd) { + const char *sep, *rsep, *id = ge->event_name; + + pr_debug("found event %s\n", id); + + /* Separate events with commas and open the group if necessary. */ + if (!no_group) { + ret = strbuf_addch(events, ','); + RETURN_IF_NON_ZERO(ret); + } + /* + * Encode the ID as an event string. Add a qualifier for + * metric_id that is the original name except with characters + * that parse-events can't parse replaced. For example, + * 'msr@tsc@' gets added as msr/tsc,metric-id=msr!3tsc!3/ + */ + sep = strchr(id, '@'); + if (sep) { + ret = strbuf_add(events, id, sep - id); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addch(events, '/'); + RETURN_IF_NON_ZERO(ret); + rsep = strrchr(sep, '@'); + ret = strbuf_add(events, sep + 1, rsep - sep - 1); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addstr(events, ",metric-id="); + RETURN_IF_NON_ZERO(ret); + sep = rsep; + } else { + sep = strchr(id, ':'); + if (sep) { + ret = strbuf_add(events, id, sep - id); + RETURN_IF_NON_ZERO(ret); + } else { + ret = strbuf_addstr(events, id); + RETURN_IF_NON_ZERO(ret); + } + ret = strbuf_addstr(events, "/metric-id="); + RETURN_IF_NON_ZERO(ret); + } + ret = encode_metric_id(events, id); + RETURN_IF_NON_ZERO(ret); + ret = strbuf_addstr(events, "/"); + RETURN_IF_NON_ZERO(ret); + + if (sep) { + ret = strbuf_addstr(events, sep + 1); + RETURN_IF_NON_ZERO(ret); + } + if (modifier) { + ret = strbuf_addstr(events, modifier); + RETURN_IF_NON_ZERO(ret); + } + no_group = false; + } + ret = strbuf_addf(events, "}:W"); + RETURN_IF_NON_ZERO(ret); + pr_debug("events-buf: %s\n", events->buf); + list_add_tail(&new_group_str->nd, group_strs); + } + } + return ret; +#undef RETURN_IF_NON_ZERO +} + /** * create_grouping - Create a list of groups and place all the events of * event_info_list into these groups. @@ -1989,8 +2079,8 @@ static int assign_event_grouping(struct metricgroup__event_info *e, */ static int create_grouping(struct list_head *pmu_info_list, struct list_head *event_info_list, - struct list_head *groupings __maybe_unused, - const char *modifier __maybe_unused) + struct list_head *groupings, + const char *modifier) { int ret = 0; struct metricgroup__event_info *e; @@ -2006,6 +2096,7 @@ static int create_grouping(struct list_head *pmu_info_list, if (ret) goto out; } + ret = hw_aware_metricgroup__build_event_string(groupings, modifier, &groups); out: metricgroup__free_group_list(&groups); return ret; @@ -2035,8 +2126,6 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *id = cur->pkey; - pr_debug("found event %s\n", id); - ret = get_metricgroup_events(id, etable, &event_info_list); if (ret) goto err_out; -- 2.42.0