зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1776898: Add additional filtering capabilities to dmd.py r=mccr8
Extend dmd.py's filtering capabilities by allowing both multiple filters and negated filters. Differential Revision: https://phabricator.services.mozilla.com/D150481
This commit is contained in:
Родитель
bc512e24a6
Коммит
fc7c4cd2b1
|
@ -21,6 +21,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from bisect import bisect_right
|
from bisect import bisect_right
|
||||||
from functools import cmp_to_key
|
from functools import cmp_to_key
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
# The DMD output version this script handles.
|
# The DMD output version this script handles.
|
||||||
outputVersion = 5
|
outputVersion = 5
|
||||||
|
@ -234,8 +235,12 @@ variable is used to find breakpad symbols for stack fixing.
|
||||||
)
|
)
|
||||||
|
|
||||||
p.add_argument(
|
p.add_argument(
|
||||||
"--allocation-filter",
|
"--filter",
|
||||||
help="Only print entries that have a stack that matches the filter",
|
default=[],
|
||||||
|
action="append",
|
||||||
|
help="Only print entries that have a stack that matches the filter. "
|
||||||
|
"A filter may be negated by prefixing it with `!`. "
|
||||||
|
"If multiple filters are specified, all of them must match.",
|
||||||
)
|
)
|
||||||
|
|
||||||
p.add_argument("input_file", help="a file produced by DMD")
|
p.add_argument("input_file", help="a file produced by DMD")
|
||||||
|
@ -622,15 +627,23 @@ def printDigest(args, digest):
|
||||||
kindUsableSize = 0
|
kindUsableSize = 0
|
||||||
maxRecord = 1000
|
maxRecord = 1000
|
||||||
|
|
||||||
if args.allocation_filter:
|
def is_match(rec: Record, key: str):
|
||||||
sortedRecords = list(
|
return any(key in desc for desc in rec.allocatedAtDesc)
|
||||||
filter(
|
|
||||||
lambda x: any(
|
for arg in args.filter:
|
||||||
map(lambda y: args.allocation_filter in y, x.allocatedAtDesc)
|
key: str
|
||||||
),
|
cond: Callable[[Record], bool]
|
||||||
sortedRecords,
|
if arg.startswith("\\"):
|
||||||
)
|
# just in case you really need to start a filter with '!' (or '\')
|
||||||
)
|
key = arg[1:]
|
||||||
|
cond = is_match
|
||||||
|
elif arg.startswith("!"):
|
||||||
|
key = arg[1:]
|
||||||
|
cond = lambda rec, key: not is_match(rec, key) # noqa: E731
|
||||||
|
else:
|
||||||
|
key = arg
|
||||||
|
cond = is_match
|
||||||
|
sortedRecords = [rec for rec in sortedRecords if cond(rec, key)]
|
||||||
|
|
||||||
# First iteration: get totals, etc.
|
# First iteration: get totals, etc.
|
||||||
for record in sortedRecords:
|
for record in sortedRecords:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче