Skip to content

Commit 8887de9

Browse files
author
unpluggedcoder
committed
Add library filter.
1 parent 80b2520 commit 8887de9

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

server-core/src/filter.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ pub fn prepare_filter(
8787

8888
if filter.function_regex.is_some()
8989
|| filter.source_regex.is_some()
90+
|| filter.library_regex.is_some()
9091
|| filter.negative_function_regex.is_some()
9192
|| filter.negative_source_regex.is_some()
93+
|| filter.negative_library_regex.is_some()
9294
{
9395
let function_regex = if let Some(ref pattern) = filter.function_regex {
9496
Some(
@@ -108,6 +110,15 @@ pub fn prepare_filter(
108110
None
109111
};
110112

113+
let library_regex = if let Some(ref pattern) = filter.library_regex {
114+
Some(
115+
Regex::new(pattern)
116+
.map_err(|err| PrepareFilterError::InvalidRegex("library_regex", err))?,
117+
)
118+
} else {
119+
None
120+
};
121+
111122
let negative_function_regex =
112123
if let Some(ref pattern) = filter.negative_function_regex {
113124
Some(Regex::new(pattern).map_err(|err| {
@@ -126,14 +137,25 @@ pub fn prepare_filter(
126137
None
127138
};
128139

140+
let negative_library_regex =
141+
if let Some(ref pattern) = filter.negative_library_regex {
142+
Some(Regex::new(pattern).map_err(|err| {
143+
PrepareFilterError::InvalidRegex("negative_library_regex", err)
144+
})?)
145+
} else {
146+
None
147+
};
148+
129149
let mut matched_backtraces = HashSet::new();
130150
let mut positive_cache = HashMap::new();
131151
let mut negative_cache = HashMap::new();
132152
for (backtrace_id, backtrace) in data.all_backtraces() {
133-
let mut positive_matched = function_regex.is_none() && source_regex.is_none();
153+
let mut positive_matched =
154+
function_regex.is_none() && source_regex.is_none() && library_regex.is_none();
134155
let mut negative_matched = false;
135-
let check_negative =
136-
negative_function_regex.is_some() || negative_source_regex.is_some();
156+
let check_negative = negative_function_regex.is_some()
157+
|| negative_source_regex.is_some()
158+
|| negative_library_regex.is_some();
137159

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

190+
let mut library = None;
191+
if (check_positive && library_regex.is_some()) || negative_library_regex.is_some() {
192+
library = frame
193+
.library()
194+
.map(|id| data.interner().resolve(id).unwrap())
195+
}
196+
168197
if check_positive {
169198
let matched_function = if let Some(regex) = function_regex.as_ref() {
170199
if let Some(ref function) = function {
@@ -186,7 +215,17 @@ pub fn prepare_filter(
186215
true
187216
};
188217

189-
positive_matched = matched_function && matched_source;
218+
let matched_library = if let Some(regex) = library_regex.as_ref() {
219+
if let Some(ref library) = library {
220+
regex.is_match(library)
221+
} else {
222+
false
223+
}
224+
} else {
225+
true
226+
};
227+
228+
positive_matched = matched_function && matched_source && matched_library;
190229
positive_cache.insert(frame_id, positive_matched);
191230
}
192231

@@ -222,6 +261,16 @@ pub fn prepare_filter(
222261
}
223262
}
224263

264+
if let Some(regex) = negative_library_regex.as_ref() {
265+
if let Some(ref library) = library {
266+
if regex.is_match(library) {
267+
negative_cache.insert(frame_id, true);
268+
negative_matched = true;
269+
break;
270+
}
271+
}
272+
}
273+
225274
negative_cache.insert(frame_id, false);
226275
}
227276
}

server-core/src/protocol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,10 @@ pub struct AllocFilter {
618618
pub arena: Option<ArenaFilter>,
619619
pub function_regex: Option<String>,
620620
pub source_regex: Option<String>,
621+
pub library_regex: Option<String>,
621622
pub negative_function_regex: Option<String>,
622623
pub negative_source_regex: Option<String>,
624+
pub negative_library_regex: Option<String>,
623625
pub marker: Option<u32>,
624626
pub group_interval_min: Option<TimestampFilter<Interval>>,
625627
pub group_interval_max: Option<TimestampFilter<Interval>>,

webui/src/PageDataAllocations.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ const FIELDS = {
260260
label: "Negative source file regex",
261261
badge: value => "Sources NOT matching /" + value + "/"
262262
},
263+
library_regex: {
264+
...REGEX_FIELD,
265+
label: "Library regex",
266+
badge: value => "Libraries matching /" + value + "/"
267+
},
268+
negative_library_regex: {
269+
...REGEX_FIELD,
270+
label: "Negative library regex",
271+
badge: value => "Libraries NOT matching /" + value + "/"
272+
},
263273
backtraces: {
264274
label: "Backtrace",
265275
badge: value => "Matching backtrace with ID " + value
@@ -436,6 +446,10 @@ class FilterEditor extends React.Component {
436446
<div className="px-2" />
437447
{this.field("negative_source_regex")}
438448
</div>
449+
<div className="px-2" />
450+
{this.field("library_regex")}
451+
<div className="px-2" />
452+
{this.field("negative_library_regex")}
439453
<div className="d-flex flex-row">
440454
{this.field("backtrace_depth_min")}
441455
<div className="px-2" />

0 commit comments

Comments
 (0)