[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionperf/master] Add --date-prefix command line switch.



commit 0025fef345803ad8ea0695181622e66530b2278d
Author: Philipp Winter <phw@xxxxxxxxx>
Date:   Fri May 29 16:00:24 2020 -0700

    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>.
---
 onionperf/analysis.py    | 11 +++++++----
 onionperf/measurement.py |  4 ++--
 onionperf/onionperf      | 11 +++++++++--
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/onionperf/analysis.py b/onionperf/analysis.py
index 59d8217..20ca354 100644
--- a/onionperf/analysis.py
+++ b/onionperf/analysis.py
@@ -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):
diff --git a/onionperf/measurement.py b/onionperf/measurement.py
index 308305c..4a58bc4 100644
--- a/onionperf/measurement.py
+++ b/onionperf/measurement.py
@@ -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)
diff --git a/onionperf/onionperf b/onionperf/onionperf
index d811e7b..a7d32f6 100755
--- a/onionperf/onionperf
+++ b/onionperf/onionperf
@@ -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

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits