From bd113c72a3a37c91806dd2cbf0cf8fd47949a2f4 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Sun, 1 May 2016 14:28:18 -0400 Subject: add profiling options --- Makefile | 8 ++++++++ server_with_soledad_syncer.py | 1 + soledad_sync.py | 27 ++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index aa881dc..52d7451 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,18 @@ soledad-sync-server: twistd -n web --port 8080 --class=server_with_soledad_syncer.resource +soledad-sync-server-lineprof: + kernprof -l server_with_soledad_syncer.py + + soledad-sync-server-debug: #twistd --profile=stats_obj --profiler=cProfile -n web --port 8080 --class=server_with_soledad_syncer.resource python -m cProfile -o sync.cprofile server_with_soledad_syncer.py +view-lineprofile: + python -m line_profiler server_with_soledad_syncer.py.lprof + + view-profile: cprofilev -f sync.cprofile diff --git a/server_with_soledad_syncer.py b/server_with_soledad_syncer.py index 5346df6..bc61bb8 100755 --- a/server_with_soledad_syncer.py +++ b/server_with_soledad_syncer.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- #!/usr/bin/env python import os diff --git a/soledad_sync.py b/soledad_sync.py index 710ecd5..44a90bd 100644 --- a/soledad_sync.py +++ b/soledad_sync.py @@ -3,14 +3,16 @@ from leap.soledad.client.api import Soledad from twisted.internet import defer # EDIT THIS TO MATCH YOUR TEST ENVIRONMENT ------------- -UUID = 'deadbeef4' -#HOST = 'http://futeisha:2323' +UUID = 'deadbeef10' +# HOST = 'http://futeisha:2323' HOST = 'http://localhost:2323' -#NUM_DOCS = 100 -NUM_DOCS = 5 +# NUM_DOCS = 100 +NUM_DOCS = 50 PAYLOAD = '/tmp/payload' # ------------------------------------------------------ +DO_THESEUS = os.environ.get('THESEUS', False) + def _get_soledad_instance_from_uuid(uuid, passphrase, basedir, server_url, cert_file, token): @@ -37,6 +39,11 @@ def upload_soledad_stuff(): with open(PAYLOAD, 'r') as f: payload = f.read() + if DO_THESEUS: + from theseus import Tracer + t = Tracer() + t.install() + s = _get_soledad_instance_from_uuid( UUID, 'pass', '/tmp/soledadsync', HOST, '', '') @@ -45,12 +52,22 @@ def upload_soledad_stuff(): d.addCallback(onSyncDone) return d + def stop_tracing(_): + if DO_THESEUS: + with open('callgrind.theseus', 'wb') as outfile: + t.write_data(outfile) + print "STOPPED TRACING, DUMPED IN CALLGRIND.THESEUS<<<<" + cd = [] for i in range(NUM_DOCS): cd.append(s.create_doc({'payload': payload})) d1 = defer.gatherResults(cd) + + # XXX comment out to nuke out the actual sync - d1.addCallback(do_sync) + #d1.addCallback(do_sync) + d1.addCallback(stop_tracing) + return d1 -- cgit v1.2.3