Skip to content

Commit fc67297

Browse files
namhyungacmel
authored andcommitted
perf tools: Separate out GTK codes to libperf-gtk.so
Separate out GTK codes to a shared object called libperf-gtk.so. This time only GTK codes are built with -fPIC and libperf remains as is. Now run GTK hist and annotation browser using libdl. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Reviewed-by: Pekka Enberg <penberg@kernel.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Pekka Enberg <penberg@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1379053663-13706-1-git-send-email-namhyung@kernel.org [ Fix it up wrt Ingo's tools/perf build speedups ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent fc2be69 commit fc67297

11 files changed

Lines changed: 165 additions & 74 deletions

File tree

‎tools/perf/Makefile.perf‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
114114
BUILTIN_OBJS =
115115
LIB_H =
116116
LIB_OBJS =
117+
GTK_OBJS =
117118
PYRF_OBJS =
118119
SCRIPT_SH =
119120

@@ -490,13 +491,19 @@ ifndef NO_SLANG
490491
endif
491492

492493
ifndef NO_GTK2
493-
LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
494-
LIB_OBJS += $(OUTPUT)ui/gtk/hists.o
495-
LIB_OBJS += $(OUTPUT)ui/gtk/setup.o
496-
LIB_OBJS += $(OUTPUT)ui/gtk/util.o
497-
LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
498-
LIB_OBJS += $(OUTPUT)ui/gtk/progress.o
499-
LIB_OBJS += $(OUTPUT)ui/gtk/annotate.o
494+
ALL_PROGRAMS += $(OUTPUT)libperf-gtk.so
495+
496+
GTK_OBJS += $(OUTPUT)ui/gtk/browser.o
497+
GTK_OBJS += $(OUTPUT)ui/gtk/hists.o
498+
GTK_OBJS += $(OUTPUT)ui/gtk/setup.o
499+
GTK_OBJS += $(OUTPUT)ui/gtk/util.o
500+
GTK_OBJS += $(OUTPUT)ui/gtk/helpline.o
501+
GTK_OBJS += $(OUTPUT)ui/gtk/progress.o
502+
GTK_OBJS += $(OUTPUT)ui/gtk/annotate.o
503+
504+
install-gtk: $(OUTPUT)libperf-gtk.so
505+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(libdir_SQ)'
506+
$(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)'
500507
endif
501508

502509
ifndef NO_LIBPERL
@@ -550,6 +557,12 @@ $(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
550557
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(OUTPUT)perf.o \
551558
$(BUILTIN_OBJS) $(LIBS) -o $@
552559

560+
$(GTK_OBJS): $(OUTPUT)%.o: %.c $(LIB_H)
561+
$(QUIET_CC)$(CC) -o $@ -c -fPIC $(CFLAGS) $(GTK_CFLAGS) $<
562+
563+
$(OUTPUT)libperf-gtk.so: $(GTK_OBJS) $(PERFLIBS)
564+
$(QUIET_LINK)$(CC) -o $@ -shared $(ALL_LDFLAGS) $(filter %.o,$^) $(GTK_LIBS)
565+
553566
$(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
554567
$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
555568
'-DPERF_HTML_PATH="$(htmldir_SQ)"' \
@@ -632,6 +645,9 @@ $(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS
632645
$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
633646
$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
634647

648+
$(OUTPUT)ui/setup.o: ui/setup.c $(OUTPUT)PERF-CFLAGS
649+
$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DLIBDIR='"$(libdir_SQ)"' $<
650+
635651
$(OUTPUT)ui/browser.o: ui/browser.c $(OUTPUT)PERF-CFLAGS
636652
$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $<
637653

@@ -673,7 +689,8 @@ $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
673689

674690
# we compile into subdirectories. if the target directory is not the source directory, they might not exists. So
675691
# we depend the various files onto their directories.
676-
DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
692+
DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(GTK_OBJS)
693+
DIRECTORY_DEPS += $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
677694
$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS)))
678695
# In the second step, we make a rule to actually create these directories
679696
$(sort $(dir $(DIRECTORY_DEPS))):
@@ -786,7 +803,9 @@ check: $(OUTPUT)common-cmds.h
786803

787804
### Installation rules
788805

789-
install-bin: all
806+
install-gtk:
807+
808+
install-bin: all install-gtk
790809
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
791810
$(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'
792811
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
@@ -831,7 +850,8 @@ config-clean:
831850
@$(MAKE) -C config/feature-checks clean
832851

833852
clean: $(LIBTRACEEVENT)-clean $(LIBLK)-clean config-clean
834-
$(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS)
853+
$(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(GTK_OBJS)
854+
$(RM) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS)
835855
$(RM) $(ALL_PROGRAMS) perf
836856
$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope*
837857
$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
@@ -850,7 +870,7 @@ else
850870
GIT-HEAD-PHONY =
851871
endif
852872

853-
.PHONY: all install clean config-clean strip
873+
.PHONY: all install clean config-clean strip install-gtk
854874
.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
855875
.PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope .FORCE-PERF-CFLAGS
856876

‎tools/perf/builtin-annotate.c‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "util/tool.h"
3131
#include "arch/common.h"
3232

33+
#include <dlfcn.h>
3334
#include <linux/bitmap.h>
3435

3536
struct perf_annotate {
@@ -142,8 +143,18 @@ static void hists__find_annotations(struct hists *self,
142143

143144
if (use_browser == 2) {
144145
int ret;
146+
int (*annotate)(struct hist_entry *he,
147+
struct perf_evsel *evsel,
148+
struct hist_browser_timer *hbt);
149+
150+
annotate = dlsym(perf_gtk_handle,
151+
"hist_entry__gtk_annotate");
152+
if (annotate == NULL) {
153+
ui__error("GTK browser not found!\n");
154+
return;
155+
}
145156

146-
ret = hist_entry__gtk_annotate(he, evsel, NULL);
157+
ret = annotate(he, evsel, NULL);
147158
if (!ret || !ann->skip_missing)
148159
return;
149160

@@ -247,8 +258,17 @@ static int __cmd_annotate(struct perf_annotate *ann)
247258
goto out_delete;
248259
}
249260

250-
if (use_browser == 2)
251-
perf_gtk__show_annotations();
261+
if (use_browser == 2) {
262+
void (*show_annotations)(void);
263+
264+
show_annotations = dlsym(perf_gtk_handle,
265+
"perf_gtk__show_annotations");
266+
if (show_annotations == NULL) {
267+
ui__error("GTK browser not found!\n");
268+
goto out_delete;
269+
}
270+
show_annotations();
271+
}
252272

253273
out_delete:
254274
/*

‎tools/perf/builtin-report.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "util/hist.h"
3636
#include "arch/common.h"
3737

38+
#include <dlfcn.h>
3839
#include <linux/bitmap.h>
3940

4041
struct perf_report {
@@ -591,8 +592,19 @@ static int __cmd_report(struct perf_report *rep)
591592
ret = 0;
592593

593594
} else if (use_browser == 2) {
594-
perf_evlist__gtk_browse_hists(session->evlist, help,
595-
NULL, rep->min_percent);
595+
int (*hist_browser)(struct perf_evlist *,
596+
const char *,
597+
struct hist_browser_timer *,
598+
float min_pcnt);
599+
600+
hist_browser = dlsym(perf_gtk_handle,
601+
"perf_evlist__gtk_browse_hists");
602+
if (hist_browser == NULL) {
603+
ui__error("GTK browser not found!\n");
604+
return ret;
605+
}
606+
hist_browser(session->evlist, help, NULL,
607+
rep->min_percent);
596608
}
597609
} else
598610
perf_evlist__tty_browse_hists(session->evlist, rep, help);

‎tools/perf/config/Makefile‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,11 @@ ifndef NO_GTK2
377377
NO_GTK2 := 1
378378
else
379379
ifeq ($(feature-gtk2-infobar), 1)
380-
CFLAGS += -DHAVE_GTK_INFO_BAR_SUPPORT
380+
GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
381381
endif
382382
CFLAGS += -DHAVE_GTK2_SUPPORT
383-
CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
384-
EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
383+
GTK_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
384+
GTK_LIBS := $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
385385
endif
386386
endif
387387

@@ -554,7 +554,12 @@ else
554554
sysconfdir = $(prefix)/etc
555555
ETC_PERFCONFIG = etc/perfconfig
556556
endif
557+
ifeq ($(IS_X86_64),1)
558+
lib = lib64
559+
else
557560
lib = lib
561+
endif
562+
libdir = $(prefix)/$(lib)
558563

559564
# Shell quote (do not use $(call) to accommodate ancient setups);
560565
ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
@@ -567,6 +572,7 @@ template_dir_SQ = $(subst ','\'',$(template_dir))
567572
htmldir_SQ = $(subst ','\'',$(htmldir))
568573
prefix_SQ = $(subst ','\'',$(prefix))
569574
sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
575+
libdir_SQ = $(subst ','\'',$(libdir))
570576

571577
ifneq ($(filter /%,$(firstword $(perfexecdir))),)
572578
perfexec_instdir = $(perfexecdir)

‎tools/perf/ui/gtk/annotate.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,
154154
return 0;
155155
}
156156

157-
int symbol__gtk_annotate(struct symbol *sym, struct map *map,
158-
struct perf_evsel *evsel,
159-
struct hist_browser_timer *hbt)
157+
static int symbol__gtk_annotate(struct symbol *sym, struct map *map,
158+
struct perf_evsel *evsel,
159+
struct hist_browser_timer *hbt)
160160
{
161161
GtkWidget *window;
162162
GtkWidget *notebook;
@@ -226,6 +226,13 @@ int symbol__gtk_annotate(struct symbol *sym, struct map *map,
226226
return 0;
227227
}
228228

229+
int hist_entry__gtk_annotate(struct hist_entry *he,
230+
struct perf_evsel *evsel,
231+
struct hist_browser_timer *hbt)
232+
{
233+
return symbol__gtk_annotate(he->ms.sym, he->ms.map, evsel, hbt);
234+
}
235+
229236
void perf_gtk__show_annotations(void)
230237
{
231238
GtkWidget *window;

‎tools/perf/ui/gtk/gtk.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ struct perf_gtk_context {
2020
guint statbar_ctx_id;
2121
};
2222

23+
int perf_gtk__init(void);
24+
void perf_gtk__exit(bool wait_for_ok);
25+
2326
extern struct perf_gtk_context *pgctx;
2427

2528
static inline bool perf_gtk__is_active_context(struct perf_gtk_context *ctx)
@@ -48,4 +51,17 @@ static inline GtkWidget *perf_gtk__setup_info_bar(void)
4851
}
4952
#endif
5053

54+
struct perf_evsel;
55+
struct perf_evlist;
56+
struct hist_entry;
57+
struct hist_browser_timer;
58+
59+
int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help,
60+
struct hist_browser_timer *hbt,
61+
float min_pcnt);
62+
int hist_entry__gtk_annotate(struct hist_entry *he,
63+
struct perf_evsel *evsel,
64+
struct hist_browser_timer *hbt);
65+
void perf_gtk__show_annotations(void);
66+
5167
#endif /* _PERF_GTK_H_ */

‎tools/perf/ui/setup.c‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,64 @@
11
#include <pthread.h>
2+
#include <dlfcn.h>
23

34
#include "../util/cache.h"
45
#include "../util/debug.h"
56
#include "../util/hist.h"
67

78
pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
9+
void *perf_gtk_handle;
10+
11+
#ifdef HAVE_GTK2_SUPPORT
12+
static int setup_gtk_browser(void)
13+
{
14+
int (*perf_ui_init)(void);
15+
16+
if (perf_gtk_handle)
17+
return 0;
18+
19+
perf_gtk_handle = dlopen(PERF_GTK_DSO, RTLD_LAZY);
20+
if (perf_gtk_handle == NULL) {
21+
char buf[PATH_MAX];
22+
scnprintf(buf, sizeof(buf), "%s/%s", LIBDIR, PERF_GTK_DSO);
23+
perf_gtk_handle = dlopen(buf, RTLD_LAZY);
24+
}
25+
if (perf_gtk_handle == NULL)
26+
return -1;
27+
28+
perf_ui_init = dlsym(perf_gtk_handle, "perf_gtk__init");
29+
if (perf_ui_init == NULL)
30+
goto out_close;
31+
32+
if (perf_ui_init() == 0)
33+
return 0;
34+
35+
out_close:
36+
dlclose(perf_gtk_handle);
37+
return -1;
38+
}
39+
40+
static void exit_gtk_browser(bool wait_for_ok)
41+
{
42+
void (*perf_ui_exit)(bool);
43+
44+
if (perf_gtk_handle == NULL)
45+
return;
46+
47+
perf_ui_exit = dlsym(perf_gtk_handle, "perf_gtk__exit");
48+
if (perf_ui_exit == NULL)
49+
goto out_close;
50+
51+
perf_ui_exit(wait_for_ok);
52+
53+
out_close:
54+
dlclose(perf_gtk_handle);
55+
56+
perf_gtk_handle = NULL;
57+
}
58+
#else
59+
static inline int setup_gtk_browser(void) { return -1; }
60+
static inline void exit_gtk_browser(bool wait_for_ok __maybe_unused) {}
61+
#endif
862

963
void setup_browser(bool fallback_to_pager)
1064
{
@@ -17,8 +71,11 @@ void setup_browser(bool fallback_to_pager)
1771

1872
switch (use_browser) {
1973
case 2:
20-
if (perf_gtk__init() == 0)
74+
if (setup_gtk_browser() == 0)
2175
break;
76+
printf("GTK browser requested but could not find %s\n",
77+
PERF_GTK_DSO);
78+
sleep(1);
2279
/* fall through */
2380
case 1:
2481
use_browser = 1;
@@ -39,7 +96,7 @@ void exit_browser(bool wait_for_ok)
3996
{
4097
switch (use_browser) {
4198
case 2:
42-
perf_gtk__exit(wait_for_ok);
99+
exit_gtk_browser(wait_for_ok);
43100
break;
44101

45102
case 1:

‎tools/perf/ui/ui.h‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/compiler.h>
77

88
extern pthread_mutex_t ui__lock;
9+
extern void *perf_gtk_handle;
910

1011
extern int use_browser;
1112

@@ -23,17 +24,6 @@ static inline int ui__init(void)
2324
static inline void ui__exit(bool wait_for_ok __maybe_unused) {}
2425
#endif
2526

26-
#ifdef HAVE_GTK2_SUPPORT
27-
int perf_gtk__init(void);
28-
void perf_gtk__exit(bool wait_for_ok);
29-
#else
30-
static inline int perf_gtk__init(void)
31-
{
32-
return -1;
33-
}
34-
static inline void perf_gtk__exit(bool wait_for_ok __maybe_unused) {}
35-
#endif
36-
3727
void ui__refresh_dimensions(bool force);
3828

3929
#endif /* _PERF_UI_H_ */

0 commit comments

Comments
 (0)