Generate profile

From sgl-project/sglang · View interactive version

Generate profile is an AI agent skill from the GitHub repository sgl-project/sglang. Generate an e2e profiling trace of an SGLang server run. Launches a server, validates accuracy, captures a Chrome-compatible trace, and returns the profile path.

How to use this skill

Skill file

Generate an E2E Profile of an SGLang Server Run

This skill launches an SGLang server, validates it with a quick accuracy test, generates a profiling trace, and returns the profile file path.

Prerequisites

Step-by-step Workflow

Step 1: Launch the server

export SGLANG_ADMIN_API_KEY=<admin_key>
CUDA_VISIBLE_DEVICES=<gpu_id> sglang serve --model-path <model> --port <port> &

Step 2: Wait for server readiness

Poll the health endpoint until the server is ready:

for i in $(seq 1 120); do
  if curl -s http://127.0.0.1:<port>/health 2>/dev/null | grep -q "ok\|healthy"; then
    echo "Server ready"
    break
  fi
  sleep 5
done

The server prints "The server is fired up and ready to roll!" to stdout when ready. The health endpoint returns 200 once the server can accept requests.

Typical startup time: 30-90 seconds depending on model size and whether CUDA graphs are being compiled.

Step 3: Validate accuracy (sanity check)

sgl-eval run gsm8k --base-url http://127.0.0.1:<port>/v1 --num-examples 20

Step 4: Generate the profile

python3 -m sglang.test.send_one --profile

This command:

  1. Sends a request to the server
  2. Triggers the profiler for 5 steps (default)
  3. Generates a trace file under /tmp/<timestamp>/
  4. The trace directory contains:

Output format:

Dump profiling traces to /tmp/<timestamp>

The profile path is printed to stdout. Parse it from the output.

Optional flags:

Step 5: Kill the server

pkill -9 -f "sglang.launch_server\|sglang serve\|sglang.srt"

Wait a moment and verify no sglang processes remain:

sleep 2 && pgrep -af "sglang serve" || echo "Server killed"

Step 6: Report the profile path

Return the profile directory path (e.g., /tmp/1773999986.4769795) and list its contents so the user knows what files were generated.

Example Full Run

# 1. Launch server
source cleanup/bin/activate
export SGLANG_ADMIN_API_KEY=sk-admin
CUDA_VISIBLE_DEVICES=1 sglang serve --model-path Qwen/Qwen3-8B --port 30000 &

# 2. Wait for ready
for i in $(seq 1 120); do
  curl -s http://127.0.0.1:30000/health | grep -q "ok" && break
  sleep 5
done

# 3. Accuracy check
sgl-eval run gsm8k --base-url http://127.0.0.1:30000/v1 --num-examples 20
# Expected: score > 80%

# 4. Profile
python3 -m sglang.test.send_one --profile
# Output: "Dump profiling traces to /tmp/1773999986.4769795"

# 5. Cleanup
pkill -9 -f "sglang.launch_server\|sglang serve\|sglang.srt"
sleep 2

# 6. Check output
ls -la /tmp/1773999986.4769795/
# 1773999986.4851577-TP-0.trace.json.gz  (Chrome trace)
# server_args.json                        (server config)

Customization

Viewing the Profile

Open the .trace.json.gz file in:

Both support the gzipped Chrome trace format natively.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.