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

[feature] #4089: Add profiling support to iroha #4220

Merged
merged 4 commits into from
Jan 24, 2024
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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/target
Dockerfile
Dockerfile*
39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,45 @@ tokio-console http://127.0.0.1:5555

</details>

### Profiling

<details> <summary> Expand to learn ho to profile iroha. </summary>

To optimize performance it's useful to profile iroha.

To do that you should compile iroha with `profiling` profile and with `wasm_profiling` compilation flag:

```bash
RUSTFLAGS="-C force-frame-pointers=on --cfg wasm_profiling" cargo build --profile profiling
```

Then start iroha and attach profiler of your choice to the iroha pid.

Alternatively it's possible to build iroha inside docker with profiler support and profile iroha this way.

```bash
docker build -f Dockerfile.glibc --build-arg="PROFILE=profiling" --build-arg='RUSTFLAGS=-C force-frame-pointers=on --cfg wasm_profiling' -t iroha2:profiling .
```

E.g. using perf (available only on linux):
mversic marked this conversation as resolved.
Show resolved Hide resolved

```bash
# to capture profile
sudo perf record -g -p <PID>
# to analyze profile
sudo perf report
```

To be able to observe profile of the executor during iroha profiling, executor should be compiled without stripping symbols.
It can be done by running:

```bash
# compile executor without optimizations
cargo run --bin iroha_wasm_builder_cli -- build ./path/to/executor --outfile executor.wasm
```

</details>

## Style Guides

Please follow these guidelines when you make code contributions to our project:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,7 @@ members = [
inherits = "release"
strip = "symbols"
lto = true

[profile.profiling]
inherits = "release"
debug = "line-tables-only"
mversic marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 17 additions & 22 deletions Dockerfile.glibc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#base stage
FROM archlinux:base-devel AS builder
# base stage
FROM debian:bookworm-slim AS builder

# Force-sync packages, install archlinux-keyring, repopulate keys
RUN pacman -Syy
RUN pacman -S archlinux-keyring --noconfirm --disable-download-timeout
RUN rm -rf /etc/pacman.d/gnupg/* && pacman-key --init && pacman-key --populate archlinux
# install required packages
RUN apt-get update -y && \
apt-get install -y curl build-essential mold

# Install updates
RUN pacman -Syu --noconfirm --disable-download-timeout

# Set up Rust toolchain
RUN pacman -S rustup mold wget --noconfirm --disable-download-timeout
# set up Rust toolchain
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup toolchain install nightly-2024-01-12
RUN rustup default nightly-2024-01-12
RUN rustup target add wasm32-unknown-unknown
Expand All @@ -19,15 +16,16 @@ RUN rustup component add rust-src
# builder stage
WORKDIR /iroha
COPY . .
RUN mold --run cargo build --target x86_64-unknown-linux-gnu --profile deploy
ARG PROFILE="deploy"
ARG RUSTFLAGS=""
RUN RUSTFLAGS="${RUSTFLAGS}" mold --run cargo build --target x86_64-unknown-linux-gnu --profile "${PROFILE}"

# final image
FROM alpine:3.18
FROM debian:bookworm-slim

ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.35-r1
ARG PROFILE="deploy"
mversic marked this conversation as resolved.
Show resolved Hide resolved
ARG STORAGE=/storage
ARG TARGET_DIR=/iroha/target/x86_64-unknown-linux-gnu/deploy
ARG TARGET_DIR=/iroha/target/x86_64-unknown-linux-gnu/${PROFILE}
ENV BIN_PATH=/usr/local/bin/
ENV CONFIG_DIR=/config
ENV IROHA2_CONFIG_PATH=$CONFIG_DIR/config.json
Expand All @@ -39,12 +37,9 @@ ENV UID=1001
ENV GID=1001

RUN set -ex && \
apk --update add libstdc++ curl ca-certificates gcompat && \
Erigara marked this conversation as resolved.
Show resolved Hide resolved
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
apk add --force-overwrite --allow-untrusted /tmp/*.apk && \
rm -v /tmp/*.apk && \
addgroup -g $GID $USER && \
apt-get update -y && \
apt-get install -y curl ca-certificates && \
addgroup --gid $GID $USER && \
adduser \
--disabled-password \
--gecos "" \
Expand Down
4 changes: 4 additions & 0 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ fn create_config() -> Result<Config> {
.consume_fuel(true)
.cache_config_load_default()
.map_err(Error::Initialization)?;
#[cfg(wasm_profiling)]
{
config.profiler(wasmtime::ProfilingStrategy::PerfMap);
}
Ok(config)
}

Expand Down