GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 053da92c authored by Karsten Loesing's avatar Karsten Loesing

Also accept a directory in `onionperf filter -i`.

And clarify that we're leaving statistics unchanged as part of the
filtering.
parent d9f8b8fe
# Changes in version 0.7 - 2020-??-??
- Add a new `onionperf filter` mode that takes an OnionPerf analysis
results file as input, applies filters, and produces a new
OnionPerf analysis results file as output.
results file or directory as input, applies filters, and produces
new OnionPerf analysis results file(s) as output.
# Changes in version 0.6 - 2020-08-08
......
......@@ -15,9 +15,6 @@ class Filtering(object):
self.fingerprints_to_exclude = None
self.fingerprint_pattern = re.compile("\$?([0-9a-fA-F]{40})")
def read_input(self, path):
self.analysis = OPAnalysis.load(filename=path)
def include_fingerprints(self, path):
self.fingerprints_to_include = []
with open(path, 'rt') as f:
......@@ -36,7 +33,8 @@ class Filtering(object):
fingerprint = fingerprint_match.group(1).upper()
self.fingerprints_to_exclude.append(fingerprint)
def apply_filters(self):
def apply_filters(self, input_path, output_dir, output_file):
self.analysis = OPAnalysis.load(filename=input_path)
if self.fingerprints_to_include is None and self.fingerprints_to_exclude is None:
return
for source in self.analysis.get_nodes():
......@@ -94,7 +92,5 @@ class Filtering(object):
retained_tgen_transfers[transfer_id] = transfer_data
self.analysis.set_tgen_streams(source, retained_tgen_streams)
self.analysis.set_tgen_transfers(source, retained_tgen_transfers)
def write_output(self, path):
self.analysis.save(filename=path)
self.analysis.save(filename=output_file, output_prefix=output_dir)
......@@ -76,8 +76,11 @@ Analyze Tor and TGen output
"""
DESC_FILTER = """
Takes an OnionPerf analysis results file as input, applies filters,
and produces a new OnionPerf analysis results file as output.
Takes an OnionPerf analysis results file or directory as input, applies filters,
and produces new OnionPerf analysis results file(s) as output.
This subcommand only filters measurements in `data/[source]/tgen/transfers`
and `data/[source]/tgen/streams`, but leaves any summaries unchanged.
"""
HELP_FILTER = """
Filter OnionPerf analysis results
......@@ -295,7 +298,8 @@ files generated by this script will be written""",
filter_parser.set_defaults(func=filter, formatter_class=my_formatter_class)
filter_parser.add_argument('-i', '--input',
help="""read the OnionPerf analysis results at PATH as input""",
help="""a file or directory PATH from which OnionPerf analysis results
files are read""",
metavar="PATH", required="True",
action="store", dest="input")
......@@ -314,8 +318,8 @@ files generated by this script will be written""",
default=None)
filter_parser.add_argument('-o', '--output',
help="""write the filtered output OnionPerf analysis results file to
PATH""",
help="""a file or directory PATH where filtered output OnionPerf
analysis results files are written""",
metavar="PATH", required="True",
action="store", dest="output")
......@@ -439,17 +443,26 @@ def analyze(args):
def filter(args):
from onionperf.filtering import Filtering
p = os.path.abspath(os.path.expanduser(args.input))
if not os.path.exists(p):
raise argparse.ArgumentTypeError("path '%s' does not exist" % args.input)
input_path = os.path.abspath(os.path.expanduser(args.input))
if not os.path.exists(input_path):
raise argparse.ArgumentTypeError("input path '%s' does not exist" % args.input)
output_path = os.path.abspath(os.path.expanduser(args.output))
if os.path.exists(output_path):
raise argparse.ArgumentTypeError("output path '%s' already exists" % args.output)
filtering = Filtering()
filtering.read_input(args.input)
if args.include_fingerprints is not None:
filtering.include_fingerprints(args.include_fingerprints)
if args.exclude_fingerprints is not None:
filtering.exclude_fingerprints(args.exclude_fingerprints)
filtering.apply_filters()
filtering.write_output(args.output)
if os.path.isfile(input_path):
output_dir, output_file = os.path.split(output_path)
filtering.apply_filters(input_path=input_path, output_dir=output_dir, output_file=output_file)
else:
for dirpath, dirnames, filenames in os.walk(input_path):
for filename in filenames:
input_file = os.path.join(dirpath, filename)
output_dir = os.path.join(output_path, os.path.relpath(dirpath, input_path))
filtering.apply_filters(input_path=input_file, output_dir=output_dir, output_file=filename)
def visualize(args):
from onionperf.visualization import TGenVisualization
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment