Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable frame pointer #60

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@
SHELL := bash
ENABLE_FEATURES ?=

# Frame pointer is enabled by default.
#
# If you want to disable frame-pointer, please manually set the environment
# variable `PROXY_FRAME_POINTER=0 make` (this will cause CPU Profiling to get
# only the top function and not the full call stack).
ifndef PROXY_FRAME_POINTER
export PROXY_FRAME_POINTER=1
endif

# The Rust standard library is recompiled by default. (The purpose is to enable
# frame pointers in std)
#
# If you want to avoid recompiling the Rust standard library, please manually
# set the environment variable `PROXY_BUILD_STD=0 make` (this will lose CPU
# Profiling samples related to Rust std functions).
ifndef PROXY_BUILD_STD
export PROXY_BUILD_STD=1
endif

ifeq ($(PROXY_FRAME_POINTER),1)
# Enable frame pointers for stable CPU Profiling.
export RUSTFLAGS := $(RUSTFLAGS) -Cforce-frame-pointers=yes
export CFLAGS := $(CFLAGS) -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
export CXXFLAGS := $(CXXFLAGS) -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
endif

# Pick an allocator
ifeq ($(TCMALLOC),1)
ENABLE_FEATURES += tcmalloc
Expand Down Expand Up @@ -101,6 +127,7 @@ BUILD_INFO_GIT_FALLBACK := "Unknown (no git or not git repo)"
BUILD_INFO_RUSTC_FALLBACK := "Unknown"
export PROXY_BUILD_TIME := $(shell date -u '+%Y-%m-%d %H:%M:%S')
export PROXY_BUILD_RUSTC_VERSION := $(shell rustc --version 2> /dev/null || echo ${BUILD_INFO_RUSTC_FALLBACK})
export PROXY_BUILD_RUSTC_TARGET := $(shell rustc -vV | awk '/host/ { print $$2 }')
export PROXY_BUILD_GIT_HASH ?= $(shell git rev-parse HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK})
export PROXY_BUILD_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK})
export DOCKER_IMAGE_NAME ?= "pingcap/tikv"
Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ echo "profile is ${PROXY_PROFILE}"
echo "engine is ${ENGINE_LABEL_VALUE}"
echo "prometheus metric name prefix is ${PROMETHEUS_METRIC_NAME_PREFIX}"

if [[ -n "${PROXY_FRAME_POINTER}" && "${PROXY_FRAME_POINTER}" != 0 ]]; then
echo "frame pointer is enabled"
else
echo "frame pointer is disabled"
fi

if [[ -n "${PROXY_BUILD_STD}" && "${PROXY_BUILD_STD}" != 0 ]]; then
echo "rust build-std is enabled"
else
echo "rust build-std is disabled"
fi

lib_suffix="so"
if [[ $(uname -s) == "Darwin" ]]; then
lib_suffix="dylib"
Expand Down
7 changes: 6 additions & 1 deletion cargo-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ fi

set -ex

cargo build --no-default-features --features "${PROXY_ENABLE_FEATURES}" ${cargo_build_extra_parameter}
if [[ -n "${PROXY_BUILD_STD}" && "${PROXY_BUILD_STD}" != "0" ]]; then
rustup component add rust-src
cargo build --no-default-features --features "${PROXY_ENABLE_FEATURES}" ${cargo_build_extra_parameter} ${PROXY_BUILD_STD_ARGS}
else
cargo build --no-default-features --features "${PROXY_ENABLE_FEATURES}" ${cargo_build_extra_parameter}
fi
10 changes: 10 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ set -e
export CARGO_PROFILE_DEV_DEBUG="true"
export CARGO_PROFILE_RELEASE_DEBUG="true"

if [[ -n "${PROXY_BUILD_STD}" && "${PROXY_BUILD_STD}" != "0" ]]; then
# When `-Z build-std` is enabled, `--target` must be specified explicitly,
# and specifying `--target` will cause the generated binary to be located
# in the `target/${TARGET}/release` directory instead of `target/release`,
# so we need to explicitly specify `--out-dir` here, to avoid errors when
# copying the output binary later.
export PROXY_BUILD_STD_ARGS="-Z build-std=core,std,alloc,proc_macro,test --target=${PROXY_BUILD_RUSTC_TARGET}"
export PROXY_BUILD_STD_ARGS="${PROXY_BUILD_STD_ARGS} -Z unstable-options --out-dir=target/debug"
fi

make build
11 changes: 11 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,16 @@ if [[ $(uname -s) == "Darwin" ]]; then
else
export PROXY_BUILD_TYPE=release
export PROXY_PROFILE=release

if [[ -n "${PROXY_BUILD_STD}" && "${PROXY_BUILD_STD}" != "0" ]]; then
# When `-Z build-std` is enabled, `--target` must be specified explicitly,
# and specifying `--target` will cause the generated binary to be located
# in the `target/${TARGET}/release` directory instead of `target/release`,
# so we need to explicitly specify `--out-dir` here, to avoid errors when
# copying the output binary later.
export PROXY_BUILD_STD_ARGS="-Z build-std=core,std,alloc,proc_macro,test --target=${PROXY_BUILD_RUSTC_TARGET}"
export PROXY_BUILD_STD_ARGS="${PROXY_BUILD_STD_ARGS} -Z unstable-options --out-dir=target/release"
fi

make build
fi