From patchwork Tue Jan 10 22:19:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 41677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2996875wrt; Tue, 10 Jan 2023 14:22:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXuYkcvfHyyb1FDmfu9buhnD5ZW0Avf40r2ygBPTX1nXUkvalvc/oGC6FmFITjVN76QTgpFV X-Received: by 2002:a17:907:7676:b0:7c1:7183:2d32 with SMTP id kk22-20020a170907767600b007c171832d32mr62303155ejc.56.1673389346749; Tue, 10 Jan 2023 14:22:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673389346; cv=none; d=google.com; s=arc-20160816; b=xw65H+A7INMRvS53IKzfH0zO8EGaes+p34YHiNoQLfG9MFLSaAgNCqOFUsSIX+HHMX 4uKOlp3icBiK3Zh1SouPC8JifqdxE3FbsWzafDH8GPLf8O+dLseQVcCKk4NjuskQcz9+ xFeBX5Sr2S5478UP+jXBU8UfuMdady4/YLlRglgqryq99cooJ0WFSBCtvpZmL1LWn0Hd WEH0gGuKVo6wCTwbNErvrIw1hZvQkf0SYInCySlQdr8Ok68x+cVyKWPKJEBCzYoRqr2/ W37sgiUsNb7S5J+9D/TUTiIZiuM+RBYQbRmTbfPYHGYMkAmdp7bmv6uLnNQl3h8hgMp/ EwFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=wXlKtQGeWTp7vou3jM8pEXClHMn0X8ibzVPnBb6ixuM=; b=HkUI8esWR+zjVtE3cXKLcGofUC8ienkKbNH6CnY0xKxDZQKT/nKiyyDsWAxsIvj5WF WgSfJSBmLe+GgvEGWn8jbKLLEt3VYFXQc43fXu/jp1rBvWMjtyVqgxxlDvbFza3yw5wL faF3oau+ilUajruh1STmtgJMf6awexxaefrM5Nves3hDjj9rlmw2dUOmDjPmXW19BN6B zoVOq759vypEG8t9Hv2wZuvJRbpwwiC2qFaNhMdLhT6CD2QrU3snmCs4kNXG0KG7653v psnN7Ri1uMiFNEnpQzg+EXT1WVj10292YsElukOr8NJq1S8uR6viMnVHhMMpDav0fKNF 3Z6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hjTIUiM3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v17-20020a056402185100b00469fd4323a4si11712462edy.246.2023.01.10.14.22.03; Tue, 10 Jan 2023 14:22:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hjTIUiM3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234449AbjAJWUw (ORCPT + 99 others); Tue, 10 Jan 2023 17:20:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234841AbjAJWUi (ORCPT ); Tue, 10 Jan 2023 17:20:38 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAECA633B7 for ; Tue, 10 Jan 2023 14:20:36 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4ce566db73eso73147557b3.11 for ; Tue, 10 Jan 2023 14:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wXlKtQGeWTp7vou3jM8pEXClHMn0X8ibzVPnBb6ixuM=; b=hjTIUiM3nzSYOud7leDVomzWDX3omcRH7XxTp1cWtIJhcikMVufN+ADzaTNdzeYkj3 HC8m5Q1q0N4tWXzZdz62Ir1LPgLAO+IhU/NZoaVR4GFeUM6+9gdxTBxUG6xXuEsppqxe 4vnw6QbBUijTFsZg9n4sHratLsuRyEm4BjeV3UDRMt9++3Yh3Cq54hMnLSk3/4AROLWi fsELZGJJQe97BgTCi3vctbH4g6noIJFn734K3HKJyuYmN0ckIZ3X1C+cnuvxMG2MVHUU +jYZGmTxMrdoDqn9BRXhS5pXUVJNJf1poMGdTSp9IsSQGq4MmAoB+vrv5a5KcpnoI+PE Ogzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wXlKtQGeWTp7vou3jM8pEXClHMn0X8ibzVPnBb6ixuM=; b=EYwnKxCaHbB21INzWpY8bwnjXUB/bGw2+gt8GFZwbAyFasxPjK7wA3GtNdxeo5OH5N MNIoqvhsFn+e8KXh8fjd2cE+AEnSAtDGFeMFPh7/TYCH/du4wiei6ete+XiXvIIyeYKk c1mE/XcPTlaSXrWabSaomlcwNlnI6S4ALUG145deNPRNL/yJx5kmhrjSx+rER/YzOcNA jxyPVHQ70dI6TjXGHcnM07k3URvbggEA2rSKLDYbgaVPtoZb6a1VK3d7a+9dpAsA/D83 rEiMSpFs+elFHj4eZJ0k3RHfSR26w01Or9wrFWulOACkC8elaQwjSmWdelWLqwD3fEn8 cTLg== X-Gm-Message-State: AFqh2kozPJygsXV2/saziJpg4HX4MUC/1Kho87J9lrnVEThv2bI9atdk tPI6Xy+FXbkMPlERuElrUkiVYU+LOpsH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:cebf:c37e:8184:56]) (user=irogers job=sendgmr) by 2002:a0d:e60b:0:b0:3ec:2e89:409c with SMTP id p11-20020a0de60b000000b003ec2e89409cmr1362309ywe.20.1673389236102; Tue, 10 Jan 2023 14:20:36 -0800 (PST) Date: Tue, 10 Jan 2023 14:19:58 -0800 In-Reply-To: <20230110222003.1591436-1-irogers@google.com> Message-Id: <20230110222003.1591436-3-irogers@google.com> Mime-Version: 1.0 References: <20230110222003.1591436-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v1 2/7] tools lib: Move strbuf to libapi From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Nathan Chancellor , Nick Desaulniers , Tom Rix , Nicolas Schier , Masahiro Yamada , Athira Rajeev , Christy Lee , Andrii Nakryiko , Ravi Bangoria , Leo Yan , Yang Jihong , Qi Liu , James Clark , Adrian Hunter , "Masami Hiramatsu (Google)" , Kan Liang , Sean Christopherson , Zhengjun Xing , Rob Herring , Xin Gao , Zechuan Chen , Jason Wang , Christophe JAILLET , Stephane Eranian , German Gomez , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754675907595853403?= X-GMAIL-MSGID: =?utf-8?q?1754675907595853403?= Move strbuf, appendable C strings, to libapi so that other libraries may use it. Signed-off-by: Ian Rogers --- tools/lib/api/Build | 1 + tools/lib/api/Makefile | 2 +- tools/{perf/util => lib/api}/strbuf.c | 5 +++-- tools/{perf/util => lib/api}/strbuf.h | 0 tools/perf/bench/evlist-open-close.c | 2 +- tools/perf/builtin-help.c | 2 +- tools/perf/builtin-list.c | 2 +- tools/perf/util/Build | 1 - tools/perf/util/cache.h | 2 +- tools/perf/util/dwarf-aux.c | 2 +- tools/perf/util/env.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/pfm.c | 2 +- tools/perf/util/pmu.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-file.c | 2 +- tools/perf/util/probe-finder.c | 2 +- tools/perf/util/sort.c | 2 +- 19 files changed, 19 insertions(+), 18 deletions(-) rename tools/{perf/util => lib/api}/strbuf.c (97%) rename tools/{perf/util => lib/api}/strbuf.h (100%) diff --git a/tools/lib/api/Build b/tools/lib/api/Build index 6e2373db5598..2eab5abbad50 100644 --- a/tools/lib/api/Build +++ b/tools/lib/api/Build @@ -3,6 +3,7 @@ libapi-y += fs/ libapi-y += cpu.o libapi-y += debug.o libapi-y += str_error_r.o +libapi-y += strbuf.o $(OUTPUT)str_error_r.o: ../str_error_r.c FORCE $(call rule_mkdir) diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile index 044860ac1ed1..dc2d810dfbad 100644 --- a/tools/lib/api/Makefile +++ b/tools/lib/api/Makefile @@ -99,7 +99,7 @@ install_lib: $(LIBFILE) $(call do_install_mkdir,$(libdir_SQ)); \ cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ) -HDRS := cpu.h debug.h io.h +HDRS := cpu.h debug.h io.h strbuf.h FD_HDRS := fd/array.h FS_HDRS := fs/fs.h fs/tracing_path.h INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/api diff --git a/tools/perf/util/strbuf.c b/tools/lib/api/strbuf.c similarity index 97% rename from tools/perf/util/strbuf.c rename to tools/lib/api/strbuf.c index a64a37628f12..4639b2d02e62 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/lib/api/strbuf.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 -#include "cache.h" -#include "debug.h" +#include "debug-internal.h" #include "strbuf.h" #include #include @@ -43,6 +42,7 @@ char *strbuf_detach(struct strbuf *sb, size_t *sz) return res; } +#define alloc_nr(x) (((x)+16)*3/2) int strbuf_grow(struct strbuf *sb, size_t extra) { char *buf; @@ -69,6 +69,7 @@ int strbuf_grow(struct strbuf *sb, size_t extra) sb->alloc = nr; return 0; } +#undef alloc_nr int strbuf_addch(struct strbuf *sb, int c) { diff --git a/tools/perf/util/strbuf.h b/tools/lib/api/strbuf.h similarity index 100% rename from tools/perf/util/strbuf.h rename to tools/lib/api/strbuf.h diff --git a/tools/perf/bench/evlist-open-close.c b/tools/perf/bench/evlist-open-close.c index 5a27691469ed..d8a8fcadb9ca 100644 --- a/tools/perf/bench/evlist-open-close.c +++ b/tools/perf/bench/evlist-open-close.c @@ -8,7 +8,7 @@ #include "../util/stat.h" #include "../util/evlist.h" #include "../util/evsel.h" -#include "../util/strbuf.h" +#include #include "../util/record.h" #include "../util/parse-events.h" #include "internal/threadmap.h" diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 3976aebe3677..8874e1e0335b 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c @@ -6,7 +6,7 @@ */ #include "util/cache.h" #include "util/config.h" -#include "util/strbuf.h" +#include #include "builtin.h" #include #include "common-cmds.h" diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 137d73edb541..ca52227f311c 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -17,7 +17,7 @@ #include "util/metricgroup.h" #include "util/string2.h" #include "util/strlist.h" -#include "util/strbuf.h" +#include #include #include #include diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 79b9498886a2..5c68ab8c69f8 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -37,7 +37,6 @@ perf-y += libstring.o perf-y += bitmap.o perf-y += hweight.o perf-y += smt.o -perf-y += strbuf.o perf-y += string.o perf-y += strlist.o perf-y += strfilter.o diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 9f2e36ef5072..19e60decb24c 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h @@ -2,7 +2,7 @@ #ifndef __PERF_CACHE_H #define __PERF_CACHE_H -#include "strbuf.h" +#include #include #include "../ui/ui.h" diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index b07414409771..673ddfeb938d 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -9,7 +9,7 @@ #include #include "debug.h" #include "dwarf-aux.h" -#include "strbuf.h" +#include #include "string2.h" /** diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 5b8cf6a421a4..3dc1c51a8335 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -10,7 +10,7 @@ #include #include #include -#include "strbuf.h" +#include struct perf_env perf_env; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 404d816ca124..35067c22a47f 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -38,7 +38,7 @@ #include "cpumap.h" #include "pmu.h" #include "vdso.h" -#include "strbuf.h" +#include #include "build-id.h" #include "data.h" #include diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index b9c273ed080a..d1d21605715a 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -9,7 +9,7 @@ #include "debug.h" #include "evlist.h" #include "evsel.h" -#include "strbuf.h" +#include #include "pmu.h" #include "pmu-hybrid.h" #include "print-events.h" diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index ac3227ba769c..c82e7bc7c5ea 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -12,7 +12,7 @@ #include "util/parse-events.h" #include "util/pmu.h" #include "util/pfm.h" -#include "util/strbuf.h" +#include #include #include diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 2bdeb89352e7..4648ccf0b50a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -27,7 +27,7 @@ #include "print-events.h" #include "header.h" #include "string2.h" -#include "strbuf.h" +#include #include "fncache.h" #include "pmu-hybrid.h" diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 0c24bc7afbca..e609970e2113 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -38,7 +38,7 @@ #include "probe-file.h" #include "session.h" #include "string2.h" -#include "strbuf.h" +#include #include #include diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index 3d50de3217d5..c1f1ef3f48d4 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -20,7 +20,7 @@ #include "dso.h" #include "color.h" #include "symbol.h" -#include "strbuf.h" +#include #include #include #include "probe-event.h" diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 54b49ce85c9f..4368a9dffc35 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -24,7 +24,7 @@ #include "dso.h" #include "debug.h" #include "intlist.h" -#include "strbuf.h" +#include #include "strlist.h" #include "symbol.h" #include "probe-finder.h" diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index e188f74698dd..32f00a340c0d 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -21,7 +21,7 @@ #include "evlist.h" #include "srcline.h" #include "strlist.h" -#include "strbuf.h" +#include #include "mem-events.h" #include "annotate.h" #include "event.h"