diff options
| author | Karsten Loesing <karsten.loesing@gmx.net> | 2020-05-30 15:10:37 +0200 |
|---|---|---|
| committer | Karsten Loesing <karsten.loesing@gmx.net> | 2020-05-30 15:10:37 +0200 |
| commit | 251f4576e97287b00a1136c08ef3fde5de92c901 (patch) | |
| tree | 472d83e0ec45689864f3818130fb630fdf88126f | |
| parent | faae535c70608b9726cf60c9407b7f802c6d3ca0 (diff) | |
squash! Add --date-prefix command line switch.
- Accept a DATE as date prefix rather than assuming the current UTC date.
- Use date prefix when writing the analysis file at midnight.
| -rw-r--r-- | onionperf/analysis.py | 10 | ||||
| -rw-r--r-- | onionperf/measurement.py | 4 | ||||
| -rwxr-xr-x | onionperf/onionperf | 15 |
3 files changed, 13 insertions, 16 deletions
diff --git a/onionperf/analysis.py b/onionperf/analysis.py index 59d8217..23104a1 100644 --- a/onionperf/analysis.py +++ b/onionperf/analysis.py @@ -96,12 +96,14 @@ 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" - else: + if date_prefix is not None: + filename = "{}.onionperf.analysis.json.xz".format(util.date_to_string(date_prefix)) + elif self.date_filter is not None: filename = "{}.onionperf.analysis.json.xz".format(util.date_to_string(self.date_filter)) + else: + filename = "onionperf.analysis.json.xz" filepath = os.path.abspath(os.path.expanduser("{0}/{1}".format(output_prefix, filename))) if not os.path.exists(output_prefix): diff --git a/onionperf/measurement.py b/onionperf/measurement.py index 3da7445..9a38216 100644 --- a/onionperf/measurement.py +++ b/onionperf/measurement.py @@ -146,10 +146,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) diff --git a/onionperf/onionperf b/onionperf/onionperf index bde37ba..49e1cb4 100755 --- a/onionperf/onionperf +++ b/onionperf/onionperf @@ -269,9 +269,10 @@ files generated by this script will be written""", default=None) date_group.add_argument('-x', '--date-prefix', - help="""add a date prefix of the form YYYY-MM-DD- to the output file""", - action="store_true", dest="date_prefix", - default=False) + help="""a DATE string in the form YYYY-MM-YY 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""", @@ -371,13 +372,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) - - filename = None - if args.date_prefix: - n = datetime.datetime.utcnow() - filename = "{}-onionperf.analysis.json.xz".format(n.strftime("%Y-%m-%d")) - - analysis.save(filename=filename, 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 |
