Skip to content

Commit

Permalink
Add library filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
unpluggedcoder committed Dec 28, 2021
1 parent a18267b commit 7f77193
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
57 changes: 53 additions & 4 deletions server-core/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ pub fn prepare_filter(

if filter.function_regex.is_some()
|| filter.source_regex.is_some()
|| filter.library_regex.is_some()
|| filter.negative_function_regex.is_some()
|| filter.negative_source_regex.is_some()
|| filter.negative_library_regex.is_some()
{
let function_regex = if let Some(ref pattern) = filter.function_regex {
Some(
Expand All @@ -108,6 +110,15 @@ pub fn prepare_filter(
None
};

let library_regex = if let Some(ref pattern) = filter.library_regex {
Some(
Regex::new(pattern)
.map_err(|err| PrepareFilterError::InvalidRegex("library_regex", err))?,
)
} else {
None
};

let negative_function_regex =
if let Some(ref pattern) = filter.negative_function_regex {
Some(Regex::new(pattern).map_err(|err| {
Expand All @@ -126,14 +137,25 @@ pub fn prepare_filter(
None
};

let negative_library_regex =
if let Some(ref pattern) = filter.negative_library_regex {
Some(Regex::new(pattern).map_err(|err| {
PrepareFilterError::InvalidRegex("negative_library_regex", err)
})?)
} else {
None
};

let mut matched_backtraces = HashSet::new();
let mut positive_cache = HashMap::new();
let mut negative_cache = HashMap::new();
for (backtrace_id, backtrace) in data.all_backtraces() {
let mut positive_matched = function_regex.is_none() && source_regex.is_none();
let mut positive_matched =
function_regex.is_none() && source_regex.is_none() && library_regex.is_none();
let mut negative_matched = false;
let check_negative =
negative_function_regex.is_some() || negative_source_regex.is_some();
let check_negative = negative_function_regex.is_some()
|| negative_source_regex.is_some()
|| negative_library_regex.is_some();

for (frame_id, frame) in backtrace {
let check_positive = if positive_matched {
Expand Down Expand Up @@ -165,6 +187,13 @@ pub fn prepare_filter(
.map(|id| data.interner().resolve(id).unwrap())
}

let mut library = None;
if (check_positive && library_regex.is_some()) || negative_library_regex.is_some() {
library = frame
.library()
.map(|id| data.interner().resolve(id).unwrap())
}

if check_positive {
let matched_function = if let Some(regex) = function_regex.as_ref() {
if let Some(ref function) = function {
Expand All @@ -186,7 +215,17 @@ pub fn prepare_filter(
true
};

positive_matched = matched_function && matched_source;
let matched_library = if let Some(regex) = library_regex.as_ref() {
if let Some(ref library) = library {
regex.is_match(library)
} else {
false
}
} else {
true
};

positive_matched = matched_function && matched_source && matched_library;
positive_cache.insert(frame_id, positive_matched);
}

Expand Down Expand Up @@ -222,6 +261,16 @@ pub fn prepare_filter(
}
}

if let Some(regex) = negative_library_regex.as_ref() {
if let Some(ref library) = library {
if regex.is_match(library) {
negative_cache.insert(frame_id, true);
negative_matched = true;
break;
}
}
}

negative_cache.insert(frame_id, false);
}
}
Expand Down
2 changes: 2 additions & 0 deletions server-core/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,10 @@ pub struct AllocFilter {
pub arena: Option<ArenaFilter>,
pub function_regex: Option<String>,
pub source_regex: Option<String>,
pub library_regex: Option<String>,
pub negative_function_regex: Option<String>,
pub negative_source_regex: Option<String>,
pub negative_library_regex: Option<String>,
pub marker: Option<u32>,
pub group_interval_min: Option<TimestampFilter<Interval>>,
pub group_interval_max: Option<TimestampFilter<Interval>>,
Expand Down
14 changes: 14 additions & 0 deletions webui/src/PageDataAllocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ const FIELDS = {
label: "Negative source file regex",
badge: value => "Sources NOT matching /" + value + "/"
},
library_regex: {
...REGEX_FIELD,
label: "Library regex",
badge: value => "Libraries matching /" + value + "/"
},
negative_library_regex: {
...REGEX_FIELD,
label: "Negative library regex",
badge: value => "Libraries NOT matching /" + value + "/"
},
backtraces: {
label: "Backtrace",
badge: value => "Matching backtrace with ID " + value
Expand Down Expand Up @@ -436,6 +446,10 @@ class FilterEditor extends React.Component {
<div className="px-2" />
{this.field("negative_source_regex")}
</div>
<div className="px-2" />
{this.field("library_regex")}
<div className="px-2" />
{this.field("negative_library_regex")}
<div className="d-flex flex-row">
{this.field("backtrace_depth_min")}
<div className="px-2" />
Expand Down

0 comments on commit 7f77193

Please sign in to comment.