diff --git a/Cargo.toml b/Cargo.toml index b21d6bb22..dce3fdd5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,8 @@ rust-version = "1.64.0" homepage = "https://github.com/EspressoSystems/jellyfish" documentation = "https://jellyfish.docs.espressosys.com" repository = "https://github.com/EspressoSystems/jellyfish" + +# optional, for coz profiler. +# see +[profile.release] +debug = 1 diff --git a/flake.nix b/flake.nix index 2362483e4..713c15e73 100644 --- a/flake.nix +++ b/flake.nix @@ -86,7 +86,8 @@ clangStdenv llvm_15 ] ++ lib.optionals stdenv.isDarwin - [ darwin.apple_sdk.frameworks.Security ]; + [ darwin.apple_sdk.frameworks.Security ] + ++ lib.optionals stdenv.isLinux [ coz ]; shellHook = '' export RUST_BACKTRACE=full diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 6b51ddf51..355345381 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -28,6 +28,7 @@ chacha20poly1305 = { version = "0.10.1", default-features = false, features = [ "alloc", "rand_core", ] } +coz = { version = "0.1", optional = true } crypto_kx = { version = "=0.2.0-pre.0", features = ["serde"] } derivative = { version = "2", features = ["use_core"] } digest = { version = "0.10.1", default-features = false, features = ["alloc"] } @@ -98,7 +99,7 @@ std = [ "jf-utils/std", "jf-relation/std", ] -print-trace = ["ark-std/print-trace"] +profiling = ["ark-std/print-trace", "dep:coz"] parallel = [ "ark-ff/parallel", "ark-ec/parallel", diff --git a/primitives/src/reed_solomon_code/mod.rs b/primitives/src/reed_solomon_code/mod.rs index f19173ba5..692f7c54c 100644 --- a/primitives/src/reed_solomon_code/mod.rs +++ b/primitives/src/reed_solomon_code/mod.rs @@ -11,6 +11,8 @@ use ark_ff::{FftField, Field}; use ark_poly::{EvaluationDomain, Radix2EvaluationDomain}; use ark_std::{format, string::ToString, vec, vec::Vec}; use core::borrow::Borrow; +#[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] +use coz; /// Erasure-encode `data` into `data.len() + parity_size` shares. /// @@ -97,6 +99,9 @@ where .clone() .map(|share| *share.borrow().0.borrow()) .collect::>(); + + #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] + coz::begin!("computing l(X)"); // Calculating l(x) = \prod (x - x_i) let mut l = vec![F::zero(); data_size + 1]; l[0] = F::one(); @@ -107,6 +112,12 @@ where } l[0] = -x[i - 1] * l[0]; } + + #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] + { + coz::end!("computing l(X)"); + coz::begin!("computing barycentric weight w_i"); + } // Calculate the barycentric weight w_i let w = (0..data_size) .map(|i| { @@ -126,6 +137,11 @@ where Ok(ret) }) .collect::, _>>()?; + #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] + { + coz::end!("computing barycentric weight w_i"); + coz::begin!("computing f(X)"); + } // Calculate f(x) = \sum_i l_i(x) let mut f = vec![F::zero(); data_size]; // for i in 0..shares.len() { @@ -140,6 +156,8 @@ where f[j] += weight * li[j]; } } + #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] + coz::end!("computing f(X)"); Ok(f) }