Skip to content

Commit

Permalink
fix: book + typos
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Nov 15, 2024
1 parent 40b61fc commit 2af35b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
21 changes: 6 additions & 15 deletions book/writing-programs/cycle-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ fn main() {

This will log the cycle count for `block name` and include it in the `ExecutionReport` in the `cycle_tracker` map.

# Profiling the ZKVM
### Profiling the ZKVM

Profiling the VM is a good way to get an understanding of what is bottlenecking your program, and special care must be taken to ensure correctness, only one program may be profiled at a time.
Profiling the VM is a good way to get an understanding of what is bottlenecking your program, note only one program may be profiled at a time.

To profile a program, you have to setup a script to execute the program, many examples can be found in the repo, such as this ('fibonacci')[../../examples/fibonacci/script/src/main.rs] script.
To profile a program, you have to setup a script to execute the program, many examples can be found in the repo, such as this ['fibonacci'](https://github.com/succinctlabs/sp1/blob/12f212e386ae4c2da30cf6a61a7d87615d56bdac/examples/fibonacci/script/src/main.rs#L22) script.
Once you have your script it should contain the following code:
```rs
// Execute the program using the `ProverClient.execute` method, without generating a proof.
Expand All @@ -70,24 +70,15 @@ Once you have your script it should contain the following code:
The data captured by the profiler can be quite large, you can set the sample rate using the `TRACE_SAMPLE_RATE` env var.
To enable profiling, set the `TRACE_FILE` env var to the path where you want the profile to be saved.

A larger sample rate will give you a smaller profile, it is the number of instructions in between each sample.

The full command to profile should look something like this
```sh
TRACE_FILE=output.json TRACE_SAMPLE_RATE=100 cargo run ...
```

To view these profiles, we recommend (Samply)[https://github.com/mstange/samply].
To view these profiles, we recommend [Samply](https://github.com/mstange/samply).
```sh
cargo install --locked samply
samply load output.json
```

To profile in release mode you can use the following setup in your `Cargo.toml`
```toml
[profile.zkvm-profiling]
inherits = "release"
debug-assertions = true
```

and then you can do:

`cargo run --profile zkvm-profiling --bin your_program`
6 changes: 3 additions & 3 deletions crates/core/executor/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum ProfilerError {

/// The ZKVM Profiler.
///
/// During exeuction, the profiler always keeps track of the callstack
/// During execution, the profiler always keeps track of the callstack
/// and will occasionally save the stack according to the sample rate.
pub struct Profiler {
sample_rate: u64,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Profiler {
let mut function_ranges = Vec::new();
let mut builder = ThreadBuilder::new(1, 0, std::time::Instant::now(), false, false);

// we need to extract all the functions from the elf file
// We need to extract all the functions from the elf file
// and thier corresponding PC ranges.
let mut main_idx = None;
for sym in &elf.syms {
Expand All @@ -63,7 +63,7 @@ impl Profiler {
let start_address = sym.st_value;
let end_address = start_address + size - 4;

// now that we have the name lets immeidalty intern it so we only need to copy
// Now that we have the name lets immediately intern it so we only need to copy
// around a usize
let demangled_name = demangled_name.to_string();
let string_idx = builder.intern_string(&demangled_name);
Expand Down

0 comments on commit 2af35b6

Please sign in to comment.