Skip to content

Commit

Permalink
Merge branch 'master' into inflight-detect
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen committed May 19, 2022
2 parents 4cf0b17 + 486761a commit 500c4d6
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 55 deletions.
51 changes: 23 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
publish = false

[features]
default = ["test-engine-kv-rocksdb", "test-engine-raft-raft-engine", "cloud-aws", "cloud-gcp", "cloud-azure"]
default = ["test-engine-kv-rocksdb", "test-engine-raft-raft-engine", "cloud-aws", "cloud-gcp", "cloud-azure", "pprof-dwarf"]
tcmalloc = ["tikv_alloc/tcmalloc"]
jemalloc = ["tikv_alloc/jemalloc", "engine_rocks/jemalloc"]
mimalloc = ["tikv_alloc/mimalloc"]
Expand Down Expand Up @@ -53,6 +53,8 @@ test-engines-panic = [
]
cloud-storage-grpc = ["sst_importer/cloud-storage-grpc"]
cloud-storage-dylib = ["sst_importer/cloud-storage-dylib"]
pprof-dwarf = ["pprof/backtrace-rs"]
pprof-fp = ["pprof/frame-pointer"]

# for testing configure propegate to other crates
# https://stackoverflow.com/questions/41700543/can-we-share-test-utilites-between-crates
Expand Down Expand Up @@ -123,6 +125,7 @@ paste = "1.0"
pd_client = { path = "components/pd_client", default-features = false }
pin-project = "1.0"
pnet_datalink = "0.23"
pprof = { git = "https://github.com/tikv/pprof-rs.git", rev = "a5a993a33a23557b27e633f18723366281d3b1c0", default-features = false, features = ["flamegraph", "protobuf-codec"] }
prometheus = { version = "0.13", features = ["nightly"] }
prometheus-static-metric = "0.5"
protobuf = { version = "2.8", features = ["bytes"] }
Expand Down Expand Up @@ -167,9 +170,6 @@ uuid = { version = "0.8.1", features = ["serde", "v4"] }
walkdir = "2"
yatp = { git = "https://github.com/tikv/yatp.git", branch = "master" }

[target.'cfg(target_arch = "x86_64")'.dependencies]
pprof = { version = "^0.6", default-features = false, features = ["flamegraph", "protobuf-codec"] }

[dev-dependencies]
api_version = { path = "components/api_version", features = ["testexport"] }
example_plugin = { path = "components/test_coprocessor_plugin/example_plugin" } # should be a binary dependency
Expand All @@ -187,7 +187,6 @@ raft = { git = "https://github.com/tikv/raft-rs", branch = "master" }
raft-proto = { git = "https://github.com/tikv/raft-rs", branch = "master" }
protobuf = { git = "https://github.com/pingcap/rust-protobuf", branch = "v2.8" }
protobuf-codegen = { git = "https://github.com/pingcap/rust-protobuf", branch = "v2.8" }
pprof = { git = "https://github.com/tikv/pprof-rs.git" }

# TODO: remove this replacement after rusoto_s3 truly supports virtual-host style (https://github.com/rusoto/rusoto/pull/1823).
rusoto_core = { git = "https://github.com/tikv/rusoto", branch = "gh1482-s3-addr-styles" }
Expand Down
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@
SHELL := bash
ENABLE_FEATURES ?=

# Frame pointer is enabled by default. The purpose is to provide stable and
# reliable stack backtraces (for CPU Profiling).
#
# If you want to disable frame-pointer, please manually set the environment
# variable `TIKV_FRAME_POINTER=0 make` (This will fallback to `libunwind`
# based stack backtrace.).
#
# Note that enabling frame-pointer means that the Rust standard library will
# be recompiled.
ifndef TIKV_FRAME_POINTER
export TIKV_FRAME_POINTER=1
endif

ifeq ($(TIKV_FRAME_POINTER),1)
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 @@ -110,6 +129,7 @@ BUILD_INFO_GIT_FALLBACK := "Unknown (no git or not git repo)"
BUILD_INFO_RUSTC_FALLBACK := "Unknown"
export TIKV_ENABLE_FEATURES := ${ENABLE_FEATURES}
export TIKV_BUILD_RUSTC_VERSION := $(shell rustc --version 2> /dev/null || echo ${BUILD_INFO_RUSTC_FALLBACK})
export TIKV_BUILD_RUSTC_TARGET := $(shell rustc -vV | awk '/host/ { print $$2 }')
export TIKV_BUILD_GIT_HASH ?= $(shell git rev-parse HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK})
export TIKV_BUILD_GIT_TAG ?= $(shell git describe --tag || echo ${BUILD_INFO_GIT_FALLBACK})
export TIKV_BUILD_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK})
Expand All @@ -123,6 +143,16 @@ export DOCKER_IMAGE_TAG ?= "latest"
# https://internals.rust-lang.org/t/evaluating-pipelined-rustc-compilation/10199/68
export CARGO_BUILD_PIPELINING=true

# Compiler gave us the following error message when using a specific version of gcc on
# aarch64 architecture and TIKV_FRAME_POINTER=1:
# .../atomic.rs: undefined reference to __aarch64_xxx
# This is a temporary workaround.
# See: https://github.com/rust-lang/rust/issues/93166
# https://bugzilla.redhat.com/show_bug.cgi?id=1830472
ifeq ($(TIKV_BUILD_RUSTC_TARGET),aarch64-unknown-linux-gnu)
export RUSTFLAGS := $(RUSTFLAGS) -Ctarget-feature=-outline-atomics
endif

# Almost all the rules in this Makefile are PHONY
# Declaring a rule as PHONY could improve correctness
# But probably instead just improves performance by a little bit
Expand Down Expand Up @@ -150,8 +180,20 @@ dev: format clippy
@env FAIL_POINT=1 make test

build: export TIKV_PROFILE=debug
ifeq ($(TIKV_FRAME_POINTER),1)
build: ENABLE_FEATURES += pprof-fp
build:
rustup component add rust-src
cargo build --no-default-features --features "${ENABLE_FEATURES}" \
-Z build-std=core,std,alloc,proc_macro,test \
-Z unstable-options \
--target "${TIKV_BUILD_RUSTC_TARGET}" \
--out-dir "${CARGO_TARGET_DIR}/debug"
else
build: ENABLE_FEATURES += pprof-dwarf
build:
cargo build --no-default-features --features "${ENABLE_FEATURES}"
endif

## Release builds (optimized dev builds)
## ----------------------------
Expand All @@ -164,8 +206,20 @@ build:
# sse2-level instruction set), but with sse4.2 and the PCLMUL instruction
# enabled (the "sse" option)
release: export TIKV_PROFILE=release
ifeq ($(TIKV_FRAME_POINTER),1)
release: ENABLE_FEATURES += pprof-fp
release:
rustup component add rust-src
cargo build --release --no-default-features --features "${ENABLE_FEATURES}" \
-Z build-std=core,std,alloc,proc_macro,test \
-Z unstable-options \
--target "${TIKV_BUILD_RUSTC_TARGET}" \
--out-dir "${CARGO_TARGET_DIR}/release"
else
release: ENABLE_FEATURES += pprof-dwarf
release:
cargo build --release --no-default-features --features "${ENABLE_FEATURES}"
endif

# An optimized build that builds an "unportable" RocksDB, which means it is
# built with -march native. It again includes the "sse" option by default.
Expand Down Expand Up @@ -356,10 +410,16 @@ endif

export X_CARGO_ARGS:=${CARGO_ARGS}

ifeq ($(TIKV_FRAME_POINTER),1)
x-build-dist: ENABLE_FEATURES += pprof-fp
else
x-build-dist: ENABLE_FEATURES += pprof-dwarf
endif
x-build-dist: export X_CARGO_CMD=build
x-build-dist: export X_CARGO_FEATURES=${ENABLE_FEATURES}
x-build-dist: export X_CARGO_RELEASE=1
x-build-dist: export X_CARGO_CONFIG_FILE=${DIST_CONFIG}
x-build-dist: export X_CARGO_TARGET_DIR=${CARGO_TARGET_DIR}
x-build-dist: export X_PACKAGE=tikv-server tikv-ctl
x-build-dist:
bash scripts/run-cargo.sh
5 changes: 4 additions & 1 deletion cmd/tikv-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
publish = false

[features]
default = ["test-engine-kv-rocksdb", "test-engine-raft-raft-engine", "cloud-aws", "cloud-gcp", "cloud-azure"]
default = ["test-engine-kv-rocksdb", "test-engine-raft-raft-engine", "cloud-aws", "cloud-gcp", "cloud-azure", "pprof-dwarf"]
tcmalloc = ["server/tcmalloc"]
jemalloc = ["server/jemalloc"]
mimalloc = ["server/mimalloc"]
Expand All @@ -28,6 +28,9 @@ test-engines-panic = ["server/test-engines-panic"]

nortcheck = ["server/nortcheck"]

pprof-dwarf = ["tikv/pprof-dwarf"]
pprof-fp = ["tikv/pprof-fp"]

[dependencies]
clap = "2.32"
server = { path = "../../components/server", default-features = false }
Expand Down
23 changes: 22 additions & 1 deletion scripts/run-cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,33 @@ if [[ -n "$X_RUSTFLAGS" ]]; then
packages="--package=tikv"
fi

build_std_args=""
if [[ -n "$TIKV_FRAME_POINTER" && "$TIKV_FRAME_POINTER" != "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.
build_std_args="$build_std_args -Z build-std=core,std,alloc,proc_macro,test --target=$TIKV_BUILD_RUSTC_TARGET"
if [[ -n "$X_CARGO_RELEASE" && "$X_CARGO_RELEASE" != "0" ]]; then
build_std_args="$build_std_args -Z unstable-options --out-dir=$X_CARGO_TARGET_DIR/release"
else
build_std_args="$build_std_args -Z unstable-options --out-dir=$X_CARGO_TARGET_DIR/debug"
fi
fi

# Turn off error -> exit
set +e

# Print commands
set -x
cargo $args $packages --features="$features" $X_CARGO_ARGS

if [[ -n "$TIKV_FRAME_POINTER" && "$TIKV_FRAME_POINTER" != "0" ]]; then
rustup component add rust-src
cargo $args $packages --features="$features" $X_CARGO_ARGS $build_std_args
else
cargo $args $packages --features="$features" $X_CARGO_ARGS
fi

# Store the exit code
r=$?
Expand Down
Loading

0 comments on commit 500c4d6

Please sign in to comment.