From ac24cec37d1f87adf80748b1b71fb8fad077c09f Mon Sep 17 00:00:00 2001 From: dubbelosix Date: Thu, 17 Aug 2023 16:36:33 +0530 Subject: [PATCH 1/4] stack analysis --- utils/zk-cycle-utils/tracer/src/main.rs | 91 +++++++++++++++++++------ 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/utils/zk-cycle-utils/tracer/src/main.rs b/utils/zk-cycle-utils/tracer/src/main.rs index 4feb167db..2ecc12d93 100644 --- a/utils/zk-cycle-utils/tracer/src/main.rs +++ b/utils/zk-cycle-utils/tracer/src/main.rs @@ -38,6 +38,10 @@ struct Args { #[arg(short, long)] /// Strip the hashes from the function name while printing strip_hashes: bool, + + #[arg(short, long)] + /// Function name to target for getting stack counts + function_name: Option, } fn strip_hash(name_with_hash: &str) -> String { @@ -45,11 +49,11 @@ fn strip_hash(name_with_hash: &str) -> String { re.replace(name_with_hash, "").to_string() } -fn print_intruction_counts(count_vec: Vec<(&String, &usize)>, top_n: usize, strip_hashes: bool) { +fn print_intruction_counts(first_header: &str, count_vec: Vec<(String, usize)>, top_n: usize, strip_hashes: bool) { let mut table = Table::new(); table.set_format(*format::consts::FORMAT_DEFAULT); table.set_titles(Row::new(vec![ - Cell::new("Function Name"), + Cell::new(first_header), Cell::new("Instruction Count"), ])); @@ -75,7 +79,18 @@ fn print_intruction_counts(count_vec: Vec<(&String, &usize)>, top_n: usize, stri table.printstd(); } -fn _build_lookups_radare_2( +fn focused_stack_counts(function_stack: &[String], + filtered_stack_counts: &mut HashMap, usize>, + function_name: &str) { + if let Some(last_function) = function_stack.last() { + if last_function == function_name { + let count = filtered_stack_counts.entry(function_stack.to_vec().clone()).or_insert(0); + *count += 1; + } + } +} + +fn _build_radare2_lookups( start_lookup: &mut HashMap, end_lookup: &mut HashMap, func_range_lookup: &mut HashMap, @@ -130,10 +145,17 @@ fn build_goblin_lookups( Ok(()) } -fn increment_stack_counts(instruction_counts: &mut HashMap, function_stack: &[String]) { - for function_name in function_stack { - *instruction_counts.entry(function_name.clone()).or_insert(0) += 1; +fn increment_stack_counts(instruction_counts: &mut HashMap, + function_stack: &[String], + filtered_stack_counts: &mut HashMap, usize>, + function_name: &Option) { + for f in function_stack { + *instruction_counts.entry(f.clone()).or_insert(0) += 1; + } + if let Some(f) = function_name { + focused_stack_counts(function_stack, filtered_stack_counts, &f) } + } fn main() -> std::io::Result<()> { @@ -145,6 +167,7 @@ fn main() -> std::io::Result<()> { let no_stack_counts = args.no_stack_counts; let no_raw_counts = args.no_raw_counts; let strip_hashes = args.strip_hashes; + let function_name = args.function_name; let mut start_lookup = HashMap::new(); let mut end_lookup = HashMap::new(); @@ -153,7 +176,7 @@ fn main() -> std::io::Result<()> { let mut function_ranges: Vec<(u64, u64, String)> = func_range_lookup .iter() - .map(|(function_name, &(start, end))| (start, end, function_name.clone())) + .map(|(f, &(start, end))| (start, end, f.clone())) .collect(); function_ranges.sort_by_key(|&(start, _, _)| start); @@ -162,6 +185,7 @@ fn main() -> std::io::Result<()> { let mut function_stack: Vec = Vec::new(); let mut instruction_counts: HashMap = HashMap::new(); let mut counts_without_callgraph: HashMap = HashMap::new(); + let mut filtered_stack_counts: HashMap, usize> = HashMap::new(); let total_lines = file_content.lines().count() as u64; let mut current_function_range : (u64,u64) = (0,0); @@ -204,17 +228,17 @@ fn main() -> std::io::Result<()> { // we are still in the current function if pc > current_function_range.0 && pc <= current_function_range.1 { - increment_stack_counts(&mut instruction_counts, &function_stack); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); continue; } // jump to a new function (or the same one) - if let Some(function_name) = start_lookup.get(&pc) { - increment_stack_counts(&mut instruction_counts, &function_stack); + if let Some(f) = start_lookup.get(&pc) { + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); // jump to a new function (not recursive) - if !function_stack.contains(&function_name) { - function_stack.push(function_name.clone()); - current_function_range = *func_range_lookup.get(function_name).unwrap(); + if !function_stack.contains(&f) { + function_stack.push(f.clone()); + current_function_range = *func_range_lookup.get(f).unwrap(); } } else { // this means pc now points to an instruction that is @@ -237,33 +261,62 @@ fn main() -> std::io::Result<()> { if unwind_found { function_stack.truncate(unwind_point + 1); - increment_stack_counts(&mut instruction_counts, &function_stack); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); continue; } // if no unwind point has been found, that means we jumped to some random location // so we'll just increment the counts for everything in the stack - increment_stack_counts(&mut instruction_counts, &function_stack); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); } } pb.finish_with_message("done"); - let mut raw_counts: Vec<(&String, &usize)> = instruction_counts.iter().collect(); + let mut raw_counts: Vec<(String, usize)> = instruction_counts + .iter() + .map(|(key, value)| (key.clone(), value.clone())) + .collect(); raw_counts.sort_by(|a, b| b.1.cmp(&a.1)); println!("\n\nTotal instructions in trace: {}", total_lines); if !no_stack_counts { println!("\n\n Instruction counts considering call graph"); - print_intruction_counts(raw_counts, top_n, strip_hashes); + print_intruction_counts("Function Name", raw_counts, top_n, strip_hashes); } - let mut raw_counts: Vec<(&String, &usize)> = counts_without_callgraph.iter().collect(); + let mut raw_counts: Vec<(String, usize)> = counts_without_callgraph + .iter() + .map(|(key, value)| (key.clone(), value.clone())) + .collect(); raw_counts.sort_by(|a, b| b.1.cmp(&a.1)); if !no_raw_counts { println!("\n\n Instruction counts ignoring call graph"); - print_intruction_counts(raw_counts, top_n, strip_hashes); + print_intruction_counts("Function Name",raw_counts, top_n, strip_hashes); + } + + let mut raw_counts: Vec<(String, usize)> = filtered_stack_counts + .iter() + .map(|(stack, count)| { + let numbered_stack = stack + .iter() + .rev() + .enumerate() + .map(|(index, line)| { + let modified_line = if strip_hashes { strip_hash(line) } else { line.clone() }; + format!("({}) {}", index + 1, modified_line) + }) + .collect::>() + .join("\n"); + (numbered_stack, *count) + }) + .collect(); + + raw_counts.sort_by(|a, b| b.1.cmp(&a.1)); + if let Some(f) = function_name { + println!("\n\n Stack patterns for function '{f}' "); + print_intruction_counts("Function Stack",raw_counts, top_n, strip_hashes); } Ok(()) } From 2d0df39ae30ede33400a52484043c2207f94aed3 Mon Sep 17 00:00:00 2001 From: dubbelosix Date: Thu, 17 Aug 2023 17:00:26 +0530 Subject: [PATCH 2/4] fix issues --- examples/demo-prover/host/benches/prover_bench.rs | 6 ++---- examples/demo-prover/methods/guest/src/bin/rollup.rs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/demo-prover/host/benches/prover_bench.rs b/examples/demo-prover/host/benches/prover_bench.rs index 4d7e80d24..3550fa35d 100644 --- a/examples/demo-prover/host/benches/prover_bench.rs +++ b/examples/demo-prover/host/benches/prover_bench.rs @@ -13,8 +13,7 @@ use demo_stf::genesis_config::create_demo_genesis_config; use jupiter::da_service::CelestiaService; use jupiter::types::{FilteredCelestiaBlock, NamespaceId}; use jupiter::verifier::address::CelestiaAddress; -use jupiter::verifier::{ChainValidityCondition, RollupParams}; -use jupiter::BlobWithSender; +use jupiter::verifier::{CelestiaSpec, RollupParams}; use log4rs::config::{Appender, Config, Root}; use methods::ROLLUP_ELF; use regex::Regex; @@ -164,8 +163,7 @@ async fn main() -> Result<(), anyhow::Error> { let sequencer_private_key = DefaultPrivateKey::generate(); - let mut app: App = - App::new(rollup_config.runner.storage.clone()); + let mut app: App = App::new(rollup_config.runner.storage.clone()); let sequencer_da_address = CelestiaAddress::from_str(SEQUENCER_DA_ADDRESS).unwrap(); diff --git a/examples/demo-prover/methods/guest/src/bin/rollup.rs b/examples/demo-prover/methods/guest/src/bin/rollup.rs index 465003904..908060a51 100644 --- a/examples/demo-prover/methods/guest/src/bin/rollup.rs +++ b/examples/demo-prover/methods/guest/src/bin/rollup.rs @@ -9,7 +9,7 @@ use demo_stf::app::create_zk_app_template; use demo_stf::ArrayWitness; use jupiter::types::NamespaceId; use jupiter::verifier::address::CelestiaAddress; -use jupiter::verifier::{CelestiaSpec, CelestiaVerifier, ChainValidityCondition}; +use jupiter::verifier::{CelestiaSpec, CelestiaVerifier}; use jupiter::{BlobWithSender, CelestiaHeader}; use risc0_adapter::guest::Risc0Guest; use risc0_zkvm::guest::env; From 068e9638dc74cecdd0d11decff820132c8d31e88 Mon Sep 17 00:00:00 2001 From: dubbelosix Date: Mon, 21 Aug 2023 17:46:27 +0530 Subject: [PATCH 3/4] some more changes --- examples/demo-prover/Cargo.lock | 5 ++ examples/demo-prover/Makefile | 19 +++++ .../demo-prover/host/benches/prover_bench.rs | 13 ++- examples/demo-prover/methods/guest/Cargo.lock | 1 - .../methods/guest/src/bin/rollup.rs | 1 - examples/demo-rollup/rollup_config.toml | 2 +- utils/zk-cycle-utils/tracer/Cargo.lock | 5 ++ utils/zk-cycle-utils/tracer/src/main.rs | 83 ++++++++++++++----- 8 files changed, 102 insertions(+), 27 deletions(-) create mode 100644 examples/demo-prover/Makefile diff --git a/examples/demo-prover/Cargo.lock b/examples/demo-prover/Cargo.lock index 271eeea6b..af82dc05a 100644 --- a/examples/demo-prover/Cargo.lock +++ b/examples/demo-prover/Cargo.lock @@ -4765,3 +4765,8 @@ dependencies = [ "libc", "pkg-config", ] + +[[patch.unused]] +name = "cc" +version = "1.0.79" +source = "git+https://github.com/rust-lang/cc-rs?rev=e5bbdfa#e5bbdfa1fa468c028cb38fee6c35a3cf2e5a2736" diff --git a/examples/demo-prover/Makefile b/examples/demo-prover/Makefile new file mode 100644 index 000000000..3c6fb360f --- /dev/null +++ b/examples/demo-prover/Makefile @@ -0,0 +1,19 @@ +# Directories and paths +TRACER_DIR = ../../utils/zk-cycle-utils/tracer +ELF_PATH_TRACER = ../../../examples/demo-prover/target/riscv-guest/riscv32im-risc0-zkvm-elf/release/rollup +TRACE_PATH_TRACER = ../../../examples/demo-prover/host/rollup.trace + +# This allows you to pass additional flags when you call `make run-tracer`. +# For example: `make run-tracer ADDITIONAL_FLAGS="--some-flag"` +ADDITIONAL_FLAGS ?= + +.PHONY: generate-files run-tracer + +all: generate-files run-tracer + +generate-files: + ROLLUP_TRACE=rollup.trace cargo bench --bench prover_bench --features bench + +run-tracer: + @cd $(TRACER_DIR) && \ + cargo run --release -- --no-raw-counts --rollup-elf $(ELF_PATH_TRACER) --rollup-trace $(TRACE_PATH_TRACER) $(ADDITIONAL_FLAGS) diff --git a/examples/demo-prover/host/benches/prover_bench.rs b/examples/demo-prover/host/benches/prover_bench.rs index 3550fa35d..f80b8e1c1 100644 --- a/examples/demo-prover/host/benches/prover_bench.rs +++ b/examples/demo-prover/host/benches/prover_bench.rs @@ -52,12 +52,17 @@ impl RegexAppender { impl log::Log for RegexAppender { fn log(&self, record: &log::Record) { if let Some(captures) = self.regex.captures(record.args().to_string().as_str()) { + let mut file_guard = self.file.lock().unwrap(); if let Some(matched_pc) = captures.get(1) { let pc_value_num = u64::from_str_radix(&matched_pc.as_str()[2..], 16).unwrap(); - let pc_value = format!("{}\n", pc_value_num); - let mut file_guard = self.file.lock().unwrap(); + let pc_value = format!("{}\t", pc_value_num); file_guard.write_all(pc_value.as_bytes()).unwrap(); } + if let Some(matched_iname) = captures.get(2) { + let iname = matched_iname.as_str().to_uppercase(); + let iname_value = format!("{}\n", iname); + file_guard.write_all(iname_value.as_bytes()).unwrap(); + } } } @@ -69,8 +74,8 @@ impl log::Log for RegexAppender { } fn get_config(rollup_trace: &str) -> Config { - let regex_pattern = r".*?pc: (0x[0-9a-fA-F]+), insn.*"; - // let log_file = "/Users/dubbelosix/sovereign/examples/demo-prover/matched_pattern.log"; + // [942786] pc: 0x0008e564, insn: 0xffc67613 => andi x12, x12, -4 + let regex_pattern = r".*?pc: (0x[0-9a-fA-F]+), insn: .*?=> ([a-z]*?) "; let custom_appender = RegexAppender::new(regex_pattern, rollup_trace); diff --git a/examples/demo-prover/methods/guest/Cargo.lock b/examples/demo-prover/methods/guest/Cargo.lock index 3b2641dc1..d95b57da8 100644 --- a/examples/demo-prover/methods/guest/Cargo.lock +++ b/examples/demo-prover/methods/guest/Cargo.lock @@ -2063,7 +2063,6 @@ dependencies = [ "risc0-zkvm", "risc0-zkvm-platform", "serde", - "serde_json", "sha2 0.10.6", "sha3", "sov-modules-api", diff --git a/examples/demo-prover/methods/guest/src/bin/rollup.rs b/examples/demo-prover/methods/guest/src/bin/rollup.rs index 908060a51..0a197dfa0 100644 --- a/examples/demo-prover/methods/guest/src/bin/rollup.rs +++ b/examples/demo-prover/methods/guest/src/bin/rollup.rs @@ -104,7 +104,6 @@ pub fn main() { let metrics_syscall_name = unsafe { risc0_zkvm_platform::syscall::SyscallName::from_bytes_with_nul(cycle_string.as_ptr()) }; - risc0_zkvm::guest::env::send_recv_slice::(metrics_syscall_name, &serialized); } } diff --git a/examples/demo-rollup/rollup_config.toml b/examples/demo-rollup/rollup_config.toml index 73fd49c4d..7b2576741 100644 --- a/examples/demo-rollup/rollup_config.toml +++ b/examples/demo-rollup/rollup_config.toml @@ -4,7 +4,7 @@ start_height = 1 [da] # The JWT used to authenticate with the celestia light client. Instructions for generating this token can be found in the README -celestia_rpc_auth_token = "MY.SECRET.TOKEN" +celestia_rpc_auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJwdWJsaWMiLCJyZWFkIiwid3JpdGUiLCJhZG1pbiJdfQ.MhcEa3-fyoZvrf5bJ-sqUnrJi1cHhfKBq0W4lGT-oso" # The address of the *trusted* Celestia light client to interact with celestia_rpc_address = "http://127.0.0.1:26658" # The largest response the rollup will accept from the Celestia node. Defaults to 100 MB diff --git a/utils/zk-cycle-utils/tracer/Cargo.lock b/utils/zk-cycle-utils/tracer/Cargo.lock index 0969d930a..17a87c187 100644 --- a/utils/zk-cycle-utils/tracer/Cargo.lock +++ b/utils/zk-cycle-utils/tracer/Cargo.lock @@ -780,3 +780,8 @@ name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[patch.unused]] +name = "cc" +version = "1.0.79" +source = "git+https://github.com/rust-lang/cc-rs?rev=e5bbdfa#e5bbdfa1fa468c028cb38fee6c35a3cf2e5a2736" diff --git a/utils/zk-cycle-utils/tracer/src/main.rs b/utils/zk-cycle-utils/tracer/src/main.rs index 2ecc12d93..8d039aafc 100644 --- a/utils/zk-cycle-utils/tracer/src/main.rs +++ b/utils/zk-cycle-utils/tracer/src/main.rs @@ -42,6 +42,11 @@ struct Args { #[arg(short, long)] /// Function name to target for getting stack counts function_name: Option, + + #[arg(short, long)] + /// Exclude functions matching these patterns from display + /// usage: -e func1 -e func2 -e func3 + exclude_view: Vec, } fn strip_hash(name_with_hash: &str) -> String { @@ -49,7 +54,29 @@ fn strip_hash(name_with_hash: &str) -> String { re.replace(name_with_hash, "").to_string() } -fn print_intruction_counts(first_header: &str, count_vec: Vec<(String, usize)>, top_n: usize, strip_hashes: bool) { +fn get_cycle_count(insn: &str) -> Result { + match insn { + "LB" | "LH" | "LW" | "LBU" | "LHU" | "ADDI" | "SLLI" | "SLTI" | "SLTIU" | + "AUIPC" | "SB" | "SH" | "SW" | "ADD" | "SUB" | "SLL" | "SLT" | "SLTU" | + "XOR" | "SRL" | "SRA" | "OR" | "AND" | "MUL" | "MULH" | "MULSU" | "MULU" | + "LUI" | "BEQ" | "BNE" | "BLT" | "BGE" | "BLTU" | "BGEU" | "JALR" | "JAL" | + "ECALL" | "EBREAK" => Ok(1), + + // Don't see this in the risc0 code base, but MUL, MULH, MULSU, and MULU all take 1 cycle, + // so going with that for MULHU as well. + "MULHU" => Ok(1), + + "XORI" | "ORI" | "ANDI" | "SRLI" | "SRAI" | "DIV" | "DIVU" | "REM" | "REMU" => Ok(2), + + _ => Err("Decode error"), + } +} + +fn print_intruction_counts(first_header: &str, + count_vec: Vec<(String, usize)>, + top_n: usize, + strip_hashes: bool, + exclude_list: Option<&[String]>) { let mut table = Table::new(); table.set_format(*format::consts::FORMAT_DEFAULT); table.set_titles(Row::new(vec![ @@ -60,6 +87,18 @@ fn print_intruction_counts(first_header: &str, count_vec: Vec<(String, usize)>, let wrap_width = 90; let mut row_count = 0; for (key, value) in count_vec { + let mut cont = false; + if let Some(ev) = exclude_list { + for e in ev { + if key.contains(e) { + cont = true; + break + } + } + if cont { + continue + } + } let mut stripped_key = key.clone(); if strip_hashes { stripped_key = strip_hash(&key); @@ -81,12 +120,12 @@ fn print_intruction_counts(first_header: &str, count_vec: Vec<(String, usize)>, fn focused_stack_counts(function_stack: &[String], filtered_stack_counts: &mut HashMap, usize>, - function_name: &str) { - if let Some(last_function) = function_stack.last() { - if last_function == function_name { - let count = filtered_stack_counts.entry(function_stack.to_vec().clone()).or_insert(0); - *count += 1; - } + function_name: &str, + instruction: &str) { + if let Some(index) = function_stack.iter().position(|s| s == function_name) { + let truncated_stack = &function_stack[0..=index]; + let count = filtered_stack_counts.entry(truncated_stack.to_vec()).or_insert(0); + *count += get_cycle_count(instruction).unwrap(); } } @@ -148,12 +187,13 @@ fn build_goblin_lookups( fn increment_stack_counts(instruction_counts: &mut HashMap, function_stack: &[String], filtered_stack_counts: &mut HashMap, usize>, - function_name: &Option) { + function_name: &Option, + instruction: &str) { for f in function_stack { - *instruction_counts.entry(f.clone()).or_insert(0) += 1; + *instruction_counts.entry(f.clone()).or_insert(0) += get_cycle_count(instruction).unwrap(); } if let Some(f) = function_name { - focused_stack_counts(function_stack, filtered_stack_counts, &f) + focused_stack_counts(function_stack, filtered_stack_counts, &f, instruction) } } @@ -168,6 +208,7 @@ fn main() -> std::io::Result<()> { let no_raw_counts = args.no_raw_counts; let strip_hashes = args.strip_hashes; let function_name = args.function_name; + let exclude_view = args.exclude_view; let mut start_lookup = HashMap::new(); let mut end_lookup = HashMap::new(); @@ -200,7 +241,9 @@ fn main() -> std::io::Result<()> { if c % &update_interval == 0 { pb.inc(update_interval as u64); } - let pc = line.parse().unwrap(); + let mut parts = line.split("\t"); + let pc = parts.next().unwrap_or_default().parse().unwrap(); + let instruction = parts.next().unwrap_or_default(); // Raw counts without considering the callgraph at all // we're just checking if the PC belongs to a function @@ -217,9 +260,9 @@ fn main() -> std::io::Result<()> { } }) { let (_, _, fname) = &function_ranges[index]; - *counts_without_callgraph.entry(fname.clone()).or_insert(0) += 1; + *counts_without_callgraph.entry(fname.clone()).or_insert(0) += get_cycle_count(instruction).unwrap(); } else { - *counts_without_callgraph.entry("anonymous".to_string()).or_insert(0) += 1; + *counts_without_callgraph.entry("anonymous".to_string()).or_insert(0) += get_cycle_count(instruction).unwrap(); } // The next section considers the callstack @@ -228,13 +271,13 @@ fn main() -> std::io::Result<()> { // we are still in the current function if pc > current_function_range.0 && pc <= current_function_range.1 { - increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name,instruction); continue; } // jump to a new function (or the same one) if let Some(f) = start_lookup.get(&pc) { - increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name,instruction); // jump to a new function (not recursive) if !function_stack.contains(&f) { function_stack.push(f.clone()); @@ -261,13 +304,13 @@ fn main() -> std::io::Result<()> { if unwind_found { function_stack.truncate(unwind_point + 1); - increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name,instruction); continue; } // if no unwind point has been found, that means we jumped to some random location // so we'll just increment the counts for everything in the stack - increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name); + increment_stack_counts(&mut instruction_counts, &function_stack, &mut filtered_stack_counts, &function_name,instruction); } } @@ -283,7 +326,7 @@ fn main() -> std::io::Result<()> { println!("\n\nTotal instructions in trace: {}", total_lines); if !no_stack_counts { println!("\n\n Instruction counts considering call graph"); - print_intruction_counts("Function Name", raw_counts, top_n, strip_hashes); + print_intruction_counts("Function Name", raw_counts, top_n, strip_hashes,Some(&exclude_view)); } let mut raw_counts: Vec<(String, usize)> = counts_without_callgraph @@ -293,7 +336,7 @@ fn main() -> std::io::Result<()> { raw_counts.sort_by(|a, b| b.1.cmp(&a.1)); if !no_raw_counts { println!("\n\n Instruction counts ignoring call graph"); - print_intruction_counts("Function Name",raw_counts, top_n, strip_hashes); + print_intruction_counts("Function Name",raw_counts, top_n, strip_hashes,Some(&exclude_view)); } let mut raw_counts: Vec<(String, usize)> = filtered_stack_counts @@ -316,7 +359,7 @@ fn main() -> std::io::Result<()> { raw_counts.sort_by(|a, b| b.1.cmp(&a.1)); if let Some(f) = function_name { println!("\n\n Stack patterns for function '{f}' "); - print_intruction_counts("Function Stack",raw_counts, top_n, strip_hashes); + print_intruction_counts("Function Stack",raw_counts, top_n, strip_hashes,None); } Ok(()) } From 1796af2d637cf657e3898faedcd973689211a558 Mon Sep 17 00:00:00 2001 From: dubbelosix Date: Tue, 29 Aug 2023 02:10:47 +0530 Subject: [PATCH 4/4] minor changes --- examples/demo-rollup/rollup_config.toml | 2 +- utils/zk-cycle-utils/tracer/src/main.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/demo-rollup/rollup_config.toml b/examples/demo-rollup/rollup_config.toml index ea8a1a300..1aaf8160f 100644 --- a/examples/demo-rollup/rollup_config.toml +++ b/examples/demo-rollup/rollup_config.toml @@ -1,6 +1,6 @@ [da] # The JWT used to authenticate with the celestia light client. Instructions for generating this token can be found in the README -celestia_rpc_auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJwdWJsaWMiLCJyZWFkIiwid3JpdGUiLCJhZG1pbiJdfQ.MhcEa3-fyoZvrf5bJ-sqUnrJi1cHhfKBq0W4lGT-oso" +celestia_rpc_auth_token = "MY.SECRET.TOKEN" # The address of the *trusted* Celestia light client to interact with celestia_rpc_address = "http://127.0.0.1:26658" # The largest response the rollup will accept from the Celestia node. Defaults to 100 MB diff --git a/utils/zk-cycle-utils/tracer/src/main.rs b/utils/zk-cycle-utils/tracer/src/main.rs index 8d039aafc..2f6e5dfd5 100644 --- a/utils/zk-cycle-utils/tracer/src/main.rs +++ b/utils/zk-cycle-utils/tracer/src/main.rs @@ -55,6 +55,8 @@ fn strip_hash(name_with_hash: &str) -> String { } fn get_cycle_count(insn: &str) -> Result { + // The opcodes and their cycle counts are taken from + // https://github.com/risc0/risc0/blob/main/risc0/zkvm/src/host/server/opcode.rs match insn { "LB" | "LH" | "LW" | "LBU" | "LHU" | "ADDI" | "SLLI" | "SLTI" | "SLTIU" | "AUIPC" | "SB" | "SH" | "SW" | "ADD" | "SUB" | "SLL" | "SLT" | "SLTU" |