Permalink
Browse files

fixes to make dispatch profilling and render logging work.

  • Loading branch information...
1 parent c0f1416 commit 1eb1180047c9e38eb4175d0ba9de6ed48689b7a8 @bthaeler committed Oct 10, 2012
@@ -252,10 +252,8 @@ Example:
},
index: function(ac) {
- ac.models.DebugBarModelFoo.getData(function(err, data) {
- var my_data = ac.debug.get("my_flag");
- ac.done("My data: " + my_data.some);
- });
+ var my_data = ac.debug.get("my_flag");
+ ac.done("My data: " + my_data.some);
}
};
@@ -292,14 +290,15 @@ Example:
index: function(ac) {
var debug = ac._adapter.debug,
currentUrl = ac._adapter.req.url,
- newUrl = currentUrl.slice(ac.app.config.debug.debugPath.length),
+ config = YUI.Env.mojito.DataProcess.retrieve('static-app-config'),
+ newUrl = currentUrl.slice(config.debug.debugPath.length),
mojitoRoute = ac.url.find(newUrl),
call = mojitoRoute.call.split('.'),
route = Y.clone(ac.app.config.specs[call[0]]);
route.action = call[1];
- Y.each(debug.parseDebugParameters(ac.params.url()[ac.app.config.debug.queryParam]), function (flag) {
+ Y.each(debug.parseDebugParameters(ac.params.url()[config.debug.queryParam]), function (flag) {
debug.addFlag(flag);
});
@@ -314,7 +313,7 @@ Example:
var res;
res = data.application + "<P>";
- Y.each(debug.parseDebugParameters(ac.params.url()[ac.app.config.debug.queryParam]), function (flag) {
+ Y.each(debug.parseDebugParameters(ac.params.url()[config.debug.queryParam]), function (flag) {
var data = debug.get(flag);
if (data)
@@ -324,7 +323,7 @@ Example:
});
}
};
- }, '0.0.1', {requires: ['mojito', 'mojito-url-addon']});
+ }, '0.0.1', {requires: ['mojito', 'mojito-url-addon', 'mojito-params-addon', 'mojito-http-addon', 'mojito-composite-addon']});
@@ -284,6 +284,10 @@ YUI.add('mojito-action-context', function(Y, NAME) {
staticAppConfig = YUI.Env.mojito.DataProcess.retrieve('static-app-config') || {},
my;
+ if (opts.adapter.debug) {
@caridy

caridy Oct 11, 2012

I don't like this API because not all elements in mojito will have access to adapter obj. That's one of the reasons we use Y.mojito.perf.* as something that is available at any given time, without requiring it.

@bthaeler

bthaeler Oct 11, 2012

Owner

Really the API is attached to the req object. This is done by the debug middleware that detects that the debugger should be turned on. The existing mojito.perf system is only useful for a single request. If you have multiple requests occurring at the same time the results will get all merged together. By attaching the debugger to the request we can keep all the data separate. This needed when we look towards running this in a production environment.

+ opts.adapter.debug.profClose("dispatch", command.instance.debugID, 'setup AC');
+ }
+
my = this;
this.action = command.action;
@@ -326,6 +330,10 @@ YUI.add('mojito-action-context', function(Y, NAME) {
perf.done(); // closing the 'ac:init' timeline
+ if (opts.adapter.debug) {
+ opts.adapter.debug.profClose("dispatch", command.instance.debugID, 'AC setup done');
+ }
+
Y.mojito.perf.mark('mojito', 'action:start', 'before the action', command);
perf = Y.mojito.perf.timeline('mojito', 'action:call',
@@ -335,6 +343,10 @@ YUI.add('mojito-action-context', function(Y, NAME) {
perf.done(); // closing the 'action:call' timeline
+ if (opts.adapter.debug) {
+ opts.adapter.debug.profClose("dispatch", command.instance.debugID, 'action call done');
+ }
+
}
ActionContext.prototype = {
@@ -375,6 +387,9 @@ YUI.add('mojito-action-context', function(Y, NAME) {
perf = Y.mojito.perf.timeline('mojito', 'ac.done',
'time to execute ac.done process', this.command);
+ if (adapter.debug) {
+ adapter.debug.profClose("dispatch", instance.debugID, 'start of done');
+ }
if (Y.Lang.isString(meta)) {
// If the meta string is a serializer set it
if (serializer[meta]) {
@@ -482,6 +497,9 @@ YUI.add('mojito-action-context', function(Y, NAME) {
adapter[callbackFunc](data, meta);
perf.done(); // closing the 'ac.done' timeline
+ if (adapter.debug) {
+ adapter.debug.profClose("dispatch", instance.debugID, 'end of done');
+ }
return;
}
@@ -517,6 +535,16 @@ YUI.add('mojito-action-context', function(Y, NAME) {
contentPath = pathToRoot + contentPath;
}
+ if (adapter.debug) {
+ adapter.debug.logOn('Render', function () {
+ var ret = {};
+ ret.mojit_view_id = (data && data.mojit_view_id);
+ ret.data = data;
+ ret.mojitType = instance.type;
+ ret.tmpl = contentPath;
+ return ret;
+ });
+ }
// optimize for server only
if (typeof context.runtime !== undefined && 'server' === context.runtime) {
renderer = CACHE.renderers[mojitView.engine];
@@ -546,6 +574,9 @@ YUI.add('mojito-action-context', function(Y, NAME) {
}
perf.done(); // closing the 'ac.done' timeline
+ if (adapter.debug) {
+ adapter.debug.profClose("dispatch", instance.debugID, 'end of done');
+ }
Y.mojito.perf.mark('mojito', 'action:stop', 'after the action', this.command);
},
@@ -38,6 +38,8 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
this.CACHE = {};
+ this.debugID = 0;
+
Y.log('Dispatcher created', 'debug', NAME);
return this;
@@ -53,7 +55,9 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
'gather details about mojit', command);
if (adapter.debug) {
- adapter.debug.profOpen("dispatch", command.instance.instanceId, (command.instance.id || '@' + command.instance.type) + ':' + (command.action || (command.instance.action || 'index')));
+ command.instance.debugID = this.debugID;
+ this.debugID = this.debugID + 1;
+ adapter.debug.profOpen("dispatch", command.instance.debugID, (command.instance.id || '@' + command.instance.type) + ':' + (command.action || (command.instance.action || 'index')));
@caridy

caridy Oct 11, 2012

In mojito-perf we use a different technique to avoid doing all the "id" computation everywhere, something that is subject to change in the future. What we do is to pass command or a string. If command is passed, internally we know how to get the ID from the command structure.

Check idFromCommand in perf.server.js

So, this line will become something like:

adapter.debug.profOpen("dispatch", command.instance.debugID, command);

@bthaeler

bthaeler Oct 11, 2012

Owner

profOpen is a general purpose profiling API. It is called in several places. We don't want to pass command in here.

We can create a new function in the api to do this, we can mirror what perf.server.js does.

adapter.debug.profOpen("dispatch", command.instance.debugID, adapter.debug.idFromCommand(command));

}
store.validateContext(command.context);
@@ -70,7 +74,7 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
perf.done(); // closing 'dispatch:expandInstance' timeline
if (adapter.debug) {
- adapter.debug.profClose("dispatch", command.instance.instanceId, 'startup done');
+ adapter.debug.profClose("dispatch", command.instance.debugID, 'startup done');
}
// We replace the given instance with the expanded instance.
@@ -107,7 +111,7 @@ YUI.add('mojito-dispatcher', function(Y, NAME) {
perf.done(); // closing the 'ac:ctor' timeline
if (adapter.debug) {
- adapter.debug.profClose("dispatch", command.instance.instanceId, 'startup instance done');
+ adapter.debug.profClose("dispatch", command.instance.debugID, 'startup instance done');
}
});
@@ -42,16 +42,6 @@ YUI.add('mojito-view-renderer', function(Y) {
* later. (streaming)
*/
render: function(data, mojitType, tmpl, adapter, meta, more) {
- if (adapter.debug) {
- adapter.debug.logOn('Render', function () {
- var ret = {};
- ret.mojit_view_id = (data && data.mojit_view_id);
- ret.data = data;
- ret.mojitType = mojitType;
- ret.tmpl = tmpl;
- return ret;
- });
- }
this._renderer.render(data, mojitType, tmpl, adapter, meta, more);
}
};

0 comments on commit 1eb1180

Please sign in to comment.