Skip to content

Commit d0761e3

Browse files
committed
perf tools: Uninline scnprintf() and vscnprint()
They were in tools/include/linux/kernel.h, requiring that it in turn included stdio.h, which is way too heavy. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-855h8olnkot9v0dajuee1lo3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 5496bc0 commit d0761e3

9 files changed

Lines changed: 39 additions & 25 deletions

File tree

‎tools/include/linux/kernel.h‎

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#define __TOOLS_LINUX_KERNEL_H
33

44
#include <stdarg.h>
5-
#include <stdio.h>
6-
#include <stdlib.h>
5+
#include <stddef.h>
76
#include <assert.h>
87

98
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
@@ -70,29 +69,8 @@
7069
#define cpu_to_le64(x) (x)
7170
#define cpu_to_le32(x) (x)
7271

73-
static inline int
74-
vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
75-
{
76-
int i;
77-
ssize_t ssize = size;
78-
79-
i = vsnprintf(buf, size, fmt, args);
80-
81-
return (i >= ssize) ? (ssize - 1) : i;
82-
}
83-
84-
static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
85-
{
86-
va_list args;
87-
ssize_t ssize = size;
88-
int i;
89-
90-
va_start(args, fmt);
91-
i = vsnprintf(buf, size, fmt, args);
92-
va_end(args);
93-
94-
return (i >= ssize) ? (ssize - 1) : i;
95-
}
72+
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
73+
int scnprintf(char * buf, size_t size, const char * fmt, ...);
9674

9775
/*
9876
* This looks more complex than it should be. But we need to

‎tools/lib/vsprintf.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <sys/types.h>
2+
#include <linux/kernel.h>
3+
#include <stdio.h>
4+
5+
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
6+
{
7+
int i = vsnprintf(buf, size, fmt, args);
8+
ssize_t ssize = size;
9+
10+
return (i >= ssize) ? (ssize - 1) : i;
11+
}
12+
13+
int scnprintf(char * buf, size_t size, const char * fmt, ...)
14+
{
15+
ssize_t ssize = size;
16+
va_list args;
17+
int i;
18+
19+
va_start(args, fmt);
20+
i = vsnprintf(buf, size, fmt, args);
21+
va_end(args);
22+
23+
return (i >= ssize) ? (ssize - 1) : i;
24+
}

‎tools/objtool/builtin-check.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include <string.h>
29+
#include <stdlib.h>
2930
#include <subcmd/parse-options.h>
3031

3132
#include "builtin.h"

‎tools/perf/MANIFEST‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tools/lib/symbol/kallsyms.h
3030
tools/lib/find_bit.c
3131
tools/lib/bitmap.c
3232
tools/lib/str_error_r.c
33+
tools/lib/vsprintf.c
3334
tools/include/asm/atomic.h
3435
tools/include/asm/barrier.h
3536
tools/include/asm/bug.h

‎tools/perf/util/Build‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ libperf-y += parse-regs-options.o
8585
libperf-y += term.o
8686
libperf-y += help-unknown-cmd.o
8787
libperf-y += mem-events.o
88+
libperf-y += vsprintf.o
8889

8990
libperf-$(CONFIG_LIBBPF) += bpf-loader.o
9091
libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
@@ -181,3 +182,7 @@ $(OUTPUT)util/str_error_r.o: ../lib/str_error_r.c FORCE
181182
$(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
182183
$(call rule_mkdir)
183184
$(call if_changed_dep,cc_o_c)
185+
186+
$(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE
187+
$(call rule_mkdir)
188+
$(call if_changed_dep,cc_o_c)

‎tools/perf/util/color.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <linux/kernel.h>
22
#include "cache.h"
33
#include "config.h"
4+
#include <stdlib.h>
5+
#include <stdio.h>
46
#include "color.h"
57
#include <math.h>
68
#include <unistd.h>

‎tools/perf/util/dso.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/atomic.h>
55
#include <linux/types.h>
66
#include <linux/rbtree.h>
7+
#include <sys/types.h>
78
#include <stdbool.h>
89
#include <pthread.h>
910
#include <linux/types.h>

‎tools/perf/util/help-unknown-cmd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "config.h"
3+
#include <stdio.h>
34
#include <subcmd/help.h>
45
#include "../builtin.h"
56
#include "levenshtein.h"

‎tools/perf/util/python-ext-sources‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ util/cpumap.c
1414
../lib/find_bit.c
1515
../lib/hweight.c
1616
../lib/str_error_r.c
17+
../lib/vsprintf.c
1718
util/thread_map.c
1819
util/util.c
1920
util/xyarray.c

0 commit comments

Comments
 (0)