summaryrefslogtreecommitdiff
path: root/scripts/profiling/sync
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/profiling/sync')
-rwxr-xr-x[-rw-r--r--]scripts/profiling/sync/profile-sync.py84
-rwxr-xr-xscripts/profiling/sync/run_plop_server.sh2
2 files changed, 74 insertions, 12 deletions
diff --git a/scripts/profiling/sync/profile-sync.py b/scripts/profiling/sync/profile-sync.py
index fdd5b5a6..6c8d249e 100644..100755
--- a/scripts/profiling/sync/profile-sync.py
+++ b/scripts/profiling/sync/profile-sync.py
@@ -1,13 +1,16 @@
-#!/usr/bin/python
-
+#!/usr/bin/env python
import argparse
+import commands
+import getpass
import logging
+import tempfile
+from datetime import datetime
+from twisted.internet import reactor
from util import StatsLogger, ValidateUserHandle
-from client_side_db import get_soledad_instance
-#from plot import plot
+from client_side_db import _get_soledad_instance, _get_soledad_info
# create a logger
@@ -15,6 +18,15 @@ logger = logging.getLogger(__name__)
LOG_FORMAT = '%(asctime)s %(message)s'
logging.basicConfig(format=LOG_FORMAT, level=logging.INFO)
+GITVER = commands.getoutput('git describe')
+
+
+def get_and_run_plop_collector():
+ from plop.collector import Collector
+ collector = Collector()
+ collector.start()
+ return collector
+
# main program
@@ -33,6 +45,16 @@ if __name__ == '__main__':
parser.add_argument(
'-l', dest='logfile', required=False, default='/tmp/profile.log',
help='the file to which write the log')
+ parser.add_argument(
+ '--no-stats', dest='do_stats', action='store_false',
+ help='skip system stats')
+ parser.add_argument(
+ '--plot', dest='do_plot', action='store_true',
+ help='do a graphical plot')
+ parser.add_argument(
+ '--plop', dest='do_plop', action='store_true',
+ help='run sync script under plop profiler')
+ parser.set_defaults(do_stats=True, do_plot=False, do_plop=False)
args = parser.parse_args()
# get the password
@@ -47,16 +69,54 @@ if __name__ == '__main__':
basedir = tempfile.mkdtemp()
logger.info('Using %s as base directory.' % basedir)
+ uuid, server_url, cert_file, token = \
+ _get_soledad_info(
+ args.username, args.provider, passphrase, basedir)
# get the soledad instance
- s = get_soledad_instance(
- args.username, args.provider, passphrase, basedir)
+ s = _get_soledad_instance(
+ uuid, passphrase, basedir, server_url, cert_file, token)
+
for i in xrange(10):
+ # XXX Profile this with more realistic payloads
s.create_doc({})
- sl = StatsLogger(
- "soledad-sync", args.logfile, procs=["python"], interval=0.001)
- sl.start()
- s.sync()
- sl.stop()
+ def start_sync():
+ if args.do_stats:
+ sl = StatsLogger(
+ "soledad-sync", args.logfile, procs=["python"], interval=0.001)
+ sl.start()
+ else:
+ sl = None
+
+ if args.do_plop:
+ plop_collector = get_and_run_plop_collector()
+ else:
+ plop_collector = None
+
+ t0 = datetime.now()
+ d = s.sync()
+ d.addCallback(onSyncDone, sl, t0, plop_collector)
+
+ def onSyncDone(sync_result, sl, t0, plop_collector):
+ print "GOT SYNC RESULT: ", sync_result
+ t1 = datetime.now()
+ if sl:
+ sl.stop()
+ if plop_collector:
+ from plop.collector import PlopFormatter
+ formatter = PlopFormatter()
+ plop_collector.stop()
+ # XXX mkdir profiles dir if not exist
+ with open('profiles/plop-sync-%s' % GITVER, 'w') as f:
+ f.write(formatter.format(plop_collector))
+
+ delta = (t1 - t0).total_seconds()
+ print "[+] Sync took %s seconds." % delta
+ reactor.stop()
+
+ if args.do_plot:
+ from plot import plot
+ plot(args.logfile)
- #plot(args.logfile)
+ reactor.callWhenRunning(start_sync)
+ reactor.run()
diff --git a/scripts/profiling/sync/run_plop_server.sh b/scripts/profiling/sync/run_plop_server.sh
new file mode 100755
index 00000000..7b905c3d
--- /dev/null
+++ b/scripts/profiling/sync/run_plop_server.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+python -m plop.viewer --datadir=profiles