CS 4414/5416:
Systems Programming

Lab 4: Profiling and Memory Layout

2026-09-18

Lab Logistics Reminder

Primary goal: Work together on something

  • Fine to have small groups (up to 4)
  • Work on the lab assignment during the hour
  • Submit lab_04-0.1.0.crate on Gradescope

This lab is about getting going on Google Compute Engine and doing some timing and profiling.

Google Cloud Setup

  • If you haven’t yet, start by making a project
  • Next steps: VPC and VM

Virtual Private Cloud

  • Go to the side menu: VPC Network / VPC networks
  • Create a VPC (if you haven’t already)
    • Name: cs4414
    • Subnet Name: cs4414-[region]
    • Subnet Region: e.g. us-central1
    • Subnet IPv4 range: e.g. 10.0.0.0/24

Virtual Private Cloud

  • Create a VPC firewall rule:
    • Name: allow-ingress-from-iap
    • Direction: Ingress
    • IP range: 35.235.240.0/20
    • Protocols and ports: 22, 3389
  • Optional: 0.0.0.0/0 IP filter for port 22
    (allows gcloud CLI to ssh in)

VM Instance

  • Go to side menu: Compute Engine / VM instances
  • Click Create Instance at the top of the screen
  • Choose a C4D instance type
  • Use the c4d-highcpu-2 preset

Standard provisioning, OS, and storage is fine

  • Debian GNU/Linux 13 (trixie)

VM Instance notes

  • This instance type is about $58 / mo.
    • You have a $50 credit (cashed in, I hope!)
    • The instance is running at creation
    • Make sure you shut down VMs when not in use!
  • Can attach cheaper instances to the same disk!
  • Or develop for correctness locally, tune on GCE

Setting Up the VM

SSH into the VM instance and set things up:

sudo apt update
sudo apt install build-essential
sudo apt install rustup
rustup default stable

Add to .profile

PATH="$HOME/.cargo/bin:$PATH"
CARGO_HOME="$HOME/.cargo"
RUSTUP_HOME="$HOME/.rustup"

May want to exit and log back in to get these variables.

Installing Samply

From the shell

cargo install --locked samply

Give samply access to performance events system:

sudo sysctl kernel.perf_event_paranoid=1

Set up an SSH Key

If you want to read-write Cornell Github:

ssh-keygen -t rsa
cat .ssh/id_rsa.pub

Then go to https://github.coecis.cornell.edu/, go to your account settings, and under SSH and GPG keys, copy this text in place.

Cloning the Repo

Repo is at https://github.coecis.cornell.edu/cs4414-f26/lab-04

Can clone with ssh as:

git clone git@github.coecis.cornell.edu:cs4414-f26/lab-04.git

or via HTTPS via

git clone https://github.coecis.cornell.edu/cs4414-f26/lab-04.git

I default to the former (with an SSH key set up)

Command Line Setup

Can do this lab fully with the web interface, but may want CLI:

Then run gcloud init to set things up.

Cargo Setup

Set up a build profile for profiling

[profile.profiling]
inherits = "release"
debug = true

You probably want debug symbols! Try with just release profile to see why.

Building and Profiling

To run the profiler on sluggy:

cargo build --profile profiling
cd data; ./generate_points.py; cd ..
samply record target/profiling/sluggy

You can Ctrl+C out (or hang on for the next slide)

Viewing the Profile

Basic setup:

You can download profile.json.gz and view directly with the web app, or use the gcloud CLI to set up a tunnel:

gcloud compute ssh instance-name-here \
       --zone=us-central1-a \
       --project=cs-4414-f26 -- -L 3000:127.0.0.1:3000

Then point web browser to 127.0.0.1:3000

The Rest of the Story

Repo: https://github.coecis.cornell.edu/cs4414-f26/lab-04

At the end of the hour

  • Fill out WRITEUP.md
  • Git commit Cargo.toml and profile.json.gz (you will need to do some git config steps)
  • cargo package and submit the crate file on Gradescope