[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230110222003.1591436-3-irogers@google.com>
Date: Tue, 10 Jan 2023 14:19:58 -0800
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Tom Rix <trix@...hat.com>, Nicolas Schier <nicolas@...sle.eu>,
Masahiro Yamada <masahiroy@...nel.org>,
Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
Christy Lee <christylee@...com>,
Andrii Nakryiko <andrii@...nel.org>,
Ravi Bangoria <ravi.bangoria@....com>,
Leo Yan <leo.yan@...aro.org>,
Yang Jihong <yangjihong1@...wei.com>,
Qi Liu <liuqi115@...wei.com>,
James Clark <james.clark@....com>,
Adrian Hunter <adrian.hunter@...el.com>,
"Masami Hiramatsu (Google)" <mhiramat@...nel.org>,
Kan Liang <kan.liang@...ux.intel.com>,
Sean Christopherson <seanjc@...gle.com>,
Zhengjun Xing <zhengjun.xing@...ux.intel.com>,
Rob Herring <robh@...nel.org>, Xin Gao <gaoxin@...rlc.com>,
Zechuan Chen <chenzechuan1@...wei.com>,
Jason Wang <wangborong@...rlc.com>,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
Stephane Eranian <eranian@...gle.com>,
German Gomez <german.gomez@....com>,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
bpf@...r.kernel.org, llvm@...ts.linux.dev
Cc: Ian Rogers <irogers@...gle.com>
Subject: [PATCH v1 2/7] tools lib: Move strbuf to libapi
Move strbuf, appendable C strings, to libapi so that other libraries
may use it.
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
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 <linux/kernel.h>
#include <linux/string.h>
@@ -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 <api/strbuf.h>
#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 <api/strbuf.h>
#include "builtin.h"
#include <subcmd/exec-cmd.h>
#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 <api/strbuf.h>
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
#include <linux/zalloc.h>
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 <api/strbuf.h>
#include <subcmd/pager.h>
#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 <stdlib.h>
#include "debug.h"
#include "dwarf-aux.h"
-#include "strbuf.h"
+#include <api/strbuf.h>
#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 <sys/utsname.h>
#include <stdlib.h>
#include <string.h>
-#include "strbuf.h"
+#include <api/strbuf.h>
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 <api/strbuf.h>
#include "build-id.h"
#include "data.h"
#include <api/fs/fs.h>
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 <api/strbuf.h>
#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 <api/strbuf.h>
#include <string.h>
#include <linux/kernel.h>
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 <api/strbuf.h>
#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 <api/strbuf.h>
#include <subcmd/pager.h>
#include <linux/ctype.h>
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 <api/strbuf.h>
#include <api/fs/tracing_path.h>
#include <api/fs/fs.h>
#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 <api/strbuf.h>
#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 <api/strbuf.h>
#include "mem-events.h"
#include "annotate.h"
#include "event.h"
--
2.39.0.314.g84b9a713c41-goog
Powered by blists - more mailing lists