Skip to content

Commit

Permalink
lazy diam calc
Browse files Browse the repository at this point in the history
  • Loading branch information
hkctkuy committed Dec 7, 2023
1 parent a06ec4d commit 89300a7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
13 changes: 3 additions & 10 deletions casr/src/bin/casr-cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,7 @@ fn update_clusters(
let casreps = util::get_reports(cluster)?;
let (_, stacktraces, crashlines, _) = util::reports_from_dirs(casreps, jobs);
// Fill cluster info structures
let diam = diam(&stacktraces);
clusters.push(Cluster {
number: i,
stacktraces,
diam,
});
clusters.push(Cluster::new(i, stacktraces));
if dedup {
for crashline in crashlines {
// NOTE: Clusters enumerate from 1, not 0
Expand All @@ -396,8 +391,7 @@ fn update_clusters(
let mut outers: Vec<(usize, f64)> = Vec::new();
// Checker if casrep is duplicate of someone else
let mut dup = false;
for cluster in &clusters {
// TODO: Add strategy options
for cluster in &mut clusters {
let relation = relation(
stacktrace,
cluster,
Expand Down Expand Up @@ -454,8 +448,7 @@ fn update_clusters(

// Update cluster
let i = clusters.iter().position(|a| a.number == number).unwrap();
clusters[i].stacktraces.push(stacktrace.to_vec());
clusters[i].diam = diam(&clusters[i].stacktraces);
clusters[i].push(stacktrace.to_vec());
}

// Handle deviant casreps
Expand Down
2 changes: 1 addition & 1 deletion casr/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub fn get_atheris_lib() -> Result<String> {
Ok(format!("{out}/asan_with_fuzzer.so"))
}

/// Create output, timeout and oOLDdirectories
/// Create output, timeout and oom directories
///
/// # Arguments
///
Expand Down
44 changes: 35 additions & 9 deletions libcasr/src/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,43 @@ pub enum AccumStrategy {
Dist,
}

// TODO: lazy diam
// TODO: encapsulation
/// Structure provides an interface for leverages with CASR report clusters
#[derive(Clone, Debug)]
pub struct Cluster {
/// Cluster number
pub number: usize,
/// Cluster report stacktraces
pub stacktraces: Vec<Stacktrace>,
stacktraces: Vec<Stacktrace>,
/// Cluster diameter
pub diam: f64,
diam: Option<f64>,
}

impl Cluster {
/// Create new `Cluster`
pub fn new(number: usize, stacktraces: Vec<Stacktrace>) -> Self {
Cluster {
number,
stacktraces,
diam: None,
}
}
/// Get CASR report stactraces
pub fn stacktraces(&self) -> Vec<Stacktrace> {
self.stacktraces.clone()
}
/// Add CASR report stacktrace to cluster
pub fn push(&mut self, stacktrace: Stacktrace) {
self.stacktraces.push(stacktrace);
self.diam = None;
}
/// Get cluster diameter
pub fn diam(&mut self) -> f64 {
if self.diam.is_none() {
diam(&self.stacktraces)
} else {
self.diam.unwrap()
}
}
}

/// This macro updates variables used to remove trusted functions from stack trace
Expand Down Expand Up @@ -339,7 +365,7 @@ pub fn dedup_crashlines(crashlines: &[String], clusters: &mut [usize]) -> usize
/// # Return value
///
/// Value of diameter
pub fn diam(stacktraces: &[Stacktrace]) -> f64 {
fn diam(stacktraces: &[Stacktrace]) -> f64 {
let mut diam = 0f64;
let len = stacktraces.len();
for i in 0..len {
Expand Down Expand Up @@ -370,15 +396,15 @@ pub fn diam(stacktraces: &[Stacktrace]) -> f64 {
/// `Relation` enum with measure according specified strategy
pub fn relation(
new: &Stacktrace,
cluster: &Cluster,
cluster: &mut Cluster,
inner_strategy: AccumStrategy,
outer_strategy: AccumStrategy,
) -> Relation {
let diam = cluster.diam;
let diam = cluster.diam();
let mut min = MAX;
let mut max = 0f64;
for stacktrace in &cluster.stacktraces {
let dist = 1.0 - similarity(new, stacktrace);
for stacktrace in cluster.stacktraces() {
let dist = 1.0 - similarity(new, &stacktrace);
if dist == 0.0 {
return Relation::Dup;
} else if dist > THRESHOLD {
Expand Down

0 comments on commit 89300a7

Please sign in to comment.