moksha/middleware
by Luke Macken
moksha/middleware/connector.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
New commits:
commit a497e7ae2309b7943ff60b7abde3a64f6cead07f
Author: Luke Macken <lmacken(a)redhat.com>
Date: Fri Jul 29 21:41:14 2011 -0400
Get our connector middleware working on py2.4 again
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index b9389e1..dfc126d 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -17,12 +17,15 @@
import logging
import pkg_resources
-import simplejson as json
import urllib
import time
import os.path
import threading
-import json
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
from paste.deploy.converters import asbool
from webob import Request, Response
12 years, 10 months
moksha/middleware
by John (J5) Palmieri
moksha/middleware/connector.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
New commits:
commit 4bacdedbe5fd1ba72f274f44da19cdd2cebffa09
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Jul 27 16:52:11 2011 -0400
make profiling output json friendly
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index 44c4f39..b9389e1 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -22,6 +22,7 @@ import urllib
import time
import os.path
import threading
+import json
from paste.deploy.converters import asbool
from webob import Request, Response
@@ -76,7 +77,7 @@ class MokshaConnectorMiddleware(object):
# output profiling data
file_name = os.path.join(directory, prof_file_name)
f = open(file_name, 'w')
- f.write("{'id': %s, 'start_time': %s, 'callback_start_time': %s, 'end_time': %s}"
+ f.write('{"id": "%s", "start_time": %s, "callback_start_time": %s, "end_time": %s}'
% (profile_id, p['start_time'], p['callback_start_time'], p['end_time']))
f.close()
return Response('{}')(environ, start_response)
@@ -186,8 +187,8 @@ class MokshaConnectorMiddleware(object):
# output call info
file_name = os.path.join(directory, info_file_name)
f = open(file_name, 'w')
- f.write("{'name': '%s', 'op': '%s', 'path': '%s', 'remote_params': %s, 'ip': '%s', 'timestamp': %f, 'id_counter': %i, 'id': %s}"
- % (conn_name, op, path, str(remote_params), ip, timestamp, prof_id_counter, profile_id))
+ f.write('{"name": "%s", "op": "%s", "path": "%s", "remote_params": %s, "ip": "%s", "timestamp": %f, "id_counter": %i, "id": "%s"}'
+ % (conn_name, op, path, json.dumps(remote_params), ip, timestamp, prof_id_counter, profile_id))
f.close()
# in order to get the results back we need to pass an object
12 years, 11 months
moksha/middleware
by John (J5) Palmieri
moksha/middleware/connector.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 49a0a3ec76cc53805645c7770e6265d818f69753
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Jul 27 14:22:37 2011 -0400
add full id to info file
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index 803081d..44c4f39 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -186,8 +186,8 @@ class MokshaConnectorMiddleware(object):
# output call info
file_name = os.path.join(directory, info_file_name)
f = open(file_name, 'w')
- f.write("{'name': '%s', 'op': '%s', 'path': '%s', 'remote_params': %s, 'ip': '%s', 'timestamp': %f, 'id_counter': %i}"
- % (conn_name, op, path, str(remote_params), ip, timestamp, prof_id_counter))
+ f.write("{'name': '%s', 'op': '%s', 'path': '%s', 'remote_params': %s, 'ip': '%s', 'timestamp': %f, 'id_counter': %i, 'id': %s}"
+ % (conn_name, op, path, str(remote_params), ip, timestamp, prof_id_counter, profile_id))
f.close()
# in order to get the results back we need to pass an object
12 years, 11 months
moksha/middleware
by John (J5) Palmieri
moksha/middleware/connector.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit c1903df507a035ef5aa76261bafd61f58c796be8
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Jul 27 13:56:30 2011 -0400
add more information to the .info file so we can sort
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index 3447de0..803081d 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -186,8 +186,8 @@ class MokshaConnectorMiddleware(object):
# output call info
file_name = os.path.join(directory, info_file_name)
f = open(file_name, 'w')
- f.write("{'name': '%s', 'op': '%s', 'path': '%s', 'remote_params': %s}"
- % (conn_name, op, path, str(remote_params)))
+ f.write("{'name': '%s', 'op': '%s', 'path': '%s', 'remote_params': %s, 'ip': '%s', 'timestamp': %f, 'id_counter': %i}"
+ % (conn_name, op, path, str(remote_params), ip, timestamp, prof_id_counter))
f.close()
# in order to get the results back we need to pass an object
12 years, 11 months
2 commits - moksha/api moksha/middleware moksha/public
by John (J5) Palmieri
moksha/api/widgets/global_resources/widget.py | 7 +++-
moksha/middleware/connector.py | 45 +++++++++++++++++++++-----
moksha/public/javascript/moksha.js | 23 ++++++++++++-
3 files changed, 64 insertions(+), 11 deletions(-)
New commits:
commit 1a2ce34b599e52f6cfaa11c09193f628d9bb3c15
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Jul 27 13:38:48 2011 -0400
add code to collect profiling data from the client and send it to teh server
diff --git a/moksha/api/widgets/global_resources/widget.py b/moksha/api/widgets/global_resources/widget.py
index 50de275..776150f 100644
--- a/moksha/api/widgets/global_resources/widget.py
+++ b/moksha/api/widgets/global_resources/widget.py
@@ -52,16 +52,18 @@ class GlobalResourceInjectionWidget(Widget):
moksha_userid = "${user_id}";
moksha_debug = ${debug};
moksha_profile = ${profile};
+ moksha_profile_connectors = ${profile_connectors};
</script>
"""
engine_name = 'mako'
- params = ['base_url', 'csrf_token', 'user_id', 'debug', 'profile', 'csrf_trusted_domains']
+ params = ['base_url', 'csrf_token', 'user_id', 'debug', 'profile', 'profile_connectors', 'csrf_trusted_domains']
base_url = '/'
csrf_token = ''
user_id = ''
debug = 'false'
profile = 'false'
+ profile_connectors = 'false'
def __init__(self):
super(GlobalResourceInjectionWidget, self).__init__()
@@ -111,6 +113,9 @@ class GlobalResourceInjectionWidget(Widget):
if asbool(config['global_conf'].get('profile')):
d['profile'] = 'true'
+ if asbool(config['global_conf'].get('profile.connectors')):
+ d['profile_connectors'] = 'true'
+
d['csrf_trusted_domains'] = self.csrf_trusted_domains_hash
identity = request.environ.get('repoze.who.identity')
diff --git a/moksha/public/javascript/moksha.js b/moksha/public/javascript/moksha.js
index d8af15f..96f973f 100644
--- a/moksha/public/javascript/moksha.js
+++ b/moksha/public/javascript/moksha.js
@@ -543,6 +543,25 @@ moksha = {
connector_load: function(resource, method, params, callback, $overlay_div, loading_icon) {
var path = moksha.url('/moksha_connector/' + resource + '/' + method);
+ if (moksha_profile_connectors == true) {
+ var start_time = new Date().getTime();
+ var profile_callback = function(data) {
+ var profile_id = data['moksha_profile_id'];
+ var callback_start_time = new Date().getTime();
+ callback(data);
+ var end_time = new Date().getTime();
+
+ profile_info = {'id' : profile_id,
+ 'start_time' : start_time,
+ 'callback_start_time': callback_start_time,
+ 'end_time' : end_time};
+
+ // fire and forget the profile collector
+ moksha.json_load('/moksha_connector/prof_collector', profile_info, function(data){}, null, null);
+ }
+ return moksha.json_load(path, params, profile_callback, $overlay_div, loading_icon);
+ }
+
return moksha.json_load(path, params, callback, $overlay_div, loading_icon);
},
@@ -576,7 +595,7 @@ moksha = {
profile_callback_start_time = date.getTime();
}
- if (typeof($overlay_div) == 'object')
+ if ($overlay_div != null && typeof($overlay_div) == 'object')
$overlay_div.hide();
callback(data);
@@ -603,7 +622,7 @@ moksha = {
}
// show loading
- if (typeof($overlay_div) == 'object') {
+ if ($overlay_div != null && typeof($overlay_div) == 'object') {
if (typeof(loading_icon) == 'undefined')
loading_icon = '/images/spinner.gif';
commit 0cba02411222b095567317d3b66d5e989ab012a1
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Jul 27 13:37:39 2011 -0400
add a profiling data collector to the connector middleware
* collects profiling data gathered by the web client
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index 055bdcc..3447de0 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -41,12 +41,16 @@ class MokshaConnectorMiddleware(object):
"""
_connectors = {}
- profile_id = 0
- profile_id_lock = threading.Lock()
+ profile_id_counter = 0
+ profile_id_counter_lock = threading.Lock()
def __init__(self, application):
log.info('Creating MokshaConnectorMiddleware')
self.application = application
+
+ # ids of profile data we are waiting to collect and record
+ self.outstanding_profile_ids = {}
+
self.load_connectors()
def strip_script(self, environ, path):
@@ -62,6 +66,23 @@ class MokshaConnectorMiddleware(object):
return path
+ def prof_collector(self, environ, request, start_response):
+ p = request.params
+ profile_id = p['id']
+ directory = config.get('profile.dir', '')
+ if self.outstanding_profile_ids.pop(profile_id, False):
+ prof_file_name = "jsonrequest_%s.jsprof" % profile_id
+
+ # output profiling data
+ file_name = os.path.join(directory, prof_file_name)
+ f = open(file_name, 'w')
+ f.write("{'id': %s, 'start_time': %s, 'callback_start_time': %s, 'end_time': %s}"
+ % (profile_id, p['start_time'], p['callback_start_time'], p['end_time']))
+ f.close()
+ return Response('{}')(environ, start_response)
+
+ return Response(status='404 Not Found')(environ, start_response)
+
def __call__(self, environ, start_response):
request = Request(environ)
@@ -70,6 +91,9 @@ class MokshaConnectorMiddleware(object):
if path.startswith('/moksha_connector'):
s = path.split('/')[2:]
+ # check to see if we need to hand this off to the profile collector
+ if s[0] == 'prof_collector':
+ return self.prof_collector(environ, request, start_response)
# since keys are not unique we need to condense them
# into an actual dictionary with multiple entries becoming lists
@@ -146,16 +170,18 @@ class MokshaConnectorMiddleware(object):
directory = config.get('profile.dir', '')
# Make sure the id is unique for each thread
- self.profile_id_lock.acquire()
- prof_id = self.profile_id
- self.profile_id += 1
- self.profile_id_lock.release()
+ self.profile_id_counter_lock.acquire()
+ prof_id_counter = self.profile_id_counter
+ self.profile_id_counter += 1
+ self.profile_id_counter_lock.release()
ip = request.remote_addr
timestamp = time.time()
- prof_file_name = "connector_%s_%f_%s_%i.prof" % (conn_name, timestamp, ip, prof_id)
- info_file_name = "connector_%s_%f_%s_%i.info" % (conn_name, timestamp, ip, prof_id)
+ profile_id = "%s_%f_%s_%i" % (conn_name, timestamp, ip, prof_id_counter)
+ self.outstanding_profile_ids[profile_id] = True
+ prof_file_name = "connector_%s.prof" % profile_id
+ info_file_name = "connector_%s.info" % profile_id
# output call info
file_name = os.path.join(directory, info_file_name)
@@ -181,6 +207,9 @@ class MokshaConnectorMiddleware(object):
file_name)
r = result['r']
+
+ # add profile id to results
+ r['moksha_profile_id'] = profile_id
else:
r = conn_obj._dispatch(op, path, remote_params, **dispatch_params)
12 years, 11 months
moksha/middleware
by John (J5) Palmieri
moksha/middleware/connector.py | 58 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 54 insertions(+), 4 deletions(-)
New commits:
commit a56b40cc8c093d656e50c39a5dc9aa1ce691dc4f
Author: John (J5) Palmieri <johnp(a)redhat.com>
Date: Wed Jul 20 16:13:17 2011 -0400
add profiling to connectors
diff --git a/moksha/middleware/connector.py b/moksha/middleware/connector.py
index e86104a..055bdcc 100644
--- a/moksha/middleware/connector.py
+++ b/moksha/middleware/connector.py
@@ -19,10 +19,14 @@ import logging
import pkg_resources
import simplejson as json
import urllib
+import time
+import os.path
+import threading
+from paste.deploy.converters import asbool
from webob import Request, Response
from pprint import pformat
-
+from tg import config
log = logging.getLogger(__name__)
@@ -37,6 +41,8 @@ class MokshaConnectorMiddleware(object):
"""
_connectors = {}
+ profile_id = 0
+ profile_id_lock = threading.Lock()
def __init__(self, application):
log.info('Creating MokshaConnectorMiddleware')
@@ -93,7 +99,7 @@ class MokshaConnectorMiddleware(object):
return response(environ, start_response)
def _run_connector(self, environ, request,
- conn, op, *path,
+ conn_name, op, *path,
**remote_params):
response = None
# check last part of path to see if it is json data
@@ -121,7 +127,7 @@ class MokshaConnectorMiddleware(object):
else:
path = ''
- conn = self._connectors.get(conn)
+ conn = self._connectors.get(conn_name)
# pretty print output
pretty_print = False
@@ -132,7 +138,51 @@ class MokshaConnectorMiddleware(object):
if conn:
conn_obj = conn['connector_class'](environ, request)
- r = conn_obj._dispatch(op, path, remote_params, **dispatch_params)
+
+ r = None
+ if asbool(config.get('profile.connectors')):
+ import cProfile
+
+ directory = config.get('profile.dir', '')
+
+ # Make sure the id is unique for each thread
+ self.profile_id_lock.acquire()
+ prof_id = self.profile_id
+ self.profile_id += 1
+ self.profile_id_lock.release()
+
+ ip = request.remote_addr
+ timestamp = time.time()
+
+ prof_file_name = "connector_%s_%f_%s_%i.prof" % (conn_name, timestamp, ip, prof_id)
+ info_file_name = "connector_%s_%f_%s_%i.info" % (conn_name, timestamp, ip, prof_id)
+
+ # output call info
+ file_name = os.path.join(directory, info_file_name)
+ f = open(file_name, 'w')
+ f.write("{'name': '%s', 'op': '%s', 'path': '%s', 'remote_params': %s}"
+ % (conn_name, op, path, str(remote_params)))
+ f.close()
+
+ # in order to get the results back we need to pass an object
+ # by refrence which will be populated with the actual results
+ result = {'r': None}
+
+ # profile call
+ file_name = os.path.join(directory, prof_file_name)
+ cProfile.runctx("result['r'] = conn_obj._dispatch(op, path, remote_params, **dispatch_params)",
+ None,
+ {'conn_obj': conn_obj,
+ 'op': op,
+ 'path': path,
+ 'remote_params': remote_params,
+ 'dispatch_params': dispatch_params,
+ 'result': result},
+ file_name)
+
+ r = result['r']
+ else:
+ r = conn_obj._dispatch(op, path, remote_params, **dispatch_params)
if pretty_print:
r = '<pre>' + pformat(r) + '</pre>'
12 years, 11 months