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@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@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)
moksha-commits@lists.fedorahosted.org