Commit d4f2b4db authored by gejun's avatar gejun
parents 99041372 b9e6314c
...@@ -11,8 +11,9 @@ CXXFLAGS=$(CPPFLAGS) -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid- ...@@ -11,8 +11,9 @@ CXXFLAGS=$(CPPFLAGS) -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-
CFLAGS=$(CPPFLAGS) -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-unused-parameter -fno-omit-frame-pointer CFLAGS=$(CPPFLAGS) -g -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-unused-parameter -fno-omit-frame-pointer
HDRPATHS=-I./src $(addprefix -I, $(HDRS)) HDRPATHS=-I./src $(addprefix -I, $(HDRS))
LIBPATHS = $(addprefix -L, $(LIBS)) LIBPATHS = $(addprefix -L, $(LIBS))
COMMA = ,
SOPATHS = $(addprefix -Wl$(COMMA)-rpath=, $(LIBS))
SRCEXTS = .c .cc .cpp .proto SRCEXTS = .c .cc .cpp .proto
HDREXTS = .h .hpp
#required by butil/crc32.cc to boost performance for 10x #required by butil/crc32.cc to boost performance for 10x
ifeq ($(shell test $(GCC_VERSION) -ge 40400; echo $$?),0) ifeq ($(shell test $(GCC_VERSION) -ge 40400; echo $$?),0)
...@@ -195,7 +196,7 @@ JSON2PB_OBJS = $(addsuffix .o, $(basename $(JSON2PB_SOURCES))) ...@@ -195,7 +196,7 @@ JSON2PB_OBJS = $(addsuffix .o, $(basename $(JSON2PB_SOURCES)))
BRPC_DIRS = src/brpc src/brpc/details src/brpc/builtin src/brpc/policy BRPC_DIRS = src/brpc src/brpc/details src/brpc/builtin src/brpc/policy
BRPC_SOURCES = $(foreach d,$(BRPC_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS)))) BRPC_SOURCES = $(foreach d,$(BRPC_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
BRPC_PROTOS = $(filter %.proto,$(BRPC_SOURCES)) BRPC_PROTOS = $(filter %.proto,$(BRPC_SOURCES))
BRPC_CFAMILIES = $(filter-out %.proto,$(BRPC_SOURCES)) BRPC_CFAMILIES = $(filter-out %.proto %.pb.cc,$(BRPC_SOURCES))
BRPC_OBJS = $(BRPC_PROTOS:.proto=.pb.o) $(addsuffix .o, $(basename $(BRPC_CFAMILIES))) BRPC_OBJS = $(BRPC_PROTOS:.proto=.pb.o) $(addsuffix .o, $(basename $(BRPC_CFAMILIES)))
MCPACK2PB_SOURCES = \ MCPACK2PB_SOURCES = \
...@@ -209,7 +210,7 @@ OBJS=$(BUTIL_OBJS) $(BVAR_OBJS) $(BTHREAD_OBJS) $(JSON2PB_OBJS) $(MCPACK2PB_OBJS ...@@ -209,7 +210,7 @@ OBJS=$(BUTIL_OBJS) $(BVAR_OBJS) $(BTHREAD_OBJS) $(JSON2PB_OBJS) $(MCPACK2PB_OBJS
DEBUG_OBJS = $(OBJS:.o=.dbg.o) DEBUG_OBJS = $(OBJS:.o=.dbg.o)
.PHONY:all .PHONY:all
all: protoc-gen-mcpack libbrpc.a output/include output/lib output/bin all: protoc-gen-mcpack libbrpc.a libbrpc.so output/include output/lib output/bin
.PHONY:debug .PHONY:debug
debug: libbrpc.dbg.a debug: libbrpc.dbg.a
...@@ -217,7 +218,7 @@ debug: libbrpc.dbg.a ...@@ -217,7 +218,7 @@ debug: libbrpc.dbg.a
.PHONY:clean .PHONY:clean
clean:clean_debug clean:clean_debug
@echo "Cleaning" @echo "Cleaning"
@rm -rf mcpack2pb/generator.o protoc-gen-mcpack libbrpc.a $(OBJS) output/include output/lib output/bin @rm -rf src/mcpack2pb/generator.o protoc-gen-mcpack libbrpc.a libbrpc.so $(OBJS) output/include output/lib output/bin
.PHONY:clean_debug .PHONY:clean_debug
clean_debug: clean_debug:
...@@ -232,6 +233,10 @@ libbrpc.a:$(BRPC_PROTOS:.proto=.pb.h) $(OBJS) ...@@ -232,6 +233,10 @@ libbrpc.a:$(BRPC_PROTOS:.proto=.pb.h) $(OBJS)
@echo "Packing $@" @echo "Packing $@"
@ar crs $@ $(OBJS) @ar crs $@ $(OBJS)
libbrpc.so:$(BRPC_PROTOS:.proto=.pb.h) $(OBJS)
@echo "Linking $@"
$(CXX) -shared -o $@ $(HDRPATHS) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $(OBJS) -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
libbrpc.dbg.a:$(BRPC_PROTOS:.proto=.pb.h) $(DEBUG_OBJS) libbrpc.dbg.a:$(BRPC_PROTOS:.proto=.pb.h) $(DEBUG_OBJS)
@echo "Packing $@" @echo "Packing $@"
@ar crs $@ $(DEBUG_OBJS) @ar crs $@ $(DEBUG_OBJS)
...@@ -244,7 +249,7 @@ output/include: ...@@ -244,7 +249,7 @@ output/include:
@cp src/idl_options.proto src/idl_options.pb.h $@ @cp src/idl_options.proto src/idl_options.pb.h $@
.PHONY:output/lib .PHONY:output/lib
output/lib:libbrpc.a output/lib:libbrpc.a libbrpc.so
@echo "Copying to $@" @echo "Copying to $@"
@mkdir -p $@ @mkdir -p $@
@cp $^ $@ @cp $^ $@
......
...@@ -4,8 +4,13 @@ include $(BRPC_PATH)/config.mk ...@@ -4,8 +4,13 @@ include $(BRPC_PATH)/config.mk
# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default # 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8 # 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -Wno-unused-parameter -fPIC -fno-omit-frame-pointer CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -Wno-unused-parameter -fPIC -fno-omit-frame-pointer
HDRPATHS = -I$(BRPC_PATH)/output/include $(addprefix -I, $(HDRS)) HDRS+=$(BRPC_PATH)/output/include
LIBPATHS = -L$(BRPC_PATH)/output/lib $(addprefix -L, $(LIBS)) LIBS+=$(BRPC_PATH)/output/lib
HDRPATHS = $(addprefix -I, $(HDRS))
LIBPATHS = $(addprefix -L, $(LIBS))
COMMA=,
SOPATHS=$(addprefix -Wl$(COMMA)-rpath=, $(LIBS))
STATIC_LINKINGS += -lbrpc STATIC_LINKINGS += -lbrpc
CLIENT_SOURCES = client.cpp CLIENT_SOURCES = client.cpp
...@@ -27,11 +32,19 @@ clean: ...@@ -27,11 +32,19 @@ clean:
echo_client:$(PROTO_OBJS) $(CLIENT_OBJS) echo_client:$(PROTO_OBJS) $(CLIENT_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
echo_server:$(PROTO_OBJS) $(SERVER_OBJS) echo_server:$(PROTO_OBJS) $(SERVER_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
%.pb.cc %.pb.h:%.proto %.pb.cc %.pb.h:%.proto
@echo "Generating $@" @echo "Generating $@"
......
...@@ -8,8 +8,13 @@ CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -Wno-u ...@@ -8,8 +8,13 @@ CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -Wno-u
ifeq ($(NEED_GPERFTOOLS), 1) ifeq ($(NEED_GPERFTOOLS), 1)
CXXFLAGS+=-DBRPC_ENABLE_CPU_PROFILER -DBRPC_ENABLE_HEAP_PROFILER CXXFLAGS+=-DBRPC_ENABLE_CPU_PROFILER -DBRPC_ENABLE_HEAP_PROFILER
endif endif
HDRPATHS = -I$(BRPC_PATH)/output/include $(addprefix -I, $(HDRS)) HDRS+=$(BRPC_PATH)/output/include
LIBPATHS = -L$(BRPC_PATH)/output/lib $(addprefix -L, $(LIBS)) LIBS+=$(BRPC_PATH)/output/lib
HDRPATHS = $(addprefix -I, $(HDRS))
LIBPATHS = $(addprefix -L, $(LIBS))
COMMA=,
SOPATHS=$(addprefix -Wl$(COMMA)-rpath=, $(LIBS))
STATIC_LINKINGS += -lbrpc STATIC_LINKINGS += -lbrpc
CLIENT_SOURCES = http_client.cpp CLIENT_SOURCES = http_client.cpp
...@@ -33,15 +38,27 @@ clean: ...@@ -33,15 +38,27 @@ clean:
http_client:$(CLIENT_OBJS) http_client:$(CLIENT_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
benchmark_http:$(BENCHMARK_OBJS) benchmark_http:$(BENCHMARK_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
http_server:$(PROTO_OBJS) $(SERVER_OBJS) http_server:$(PROTO_OBJS) $(SERVER_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
%.pb.cc %.pb.h:%.proto %.pb.cc %.pb.h:%.proto
@echo "Generating $@" @echo "Generating $@"
......
BRPC_PATH = ../../ BRPC_PATH = ../../
include $(BRPC_PATH)/config.mk include $(BRPC_PATH)/config.mk
CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -fPIC -fno-omit-frame-pointer CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -fPIC -fno-omit-frame-pointer
HDRPATHS = -I$(BRPC_PATH)/output/include $(addprefix -I, $(HDRS)) HDRS+=$(BRPC_PATH)/output/include
LIBPATHS = -L$(BRPC_PATH)/output/lib $(addprefix -L, $(LIBS)) LIBS+=$(BRPC_PATH)/output/lib
HDRPATHS = $(addprefix -I, $(HDRS))
LIBPATHS = $(addprefix -L, $(LIBS))
COMMA=,
SOPATHS=$(addprefix -Wl$(COMMA)-rpath=, $(LIBS))
STATIC_LINKINGS += -lbrpc STATIC_LINKINGS += -lbrpc
SOURCES = $(wildcard *.cpp) SOURCES = $(wildcard *.cpp)
...@@ -18,7 +23,11 @@ clean: ...@@ -18,7 +23,11 @@ clean:
memcache_client:$(OBJS) memcache_client:$(OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
%.o:%.cpp %.o:%.cpp
@echo "Compiling $@" @echo "Compiling $@"
......
...@@ -8,8 +8,14 @@ CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -Wno-u ...@@ -8,8 +8,14 @@ CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -Wno-u
ifeq ($(NEED_GPERFTOOLS), 1) ifeq ($(NEED_GPERFTOOLS), 1)
CXXFLAGS += -DBRPC_ENABLE_CPU_PROFILER -DBRPC_ENABLE_HEAP_PROFILER CXXFLAGS += -DBRPC_ENABLE_CPU_PROFILER -DBRPC_ENABLE_HEAP_PROFILER
endif endif
HDRPATHS=-I$(BRPC_PATH)/output/include $(addprefix -I, $(HDRS)) HDRS+=$(BRPC_PATH)/output/include
LIBPATHS=-L$(BRPC_PATH)/output/lib $(addprefix -L, $(LIBS)) LIBS+=$(BRPC_PATH)/output/lib
HDRPATHS=$(addprefix -I, $(HDRS))
LIBPATHS=$(addprefix -L, $(LIBS))
COMMA=,
SOPATHS=$(addprefix -Wl$(COMMA)-rpath=, $(LIBS))
STATIC_LINKINGS+=-lbrpc STATIC_LINKINGS+=-lbrpc
CLIENT_SOURCES = client.cpp CLIENT_SOURCES = client.cpp
...@@ -31,11 +37,19 @@ clean: ...@@ -31,11 +37,19 @@ clean:
echo_client:$(PROTO_OBJS) $(CLIENT_OBJS) echo_client:$(PROTO_OBJS) $(CLIENT_OBJS)
@echo "Linking $@" @echo "Linking $@"
$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
echo_server:$(PROTO_OBJS) $(SERVER_OBJS) echo_server:$(PROTO_OBJS) $(SERVER_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
%.pb.cc %.pb.h:%.proto %.pb.cc %.pb.h:%.proto
@echo "Generating $@" @echo "Generating $@"
......
BRPC_PATH = ../../ BRPC_PATH = ../../
include $(BRPC_PATH)/config.mk include $(BRPC_PATH)/config.mk
CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -fPIC -fno-omit-frame-pointer CXXFLAGS = -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Werror -fPIC -fno-omit-frame-pointer
HDRPATHS = -I$(BRPC_PATH)/output/include $(addprefix -I, $(HDRS)) HDRS+=$(BRPC_PATH)/output/include
LIBPATHS = -L$(BRPC_PATH)/output/lib $(addprefix -L, $(LIBS)) LIBS+=$(BRPC_PATH)/output/lib
HDRPATHS = $(addprefix -I, $(HDRS))
LIBPATHS = $(addprefix -L, $(LIBS))
COMMA=,
SOPATHS=$(addprefix -Wl$(COMMA)-rpath=, $(LIBS))
DYNAMIC_LINKINGS += -lreadline -lncurses DYNAMIC_LINKINGS += -lreadline -lncurses
STATIC_LINKINGS += -lbrpc STATIC_LINKINGS += -lbrpc
...@@ -22,11 +27,19 @@ clean: ...@@ -22,11 +27,19 @@ clean:
redis_press:$(PRESS_OBJS) redis_press:$(PRESS_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
redis_cli:$(CLI_OBJS) redis_cli:$(CLI_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifneq ("$(LINK_SO)", "")
@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
else
@$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@ @$(CXX) $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) -o $@
endif
%.o:%.cpp %.o:%.cpp
@echo "Compiling $@" @echo "Compiling $@"
......
...@@ -24,15 +24,13 @@ ...@@ -24,15 +24,13 @@
#include "brpc/reloadable_flags.h" #include "brpc/reloadable_flags.h"
#include "brpc/builtin/pprof_perl.h" #include "brpc/builtin/pprof_perl.h"
#include "brpc/builtin/hotspots_service.h" #include "brpc/builtin/hotspots_service.h"
#include "brpc/details/tcmalloc_extension.h"
extern "C" { extern "C" {
int __attribute__((weak)) ProfilerStart(const char* fname); int __attribute__((weak)) ProfilerStart(const char* fname);
void __attribute__((weak)) ProfilerStop(); void __attribute__((weak)) ProfilerStop();
} }
void __attribute__((weak)) TCMallocGetHeapSample(std::string* writer);
void __attribute__((weak)) TCMallocGetHeapGrowthStacks(std::string* writer);
namespace bthread { namespace bthread {
bool ContentionProfilerStart(const char* filename); bool ContentionProfilerStart(const char* filename);
void ContentionProfilerStop(); void ContentionProfilerStop();
...@@ -661,7 +659,8 @@ static void DoProfiling(ProfilingType type, ...@@ -661,7 +659,8 @@ static void DoProfiling(ProfilingType type,
} }
bthread::ContentionProfilerStop(); bthread::ContentionProfilerStop();
} else if (type == PROFILING_HEAP) { } else if (type == PROFILING_HEAP) {
if ((void*)TCMallocGetHeapSample == NULL) { MallocExtension* malloc_ext = MallocExtension::instance();
if (malloc_ext == NULL) {
os << "Heap profiler is not enabled" os << "Heap profiler is not enabled"
<< (use_html ? "</body></html>" : "\n"); << (use_html ? "</body></html>" : "\n");
os.move_to(resp); os.move_to(resp);
...@@ -669,7 +668,7 @@ static void DoProfiling(ProfilingType type, ...@@ -669,7 +668,7 @@ static void DoProfiling(ProfilingType type,
return NotifyWaiters(type, cntl, view); return NotifyWaiters(type, cntl, view);
} }
std::string obj; std::string obj;
TCMallocGetHeapSample(&obj); malloc_ext->GetHeapSample(&obj);
if (!WriteSmallFile(prof_name, obj)) { if (!WriteSmallFile(prof_name, obj)) {
os << "Fail to write " << prof_name os << "Fail to write " << prof_name
<< (use_html ? "</body></html>" : "\n"); << (use_html ? "</body></html>" : "\n");
...@@ -679,7 +678,8 @@ static void DoProfiling(ProfilingType type, ...@@ -679,7 +678,8 @@ static void DoProfiling(ProfilingType type,
return NotifyWaiters(type, cntl, view); return NotifyWaiters(type, cntl, view);
} }
} else if (type == PROFILING_GROWTH) { } else if (type == PROFILING_GROWTH) {
if ((void*)TCMallocGetHeapGrowthStacks == NULL) { MallocExtension* malloc_ext = MallocExtension::instance();
if (malloc_ext == NULL) {
os << "Growth profiler is not enabled" os << "Growth profiler is not enabled"
<< (use_html ? "</body></html>" : "\n"); << (use_html ? "</body></html>" : "\n");
os.move_to(resp); os.move_to(resp);
...@@ -687,7 +687,7 @@ static void DoProfiling(ProfilingType type, ...@@ -687,7 +687,7 @@ static void DoProfiling(ProfilingType type,
return NotifyWaiters(type, cntl, view); return NotifyWaiters(type, cntl, view);
} }
std::string obj; std::string obj;
TCMallocGetHeapGrowthStacks(&obj); malloc_ext->GetHeapGrowthStacks(&obj);
if (!WriteSmallFile(prof_name, obj)) { if (!WriteSmallFile(prof_name, obj)) {
os << "Fail to write " << prof_name os << "Fail to write " << prof_name
<< (use_html ? "</body></html>" : "\n"); << (use_html ? "</body></html>" : "\n");
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "brpc/closure_guard.h" // ClosureGuard #include "brpc/closure_guard.h" // ClosureGuard
#include "brpc/builtin/pprof_service.h" #include "brpc/builtin/pprof_service.h"
#include "brpc/builtin/common.h" #include "brpc/builtin/common.h"
#include "brpc/details/tcmalloc_extension.h"
#include "bthread/bthread.h" // bthread_usleep #include "bthread/bthread.h" // bthread_usleep
#include "butil/fd_guard.h" #include "butil/fd_guard.h"
...@@ -37,9 +38,6 @@ int __attribute__((weak)) ProfilerStart(const char* fname); ...@@ -37,9 +38,6 @@ int __attribute__((weak)) ProfilerStart(const char* fname);
void __attribute__((weak)) ProfilerStop(); void __attribute__((weak)) ProfilerStop();
} }
void __attribute__((weak)) TCMallocGetHeapSample(std::string* writer);
void __attribute__((weak)) TCMallocGetHeapGrowthStacks(std::string* writer);
namespace bthread { namespace bthread {
bool ContentionProfilerStart(const char* filename); bool ContentionProfilerStart(const char* filename);
void ContentionProfilerStop(); void ContentionProfilerStop();
...@@ -204,7 +202,8 @@ void PProfService::heap( ...@@ -204,7 +202,8 @@ void PProfService::heap(
::google::protobuf::Closure* done) { ::google::protobuf::Closure* done) {
ClosureGuard done_guard(done); ClosureGuard done_guard(done);
Controller* cntl = static_cast<Controller*>(controller_base); Controller* cntl = static_cast<Controller*>(controller_base);
if ((void*)TCMallocGetHeapSample == NULL) { MallocExtension* malloc_ext = MallocExtension::instance();
if (malloc_ext == NULL) {
cntl->SetFailed(ENOMETHOD, "%s, to enable heap profiler, check out " cntl->SetFailed(ENOMETHOD, "%s, to enable heap profiler, check out "
"docs/cn/heap_profiler.md", "docs/cn/heap_profiler.md",
berror(ENOMETHOD)); berror(ENOMETHOD));
...@@ -220,7 +219,7 @@ void PProfService::heap( ...@@ -220,7 +219,7 @@ void PProfService::heap(
LOG(INFO) << " requests for heap profile"; LOG(INFO) << " requests for heap profile";
std::string obj; std::string obj;
TCMallocGetHeapSample(&obj); malloc_ext->GetHeapSample(&obj);
cntl->http_response().set_content_type("text/plain"); cntl->http_response().set_content_type("text/plain");
cntl->response_attachment().append(obj); cntl->response_attachment().append(obj);
} }
...@@ -232,7 +231,8 @@ void PProfService::growth( ...@@ -232,7 +231,8 @@ void PProfService::growth(
::google::protobuf::Closure* done) { ::google::protobuf::Closure* done) {
ClosureGuard done_guard(done); ClosureGuard done_guard(done);
Controller* cntl = static_cast<Controller*>(controller_base); Controller* cntl = static_cast<Controller*>(controller_base);
if ((void*)TCMallocGetHeapGrowthStacks == NULL) { MallocExtension* malloc_ext = MallocExtension::instance();
if (malloc_ext == NULL) {
cntl->SetFailed(ENOMETHOD, "%s, to enable growth profiler, check out " cntl->SetFailed(ENOMETHOD, "%s, to enable growth profiler, check out "
"docs/cn/heap_profiler.md", "docs/cn/heap_profiler.md",
berror(ENOMETHOD)); berror(ENOMETHOD));
...@@ -248,7 +248,7 @@ void PProfService::growth( ...@@ -248,7 +248,7 @@ void PProfService::growth(
LOG(INFO) << " requests for growth profile"; LOG(INFO) << " requests for growth profile";
std::string obj; std::string obj;
TCMallocGetHeapGrowthStacks(&obj); malloc_ext->GetHeapGrowthStacks(&obj);
cntl->http_response().set_content_type("text/plain"); cntl->http_response().set_content_type("text/plain");
cntl->response_attachment().append(obj); cntl->response_attachment().append(obj);
} }
......
...@@ -30,13 +30,6 @@ void ProfilerStop(const char*); ...@@ -30,13 +30,6 @@ void ProfilerStop(const char*);
#endif #endif
#endif #endif
#if defined(BRPC_ENABLE_HEAP_PROFILER) || defined(BAIDU_RPC_ENABLE_HEAP_PROFILER)
#include <string>
void TCMallocGetHeapSample(std::string* writer);
void TCMallocGetHeapGrowthStacks(std::string* writer);
#endif
namespace brpc { namespace brpc {
// defined in src/brpc/builtin/index_service.cpp // defined in src/brpc/builtin/index_service.cpp
...@@ -49,7 +42,7 @@ extern int PROFILER_LINKER_DUMMY; ...@@ -49,7 +42,7 @@ extern int PROFILER_LINKER_DUMMY;
struct ProfilerLinker { struct ProfilerLinker {
// [ Must be inlined ] // [ Must be inlined ]
// This function is included by user's compilation unit to force // This function is included by user's compilation unit to force
// linking of ProfilerStart()/ProfilerStop()/TCMallocGetHeapSample() // linking of ProfilerStart()/ProfilerStop()
// etc when corresponding macros are defined. // etc when corresponding macros are defined.
inline ProfilerLinker() { inline ProfilerLinker() {
...@@ -64,10 +57,6 @@ struct ProfilerLinker { ...@@ -64,10 +57,6 @@ struct ProfilerLinker {
#if defined(BRPC_ENABLE_HEAP_PROFILER) || defined(BAIDU_RPC_ENABLE_HEAP_PROFILER) #if defined(BRPC_ENABLE_HEAP_PROFILER) || defined(BAIDU_RPC_ENABLE_HEAP_PROFILER)
heap_profiler_enabled = true; heap_profiler_enabled = true;
if (PROFILER_LINKER_DUMMY != 0/*must be false*/) {
TCMallocGetHeapSample(NULL);
TCMallocGetHeapGrowthStacks(NULL);
}
#endif #endif
} }
}; };
......
#include "butil/compiler_specific.h"
#include "brpc/details/tcmalloc_extension.h"
MallocExtension* BAIDU_WEAK MallocExtension::instance() {
return NULL;
}
// This file pastes google/malloc_extension.h and implements
// TCMallocGetHeapSample in the last sections.
// Copyright (c) 2005, Google Inc. // Copyright (c) 2005, Google Inc.
// All rights reserved. // All rights reserved.
// //
...@@ -65,7 +62,7 @@ static const int kMallocHistogramSize = 64; ...@@ -65,7 +62,7 @@ static const int kMallocHistogramSize = 64;
typedef std::string MallocExtensionWriter; typedef std::string MallocExtensionWriter;
namespace butil { namespace base {
struct MallocRange; struct MallocRange;
} }
...@@ -120,7 +117,7 @@ class PERFTOOLS_DLL_DECL MallocExtension { ...@@ -120,7 +117,7 @@ class PERFTOOLS_DLL_DECL MallocExtension {
// //
// This is a best-effort interface useful only for performance // This is a best-effort interface useful only for performance
// analysis. The implementation may not call func at all. // analysis. The implementation may not call func at all.
typedef void (RangeFunction)(void*, const butil::MallocRange*); typedef void (RangeFunction)(void*, const base::MallocRange*);
virtual void Ranges(void* arg, RangeFunction func); virtual void Ranges(void* arg, RangeFunction func);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -314,12 +311,3 @@ class PERFTOOLS_DLL_DECL MallocExtension { ...@@ -314,12 +311,3 @@ class PERFTOOLS_DLL_DECL MallocExtension {
// in the address space size. // in the address space size.
virtual void** ReadHeapGrowthStackTraces(); virtual void** ReadHeapGrowthStackTraces();
}; };
// Following functions will not be linked when BRPC_ENABLE_HEAP_PROFILER is
// undefined.
void TCMallocGetHeapSample(std::string* writer) {
MallocExtension::instance()->GetHeapSample(writer);
}
void TCMallocGetHeapGrowthStacks(std::string* writer) {
MallocExtension::instance()->GetHeapGrowthStacks(writer);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment