Skip to content

Commit

Permalink
Add support for bytehound memory prfiling in MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya committed Nov 5, 2024
1 parent c72ee42 commit adbdf16
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Memory profiler output
memory-profiling_*
profile-*
profile/memory-profiling_*

# CLI history
.history
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,8 @@ vergen-gitcl = { version = "1", features = ["build", "cargo", "rustc"] }
codegen-units = 1
lto = true
strip = true

[profile.release-with-debug]
debug = true
inherits = "release"
strip = false
47 changes: 47 additions & 0 deletions profile/Dockerfile.profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Image that wraps Seafowl with a bytehound binary and records
# memory allocations for profiling
#
# To build run just the bytehound layer run
# docker build --target bytehound -f Dockerfile.profile -t splitgraph/bytehound .
#
# To build the full image run
# docker build -f Dockerfile.profile -t splitgraph/seafowl:profile ..

FROM rust:slim AS bytehound

RUN apt-get update && \
apt-get install -y git protobuf-compiler ca-certificates npm && \
npm install -g yarn

# Fetch bytehound source and compile
RUN git clone https://github.com/koute/bytehound.git && \
cd bytehound && \
cargo build --release -p bytehound-preload && \
cargo build --release -p bytehound-cli

FROM bytehound AS profile

RUN rustup default nightly-2024-10-30

# Compile an empty project, so as to cache the compiled deps and avoid unneeded re-compilation.
# Adapted from https://gist.github.com/noelbundick/6922d26667616e2ba5c3aff59f0824cd
RUN cargo new seafowl
WORKDIR seafowl
COPY Cargo.toml Cargo.lock build.rs .
COPY clade clade
COPY datafusion_remote_tables datafusion_remote_tables
COPY migrations migrations
COPY object_store_factory object_store_factory
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --profile release-with-debug

# Copy the rest of the code now and update timestamps to force a new build only for it
COPY src src
RUN --mount=type=cache,target=/usr/local/cargo/registry set -e && \
touch src/lib.rs src/main.rs && \
cargo build --profile release-with-debug

RUN cd .. && mkdir seafowl-data

ENV MEMORY_PROFILER_OUTPUT=profiles/memory-profiling_%e_%t_%p.dat
ENV LD_PRELOAD=/bytehound/target/release/libbytehound.so
ENTRYPOINT [ "./target/release-with-debug/seafowl" ]
19 changes: 19 additions & 0 deletions profile/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build-bytehound:
docker build --target bytehound -f Dockerfile.profile -t splitgraph/bytehound .

build-profiler:
docker build -f Dockerfile.profile -t splitgraph/seafowl:profile ..

profile:
docker run \
-p 8080:8080 -p 47470:47470 \
-v .:/seafowl/profiles \
-v `realpath ../seafowl.toml`:/seafowl.toml \
splitgraph/seafowl:profile -c /seafowl.toml

view:
docker run -p 8888:8888 -v .:/profiles -w /profiles splitgraph/bytehound \
/bytehound/target/release/bytehound server -i 0.0.0.0 -p 8888 memory-profiling_*

clean:
rm -rf memory-profiling_*
2 changes: 1 addition & 1 deletion seafowl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ bind_port = 6432
bind_host = "0.0.0.0"

[frontend.flight]
bind_host = "127.0.0.1"
bind_host = "0.0.0.0"

0 comments on commit adbdf16

Please sign in to comment.