[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Add support for test_start_time and test_runtime keys in report.
commit 2bb6595baa74e90bc4a2927be1a266d3632fda90
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Fri Oct 17 11:05:16 2014 +0200
Add support for test_start_time and test_runtime keys in report.
---
ooni/nettest.py | 9 ++++++++-
ooni/otime.py | 7 ++++++-
ooni/reporter.py | 19 -------------------
ooni/tasks.py | 12 ++++++++++--
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 3db82d7..4a07b7d 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -8,6 +8,7 @@ from twisted.internet import defer
from twisted.trial.runner import filenameToModule
from twisted.python import usage, reflect
+from ooni import otime
from ooni.tasks import Measurement
from ooni.utils import log, checkForRoot, sanitize_options
from ooni.settings import config
@@ -201,7 +202,7 @@ class NetTestLoader(object):
input_file_hashes.append(input_file['hash'])
options = sanitize_options(self.options)
- test_details = {'start_time': time.time(),
+ test_details = {'start_time': otime.epochToUTC(time.time()),
'probe_asn': config.probe_ip.geodata['asn'],
'probe_cc': config.probe_ip.geodata['countrycode'],
'probe_ip': config.probe_ip.geodata['ip'],
@@ -527,6 +528,12 @@ class NetTest(object):
if self.report:
post = defer.DeferredList(measurements)
+ @post.addCallback
+ def set_runtime(results):
+ runtime = time.time() - test_instance._start_time
+ test_instance.report['test_runtime'] = runtime
+ return results
+
# Call the postProcessor, which must return a single report
# or a deferred
post.addCallback(test_instance.postProcessor)
diff --git a/ooni/otime.py b/ooni/otime.py
index 51124db..60725c3 100644
--- a/ooni/otime.py
+++ b/ooni/otime.py
@@ -65,5 +65,10 @@ def timestamp(t=None):
ISO8601 = "%Y-%m-%dT%H%M%SZ"
return t.strftime(ISO8601)
+
def epochToTimestamp(seconds):
- return timestamp(datetime.utcfromtimestamp(seconds))
+ return timestamp(datetime.fromtimestamp(seconds))
+
+
+def epochToUTC(seconds):
+ return float(datetime.utcfromtimestamp(seconds).strftime("%s"))
diff --git a/ooni/reporter.py b/ooni/reporter.py
index e0e92c6..06f866e 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -142,25 +142,6 @@ class OReporter(object):
def finish(self):
pass
- def testDone(self, test, test_name):
- # XXX put this inside of Report.close
- # or perhaps put something like this inside of netTestDone
- log.msg("Finished running %s" % test_name)
- test_report = dict(test.report)
-
- if isinstance(test.input, Packet):
- test_input = createPacketReport(test.input)
- else:
- test_input = test.input
-
- test_report['input'] = test_input
- test_report['test_name'] = test_name
- test_report['test_started'] = test._start_time
- test_report['test_runtime'] = time.time() - test._start_time
-
- return defer.maybeDeferred(self.writeReportEntry, test_report)
-
-
class YAMLReporter(OReporter):
"""
diff --git a/ooni/tasks.py b/ooni/tasks.py
index 9d281ab..3f331a2 100644
--- a/ooni/tasks.py
+++ b/ooni/tasks.py
@@ -1,8 +1,10 @@
import time
+from twisted.internet import defer, reactor
+
from ooni import errors as e
from ooni.settings import config
-from twisted.internet import defer, reactor
+from ooni import otime
class BaseTask(object):
@@ -109,9 +111,15 @@ class Measurement(TaskWithTimeout):
self.testInstance = test_instance
self.testInstance.input = test_input
self.testInstance._setUp()
+ if not hasattr(self.testInstance, '_start_time'):
+ self.testInstance._start_time = time.time()
+
if 'input' not in self.testInstance.report.keys():
self.testInstance.report['input'] = test_input
- self.testInstance._start_time = time.time()
+ if 'test_start_time' not in self.testInstance.report.keys():
+ start_time = otime.epochToUTC(self.testInstance._start_time)
+ self.testInstance.report['test_start_time'] = start_time
+
self.testInstance.setUp()
self.netTestMethod = getattr(self.testInstance, test_method)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits