Commit 0025fef3 authored by Philipp Winter's avatar Philipp Winter Committed by Karsten Loesing
Browse files

Add --date-prefix command line switch.

The switch tells OnionPerf to prepend yesterday's date to the analysis
output file.  This new switch is mutually exclusive with --date-filter.

This fixes <https://bugs.torproject.org/29369>.
parent 7b5e65dc
......@@ -96,12 +96,15 @@ class Analysis(object):
else:
self.json_db['data'][nickname] = analysis.json_db['data'][nickname]
def save(self, filename=None, output_prefix=os.getcwd(), do_compress=True):
def save(self, filename=None, output_prefix=os.getcwd(), do_compress=True, date_prefix=None):
if filename is None:
if self.date_filter is None:
filename = "onionperf.analysis.json.xz"
base_filename = "onionperf.analysis.json.xz"
if date_prefix is not None:
filename = "{0}.{1}".format(util.date_to_string(date_prefix), base_filename)
elif self.date_filter is not None:
filename = "{0}.{1}".format(util.date_to_string(self.date_filter), base_filename)
else:
filename = "{}.onionperf.analysis.json.xz".format(util.date_to_string(self.date_filter))
filename = base_filename
filepath = os.path.abspath(os.path.expanduser("{0}/{1}".format(output_prefix, filename)))
if not os.path.exists(output_prefix):
......
......@@ -157,10 +157,10 @@ def logrotate_thread_task(writables, tgen_writable, torctl_writable, docroot, ni
anal.add_torctl_file(torctl_writable.rotate_file(filename_datetime=next_midnight))
# run the analysis, i.e. parse the files
anal.analyze(do_simple=False, date_filter=next_midnight.date())
anal.analyze(do_simple=False)
# save the results in onionperf json format in the www docroot
anal.save(output_prefix=docroot, do_compress=True)
anal.save(output_prefix=docroot, do_compress=True, date_prefix=next_midnight.date())
# update the xml index in docroot
generate_docroot_index(docroot)
......
......@@ -266,12 +266,19 @@ files generated by this script will be written""",
action="store", dest="nickname",
default=None)
analyze_parser.add_argument('-d', '--date-filter',
date_group = analyze_parser.add_mutually_exclusive_group()
date_group.add_argument('-d', '--date-filter',
help="""a DATE string in the form YYYY-MM-DD, all log messages that did not occur on this date will be filtered out of the analysis""",
metavar="DATE", type=type_str_date_in,
action="store", dest="date_filter",
default=None)
date_group.add_argument('-x', '--date-prefix',
help="""a DATE string in the form YYYY-MM-DD to add as prefix to the output file""",
metavar="DATE", type=type_str_date_in,
action="store", dest="date_prefix",
default=None)
analyze_parser.add_argument('-s', '--do-simple-parse',
help="""parse and export only summary statistics rather than full transfer/circuit/stream data""",
action="store_true", dest="do_simple",
......@@ -381,7 +388,7 @@ def analyze(args):
if args.torctl_logpath is not None:
analysis.add_torctl_file(args.torctl_logpath)
analysis.analyze(args.do_simple, date_filter=args.date_filter)
analysis.save(output_prefix=args.prefix)
analysis.save(output_prefix=args.prefix, date_prefix=args.date_prefix)
elif args.tgen_logpath is not None and os.path.isdir(args.tgen_logpath) and args.torctl_logpath is not None and os.path.isdir(args.torctl_logpath):
from onionperf import reprocessing
......
Supports Markdown
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