diff --git a/src/profiler_def.js b/src/profiler_def.js index 0def9c2..005f938 100644 --- a/src/profiler_def.js +++ b/src/profiler_def.js @@ -232,15 +232,13 @@ function _profileJavaApis(profiler) { } // // アプリケーション共通モジュール API -// // (Webに設定すると無限ループになるので除外) +// // ※ WebとContentは、session.jsで変更しているので除外 // profileStaticApis("Archiver", [ "zip", "unzip" ]); // profileInstancializeApis("BatchManager", [ "exportData", "getExportCategories", "getImportCategories", "importData", "isUpdate", "addBatch", "deleteBatch", "deleteBatches", "getBatch", "getBatches", "getBatchesByIds", "getBatchIds", "updateBatch" ]); // profileInstancializeApis("BatchServer", [ "isConnected", "start", "restart", "stop", "setRefresh", "getRefresh", "isRun", "executeBatchProgram" ]); // profileStaticApis("CSVParser", [ "parse" ]); // profileStaticApis("Client", [ "destroy", "get", "identifier", "keys", "life", "remove", "removeSession", "set", "sleep" ]); // profileStaticApis("Constant", [ "define", "load" ]); -// profileStaticApis("Content", [ "executeFunction" ]); -// profileInstancializeApis("Content", [ "execute", "isError", "toString", "getFunction" ]); // profileInstancializeApis("DOMAttribute", [ "getName", "getValue", "getParentNode", "toString" ]); // profileInstancializeApis("DOMDocument", [ "getDocumentElement", "getElementsByTagName", "getElementById", "createElement", "createTextNode", "getDoctype", "isError", "getErrorMessage" ]); // profileInstancializeApis("DOMDocumentType", [ "getName", "getPublicId", "getSystemId", "getInternalSubset", "getEntities", "getNotations", "toString" ]); @@ -530,7 +528,7 @@ function _profileJavaApis(profiler) { // profileInstancializeApis("UpdateManager", [ "getKeys", "getLastModified", "isUpDate", "modify", "removeAll", "remove" ]); // // // iAP Platform -// // (Webに設定すると無限ループになるので除外) +// // ※ WebとContentは、session.jsで変更しているので除外 // profileInstancializeApis("WorkManager", [ "addParallelizedTask", "addSerializedTaskQueue", "addSerializedTask", "getRegisteredInfo", "releaseRunningParallelizedTask", "releaseRunningSerializedTask", "removeParallelizedTask", "removeSerializedTaskQueue", "removeSerializedTask", "setParallelizedTaskQueueActive", "setSerializedTaskQueueActive", "stopRunningParallelizedTask", "stopRunningSerializedTask" ]); // profileInstancializeApis("Cache", [ "get", "put", "removeAll", "remove" ]); // profileInstancializeApis("DatabaseMetaData", [ "getDatabaseMajorVersion", "getDatabaseMinorVersion", "getDatabaseProductName", "getDatabaseProductVersion", "getDriverMajorVersion", "getDriverMinorVersion", "getDriverName", "getDriverVersion", "getSearchStringEscape" ]); @@ -548,8 +546,6 @@ function _profileJavaApis(profiler) { // profileStaticApis("Archiver", [ "zip", "unzip" ]); // profileStaticApis("Client", [ "destroy", "get", "identifier", "keys", "life", "remove", "removeSession", "set", "sleep" ]); // profileInstancializeApis("Constant", [ "define", "load" ]); -// profileStaticApis("Content", [ "executeFunction" ]); -// profileInstancializeApis("Content", [ "execute", "isError", "toString", "getFunction" ]); // profileStaticApis("CSVParser", [ "parse" ]); // profileStaticApis("Debug", [ "browse", "print", "write", "console" ]); // profileInstancializeApis("DOMAttribute", [ "getName", "getValue", "getParentNode", "toString" ]); diff --git a/src/session.js b/src/session.js index 7fc5505..0e1c19a 100644 --- a/src/session.js +++ b/src/session.js @@ -60,8 +60,10 @@ function profile(request) { // forwardのプロファイル設定 weaveIntoForward(profiler, profilerDef); - + // Contentのプロファイル設定 + weaveIntoContent(profiler, profilerDef); + // ライブラリのプロファイル設定 profilerDef.getFunction("profileLibraries")(profiler); @@ -118,6 +120,79 @@ function weaveIntoForward(profiler, profilerDef) { } } +/** + * Contentをオーバーライドして、プロファイラの設定を行う。 + * + * @param {Profiler} profiler + * @param {Content} profilerDef + * @returns {undefined} + * @since 1.0.4 + */ +function weaveIntoContent(profiler, profilerDef) { + + if (Content.__profiler_weaved__) { + return; + } + + // コンストラクタ引数を getFuncion などから参照できるように、 + // Content完全に作りかえる。 + + // コンストラクタ + this.__proto__.Content = function(srcPath) { + this.srcPath = srcPath; + }; + + this.__proto__.Content.__profiler_weaved__ = true; + + // execute + this.__proto__.Content.prototype.execute = function execute(request) { + + return executeAndProfile(profiler, profilerDef, this.srcPath, request, true); + }; + + // executeFunction + this.__proto__.Content.executeFunction = function executeFunction() { + + var args = Array.prototype.slice.call(arguments); + var path = args[0]; + var functionName = args[1]; + var funcArgs = []; + + if (args.length >= 3) { + for (var i = 2; i < args.length; i++) { + funcArgs[i - 2] = args[i]; + } + } + + var scriptScope = getScriptScope(profiler, profilerDef, path); + return scriptScope[functionName].apply(this, funcArgs); + }; + + // getFunction + this.__proto__.Content.prototype.getFunction = function getFunction(functionName) { + + var scriptScope = getScriptScope(profiler, profilerDef, this.srcPath); + return scriptScope[functionName]; + }; + + // isError + this.__proto__.Content.prototype.isError = function isError() { + + try { + $javaClass.JSSPViewBuilder.getBuilder().getComposition(this.srcPath); + return false; + + } catch (e) { + return true; + } + }; + + // toString + this.__proto__.Content.prototype.toString = function toString() { + return this.srcPath; + }; +} + /** * im_actionにプロファイラを設定して実行する。 * @@ -135,15 +210,32 @@ function executeAndProfileAction(request, profiler, profilerDef) { return; } - var imActive = request.im_active ? request.im_active.replace(/\(2f\)/g, "/").replace(/\(5f\)/g, "_") : null; + var imActive = request.im_active ? + request.im_active.replace(/\(2f\)/g, "/").replace(/\(5f\)/g, "_") : + null; - var path = imActive || currentPath; + var scriptScope = getScriptScope(profiler, profilerDef, imActive || currentPath); + + scriptScope[imAction](request); +} + +/** + * プロファイラ設定済みのScriptScopeオブジェクトを取得する。 + * + * @param {Profiler} profiler + * @param {Content} profilerDef + * @param {String} path + * @returns {ScriptScope} + */ +function getScriptScope(profiler, profilerDef, path) { var scriptScope = $javaClass.JSSPScriptBuilder.getBuilder().getScriptScope(path); - profiler.addAllExclude(scriptScope, getExcludeFunctions(profilerDef, path), path); + if (path !== "profiler_def") { + profiler.addAllExclude(scriptScope, getExcludeFunctions(profilerDef, path), path); + } - scriptScope[imAction](request); + return scriptScope; } /** @@ -171,22 +263,22 @@ function getExcludeFunctions(profilerDef, path) { } /** - * pathを実行し、プロファイルを行う。また、結果をレスポンスに書き出す。 + * pathを実行し、プロファイルを行う。 * * @param {Profiler} profiler プロファイラオブジェクト * @param {Object} profilerDef プロファイラ対象定義オブジェクト * @param {String} path JSSPパス(拡張子は含まない) * @param {Array} args pathの引数 + * @param {boolean} returnText trueの場合、実行結果のHTMLを文字列で返却する。falseの場合は、結果をレスポンスに書き出す。 * @returns {undefined} */ -function executeAndProfile(profiler, profilerDef, path, args) { +function executeAndProfile(profiler, profilerDef, path, args, returnText) { var ctx = $javaClass.Context.getCurrentContext(); if (existsJsSource(path)) { - var scriptScope = $javaClass.JSSPScriptBuilder.getBuilder().getScriptScope(path); - profiler.addAllExclude(scriptScope, getExcludeFunctions(profilerDef, path), path); + var scriptScope = getScriptScope(profiler, profilerDef, path); if ($javaClass.ScriptableObject.hasProperty(scriptScope, "init")) { @@ -204,6 +296,10 @@ function executeAndProfile(profiler, profilerDef, path, args) { try { var html = view.execute(ctx, scriptScope || new $javaClass.ScriptScope()); + if (returnText) { + return html; + } + Web.getHTTPResponse().sendMessageBodyString(html); } finally {