For launching time performance, patch to not exec web process.
authorTaejeong Lee <taejeong.lee@samsung.com>
Tue, 23 Oct 2012 12:01:55 +0000 (21:01 +0900)
committerGerrit Code Review <gerrit2@kim11>
Tue, 8 Jan 2013 10:02:13 +0000 (19:02 +0900)
 * This patch is for launching time performance.
 * This patch moves up creating web process by forking procedure.
 * The forking procedure makes possible that web process can re-use libraries which was already loaded by UI process.

 * This commit needs a webkit patch below.
   - https://tizendev.org/gerrit/#/c/21558/

[Issue#] N/A
[Problem] For launching time performance.
[Cause] N/A
[Solution] Moves up creating web process by forking procedure.

Change-Id: I295aab7d705fcdc4dd5502411eeaadbd62a7cf1c

src/api_new/core_module.cpp [changed mode: 0755->0644]
src/api_new/core_module.h
src/wrt-client/wrt-client.cpp [changed mode: 0755->0644]
src/wrt-client/wrt-client.h [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 9aca8c2..86246a7
@@ -118,19 +118,23 @@ public:
             }
             Try
             {
-
-                // Needed settings for WKContext are located here
-                // create Ewk_Context
-                Ewk_Context* newEwkContext =
-                    ewk_context_new_with_injected_bundle_path(bundlePath);
-                if (!newEwkContext) {
-                    LogError("Failed to create Ewk_Context");
-                    ThrowMsg(DPL::Exception, "Failed to create ewk context");
+                if(!m_ewkContext)
+                {
+                    // Needed settings for WKContext are located here
+                    // create Ewk_Context
+                    Ewk_Context* newEwkContext =
+                        ewk_context_new_with_injected_bundle_path(bundlePath);
+                    if (!newEwkContext) {
+                        LogError("Failed to create Ewk_Context");
+                        ThrowMsg(DPL::Exception, "Failed to create ewk context");
+                    }
+
+                    m_ewkContext = newEwkContext;
                 }
-                    // cache model setting
-                ewk_context_cache_model_set(newEwkContext,
+
+                // cache model setting
+                ewk_context_cache_model_set(m_ewkContext,
                                             EWK_CACHE_MODEL_DOCUMENT_BROWSER);
-                m_ewkContext = newEwkContext;
                 ADD_PROFILING_POINT("WebProcess fork", "start");
 
                 // To fork a Webprocess as soon as possible,
@@ -161,6 +165,16 @@ public:
         return true;
     }
 
+    bool Init(Ewk_Context* ewk_context)
+    {
+        if(ewk_context)
+        {
+            m_ewkContext = ewk_context;
+        }
+
+        return Init();
+    }
+
     void Terminate()
     {
         if (m_ewkContext) {
@@ -244,6 +258,11 @@ bool CoreModule::Init()
     return m_impl->Init();
 }
 
+bool CoreModule::Init(Ewk_Context* ewk_context)
+{
+    return m_impl->Init(ewk_context);
+}
+
 void CoreModule::Terminate()
 {
     return m_impl->Terminate();
index 85d9802..f436012 100644 (file)
@@ -29,6 +29,8 @@
 #include <dpl/singleton.h>
 #include <memory>
 
+#include <EWebKit2.h>
+
 namespace WRT {
 
 class CoreModuleImpl; // forward declaration
@@ -53,6 +55,7 @@ class CoreModule
      * @return true on success, false when it fails
      */
     bool Init();
+    bool Init(Ewk_Context* ewk_context);
     /**
      * Deinitialize CoreModule. If it called without Init() some internal
      * asserts will fail.
old mode 100755 (executable)
new mode 100644 (file)
index c10b0f8..b04c4d1
@@ -36,6 +36,9 @@ const char *EDJE_SHOW_BACKWARD_SIGNAL = "show,backward,signal";
 const std::string VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
 const std::string VIEWMODE_TYPE_MAXIMIZED = "maximized";
 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
+const char* const BUNDLE_PATH = "/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so";
+
+static Ewk_Context* s_ewk_context = NULL;
 
 WrtClient::WrtClient(int argc, char **argv) :
     Application(argc, argv, "wrt-client", false),
@@ -155,47 +158,57 @@ void WrtClient::showHelpAndQuit()
 
 bool WrtClient::checkArgument()
 {
-    LogInfo("checkArgument");
+    std::string tizenId = getTizenIdFromArgument(m_argc, m_argv);
+
+    if(tizenId.empty()){
+        // Just show help
+        return false;
+    } else {
+        m_tizenId = tizenId;
+        LogDebug("Tizen id: " << m_tizenId);
+        return true;
+    }
+}
 
-    std::string arg = m_argv[0];
+std::string WrtClient::getTizenIdFromArgument(int argc, char **argv)
+{
+    LogInfo("checkArgument");
+    std::string arg = argv[0];
 
     if (arg.empty()) {
-        return false;
+        return "";
     }
 
-    if (arg.find("wrt-client") != std::string::npos)
-    {
-        if (m_argc <= 1) {
-            return false;
+    if (arg.find("wrt-client") != std::string::npos) {
+        if (argc <= 1) {
+            return "";
         }
 
-        arg = m_argv[1];
+        arg = argv[1];
 
         if (arg == "-h" || arg == "--help") {
-            // Just show help
-            return false;
+            return "";
         } else if (arg == "-l" || arg == "--launch" ||
                 arg == "-t" || arg == "--tizen") {
-            if (m_argc != 3) {
-                return false;
+            if (argc != 3) {
+                return "";
             }
-            m_tizenId = std::string(m_argv[2]);
+            return argv[2];
         } else {
-            return false;
+            return "";
         }
     } else {
+        // Launch widget based on application basename
         size_t pos = arg.find_last_of('/');
 
         if (pos != std::string::npos) {
             arg = arg.erase(0, pos + 1);
         }
 
-        // Launch widget based on application basename
-        m_tizenId = arg;
-        LogDebug("Tizen id: " << m_tizenId);
+        return arg;
     }
 
-    return true;
+    return "";
 }
 
 void WrtClient::setStep()
@@ -278,7 +291,7 @@ void WrtClient::OnEventReceived(const NextStepEvent& /*event*/)
 void WrtClient::initStep()
 {
     LogDebug("");
-    if (WRT::CoreModuleSingleton::Instance().Init()) {
+    if (WRT::CoreModuleSingleton::Instance().Init(s_ewk_context)) {
         m_initialized = true;
     } else {
         m_returnStatus = ReturnStatus::Failed;
@@ -662,6 +675,21 @@ int main(int argc,
     {
         ADD_PROFILING_POINT("main-entered", "point");
 
+        // Set log tagging
+        DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
+
+        // This code is to fork a web process without exec.
+        std::string tizenId = WrtClient::getTizenIdFromArgument(argc, argv);
+
+        if (!tizenId.empty())
+        {
+            LogDebug("Launching by fork mode");
+            ewk_init();
+            ewk_set_arguments(argc, argv);
+            setenv("WRT_LAUNCHING_PERFORMANCE", "1", 1);
+            s_ewk_context = ewk_context_new_with_injected_bundle_path(BUNDLE_PATH);
+        }
+
         // Output on stdout will be flushed after every newline character,
         // even if it is redirected to a pipe. This is useful for running
         // from a script and parsing output.
@@ -687,9 +715,6 @@ int main(int argc,
         setenv("CAIRO_GL_LAZY_FLUSHING", "yes", 1);
         setenv("ELM_IMAGE_CACHE", "0", 1);
 
-        // Set log tagging
-        DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-CLIENT");
-
         WrtClient app(argc, argv);
 
         ADD_PROFILING_POINT("Before appExec", "point");
old mode 100755 (executable)
new mode 100644 (file)
index e5ce5c6..078dbcc
@@ -54,6 +54,7 @@ class WrtClient :
 
     ReturnStatus::Type   getReturnStatus() const;
     virtual void Quit();
+    static std::string getTizenIdFromArgument(int argc, char **argv);
 
   protected:
     virtual void OnStop();