Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hkctkuy committed Nov 3, 2023
1 parent 63e27c7 commit f25507a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
10 changes: 6 additions & 4 deletions casr/src/bin/casr-cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ fn make_clusters(inpath: &Path, outpath: Option<&Path>, jobs: usize, dedup: bool
if let Ok(trace) = report.filtered_stacktrace() {
traces.write().unwrap().push(trace);
filtered_casreps.write().unwrap().push(casreps[i].clone());
}
if dedup {
crashlines.write().unwrap().push(report.crashline);
if dedup {
crashlines.write().unwrap().push(report.crashline);
}
} else {
badreports.write().unwrap().push(casreps[i].clone());
}

Check warning on line 92 in casr/src/bin/casr-cluster.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cluster.rs#L90-L92

Added lines #L90 - L92 were not covered by tests
} else {
badreports.write().unwrap().push(casreps[i].clone());
Expand Down Expand Up @@ -127,7 +129,7 @@ fn make_clusters(inpath: &Path, outpath: Option<&Path>, jobs: usize, dedup: bool

// Get clusters with crashline deduplication
if dedup {
clusters = dedup_crashlines(&crashlines, clusters)?;
dedup_crashlines(&crashlines, &mut clusters);
}

for i in 0..clusters.len() {
Expand Down
7 changes: 3 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ Tool for clustering CASR reports
-V, --version
Print version

If you set `CASR_CLUSTER_UNIQUE_CRASHLINE` environment variable as "1"
casr-cluster will deduplicate reports by crashline for each cluster and won't if
you set any other value or do not set anything.

Report deduplication and clustering is based on stack trace comparison from
[gdb-command](https://github.com/anfedotoff/gdb-command). The idea is to run
deduplication first to remove equal reports, then run clustering on remaining
Expand Down Expand Up @@ -303,6 +299,9 @@ For the **--ignore <FILE>** option, file format should be as follows:
Headers may be in different order, one of them may be missing.
Frames that match these regular expressions will be not considered during analysis.

When `CASR_CLUSTER_UNIQUE_CRASHLINE` environment variable is set to 1, each
cluster will contain reports with unique crash lines.

## casr-cli

App provides text-based user interface to view CASR reports, prints joint statistics for
Expand Down
31 changes: 14 additions & 17 deletions libcasr/src/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub fn similarity(first: &Stacktrace, second: &Stacktrace) -> f64 {
///
/// # Return value
///
/// An vector of the same length as `stacktraces`.
/// A vector of the same length as `stacktraces`.
/// Vec\[i\] is false, if original stacktrace i is a duplicate of any element of `stacktraces`.
pub fn dedup_stacktraces(stacktraces: &[Stacktrace]) -> Vec<bool> {
let mut traces = HashSet::new();
Expand All @@ -194,7 +194,7 @@ pub fn dedup_stacktraces(stacktraces: &[Stacktrace]) -> Vec<bool> {
///
/// # Return value
///
/// An vector of the same length as `stacktraces`.
/// A vector of the same length as `stacktraces`.
/// Vec\[i\] is the flat cluster number to which original stack trace i belongs.
pub fn cluster_stacktraces(stacktraces: &[Stacktrace]) -> Result<Vec<usize>> {
// Writing distance matrix
Expand Down Expand Up @@ -250,37 +250,34 @@ pub fn cluster_stacktraces(stacktraces: &[Stacktrace]) -> Result<Vec<usize>> {
Ok(flat_clusters)
}

/// Perform crashline deduplication for each cluster
/// Perform crashline deduplication for each cluster:
/// Reset Vec\[i\] to 0 if asrep crashline is duplicate of some other.
///
/// # Arguments
///
/// * `crashlines` - slice of crashlines as String
///
/// * 'clusters' - An vector of the same length as `crashlines`.
/// * 'clusters' - A vector of the same length as `crashlines`.
/// Vec\[i\] is the flat cluster number to which original casrep i belongs.
///
/// # Return value
///
/// An vector of the same length as `clusters`.
/// Vec\[i\] is the flat cluster number to which original casrep i belongs,
/// if Vec\[i\] is 0, casrep crashline is duplicate of some other
pub fn dedup_crashlines(crashlines: &[String], clusters: Vec<usize>) -> Result<Vec<usize>> {
// Init cluster vec with crashline dedup
let mut dedup_clusters = vec![0; crashlines.len()];
pub fn dedup_crashlines(crashlines: &[String], clusters: &mut [usize]) {
// Count number of clusters
let cluster_num: usize = *clusters.iter().max().unwrap();
let cluster_num: usize = if !clusters.is_empty() {
*clusters.iter().max().unwrap()
} else {
return;

Check warning on line 267 in libcasr/src/stacktrace.rs

View check run for this annotation

Codecov / codecov/patch

libcasr/src/stacktrace.rs#L267

Added line #L267 was not covered by tests
};
// Init dedup crashline list for each cluster
let mut unique_crashlines: Vec<HashSet<String>> = vec![HashSet::new(); cluster_num];

// Dedup reports by crashlibe
// Dedup reports by crashline
for (i, crashline) in crashlines.iter().enumerate() {
// Leave report in the cluster if crashline is absent
if crashline.is_empty() || unique_crashlines[clusters[i] - 1].insert(crashline.to_string())
{
dedup_clusters[i] = clusters[i];
continue;
}
clusters[i] = 0;
}
Ok(dedup_clusters)
}

/// Stack trace filtering trait.
Expand Down

0 comments on commit f25507a

Please sign in to comment.