Skip to content

Commit

Permalink
perf tools: Uninline scnprintf() and vscnprint()
Browse files Browse the repository at this point in the history
They were in tools/include/linux/kernel.h, requiring that it in turn
included stdio.h, which is way too heavy.

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Jul 12, 2016
1 parent 5496bc0 commit d0761e3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 25 deletions.
28 changes: 3 additions & 25 deletions tools/include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define __TOOLS_LINUX_KERNEL_H

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>

#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
Expand Down Expand Up @@ -70,29 +69,8 @@
#define cpu_to_le64(x) (x)
#define cpu_to_le32(x) (x)

static inline int
vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
int i;
ssize_t ssize = size;

i = vsnprintf(buf, size, fmt, args);

return (i >= ssize) ? (ssize - 1) : i;
}

static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
{
va_list args;
ssize_t ssize = size;
int i;

va_start(args, fmt);
i = vsnprintf(buf, size, fmt, args);
va_end(args);

return (i >= ssize) ? (ssize - 1) : i;
}
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
int scnprintf(char * buf, size_t size, const char * fmt, ...);

/*
* This looks more complex than it should be. But we need to
Expand Down
24 changes: 24 additions & 0 deletions tools/lib/vsprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <sys/types.h>
#include <linux/kernel.h>
#include <stdio.h>

int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
int i = vsnprintf(buf, size, fmt, args);
ssize_t ssize = size;

return (i >= ssize) ? (ssize - 1) : i;
}

int scnprintf(char * buf, size_t size, const char * fmt, ...)
{
ssize_t ssize = size;
va_list args;
int i;

va_start(args, fmt);
i = vsnprintf(buf, size, fmt, args);
va_end(args);

return (i >= ssize) ? (ssize - 1) : i;
}
1 change: 1 addition & 0 deletions tools/objtool/builtin-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#include <string.h>
#include <stdlib.h>
#include <subcmd/parse-options.h>

#include "builtin.h"
Expand Down
1 change: 1 addition & 0 deletions tools/perf/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tools/lib/symbol/kallsyms.h
tools/lib/find_bit.c
tools/lib/bitmap.c
tools/lib/str_error_r.c
tools/lib/vsprintf.c
tools/include/asm/atomic.h
tools/include/asm/barrier.h
tools/include/asm/bug.h
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/util/Build
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ libperf-y += parse-regs-options.o
libperf-y += term.o
libperf-y += help-unknown-cmd.o
libperf-y += mem-events.o
libperf-y += vsprintf.o

libperf-$(CONFIG_LIBBPF) += bpf-loader.o
libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
Expand Down Expand Up @@ -181,3 +182,7 @@ $(OUTPUT)util/str_error_r.o: ../lib/str_error_r.c FORCE
$(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)

$(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
2 changes: 2 additions & 0 deletions tools/perf/util/color.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <linux/kernel.h>
#include "cache.h"
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include "color.h"
#include <math.h>
#include <unistd.h>
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/dso.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/atomic.h>
#include <linux/types.h>
#include <linux/rbtree.h>
#include <sys/types.h>
#include <stdbool.h>
#include <pthread.h>
#include <linux/types.h>
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/help-unknown-cmd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cache.h"
#include "config.h"
#include <stdio.h>
#include <subcmd/help.h>
#include "../builtin.h"
#include "levenshtein.h"
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/python-ext-sources
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ util/cpumap.c
../lib/find_bit.c
../lib/hweight.c
../lib/str_error_r.c
../lib/vsprintf.c
util/thread_map.c
util/util.c
util/xyarray.c
Expand Down

0 comments on commit d0761e3

Please sign in to comment.