Skip to content

Commit

Permalink
feat: add coz profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
alxiong committed Jun 15, 2023
1 parent c7367b3 commit 5d9ab4b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/plasma-umass/coz/tree/master/rust>
[profile.release]
debug = 1
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
18 changes: 18 additions & 0 deletions primitives/src/reed_solomon_code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
use coz;

/// Erasure-encode `data` into `data.len() + parity_size` shares.
///
Expand Down Expand Up @@ -97,6 +99,9 @@ where
.clone()
.map(|share| *share.borrow().0.borrow())
.collect::<Vec<_>>();

#[cfg(all(debug_assertions, target_os = "linux"))]
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();
Expand All @@ -107,6 +112,12 @@ where
}
l[0] = -x[i - 1] * l[0];
}

#[cfg(all(debug_assertions, target_os = "linux"))]
{
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| {
Expand All @@ -126,6 +137,11 @@ where
Ok(ret)
})
.collect::<Result<Vec<_>, _>>()?;
#[cfg(all(debug_assertions, target_os = "linux"))]
{
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() {
Expand All @@ -140,6 +156,8 @@ where
f[j] += weight * li[j];
}
}
#[cfg(all(debug_assertions, target_os = "linux"))]
coz::end!("computing f(X)");
Ok(f)
}

Expand Down

0 comments on commit 5d9ab4b

Please sign in to comment.