Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] Add Log for subProcess (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darin726 authored and YorkShen committed Jul 3, 2019
1 parent 3768c8f commit 4695a70
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 135 deletions.
2 changes: 1 addition & 1 deletion android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ android {
if (ndkversion < 16) {
api_level = "android-14";
} else {
api_level = "android-21";
api_level = "android-16";
}

def android_project_dir = projectDir
Expand Down
15 changes: 13 additions & 2 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan
private boolean isDestroy=false;
private boolean hasException = false;
private boolean isRenderSuccess = false;
private boolean createInstanceHeartBeat = false;
private Map<String,Serializable> mUserTrackParams;
private NativeInvokeHelper mNativeInvokeHelper;
private boolean isCommit=false;
Expand Down Expand Up @@ -533,6 +534,12 @@ public boolean isHasException() {
public void setHasException(boolean hasException) {
this.hasException = hasException;
}

public void createInstanceFuncHeartBeat() {
WXLogUtils.d("createInstanceFuncHeartBeat: " + mInstanceId);
this.createInstanceHeartBeat = true;
}

public void addOnInstanceVisibleListener(OnInstanceVisibleListener l){
mVisibleListeners.add(l);
}
Expand Down Expand Up @@ -892,7 +899,10 @@ public void run() {
if(wxJscProcessManager.withException(WXSDKInstance.this)) {
onJSException(String.valueOf(WX_ERR_RELOAD_PAGE),"jsc reboot","jsc reboot");
}
WXBridgeManager.getInstance().callReportCrashReloadPage(mInstanceId, null);
if(!createInstanceHeartBeat) {
WXBridgeManager.getInstance().callReportCrashReloadPage(mInstanceId, null);
WXLogUtils.e("callReportCrashReloadPage with jsc reboot");
}
}
}
}
Expand Down Expand Up @@ -1104,7 +1114,8 @@ public void reloadPage(boolean reloadThis) {
"true"));
WXLogUtils.e("degrade : " + degrade);
if(degrade) {
onJSException(String.valueOf(WX_ERR_JSC_CRASH.getErrorCode()),"jsc Crashed", "jsc Crashed degradeToH5");
onJSException(String.valueOf(WX_ERR_RELOAD_PAGE.getErrorCode()),"Do not reloadPage", "Do not reloadPage degradeToH5");
WXLogUtils.e("Do not reloadPage degradeToH5");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public String execJSOnInstance(String instanceId, String script, int type) {
*/
@CalledByNative
public int callNative(String instanceId, byte[] tasks, String callback) {
if("HeartBeat".equals(callback)) {
Log.e("HeartBeat instanceId", instanceId);
WXSDKInstance sdkInstance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if(sdkInstance != null) {
sdkInstance.createInstanceFuncHeartBeat();
}
return IWXBridge.INSTANCE_RENDERING;
}

return callNative(instanceId, (JSONArray) JSON.parseArray(new String(tasks)), callback);
}

Expand Down
59 changes: 33 additions & 26 deletions weex_core/Source/android/bridge/script_bridge_in_multi_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,32 +196,6 @@ static std::unique_ptr<IPCResult> HandleCallNative(IPCArguments *arguments) {
->CallNative(pageId.get(), task.get(), callback.get());
}
}));

// char *pageId = getArumentAsCStr(arguments, 0);
// char *task = getArumentAsCStr(arguments, 1);
// char *callback = getArumentAsCStr(arguments, 2);
//
// if (pageId != nullptr && task != nullptr) {
//#if JSAPI_LOG
// LOGD("[ExtendJSApi] handleCallNative >>>> pageId: %s, task: %s", pageId,
// task);
//#endif
// WeexCoreManager::Instance()->script_bridge()->core_side()->CallNative(
// pageId, task, callback);
// }
//
// if (pageId != nullptr) {
// delete[] pageId;
// pageId = nullptr;
// }
// if (task != nullptr) {
// delete[] task;
// task = nullptr;
// }
// if (callback != nullptr) {
// delete[] callback;
// callback = nullptr;
// }
return createInt32Result(0);
}

Expand Down Expand Up @@ -977,6 +951,35 @@ std::unique_ptr<IPCResult> UpdateComponentData(IPCArguments *arguments) {
return createInt32Result(static_cast<int32_t>(true));
}


std::unique_ptr<IPCResult> Tlog(IPCArguments *arguments) {
auto arg1 = std::unique_ptr<char[]>(getArumentAsCStr(arguments, 0));
auto arg2 = std::unique_ptr<char[]>(getArumentAsCStr(arguments, 1));
WeexCoreManager::Instance()->script_thread()->message_loop()->PostTask(
weex::base::MakeCopyable(
[tag = std::move(arg1), log = std::move(arg2)]() {
LOGE_TAG(tag.get(),"%s",log.get());
}));
return createInt32Result(static_cast<int32_t>(true));
}


std::unique_ptr<IPCResult> HeartBeat(IPCArguments *arguments) {
auto arg1 = std::unique_ptr<char[]>(getArumentAsCStr(arguments, 0));
WeexCoreManager::Instance()->script_thread()->message_loop()->PostTask(
weex::base::MakeCopyable(
[pageId = std::move(arg1)]() {
if (pageId != nullptr) {
LOGE("HeartBeat %s", pageId.get());
WeexCoreManager::Instance()
->script_bridge()
->core_side()
->CallNative(pageId.get(), "HeartBeat", "HeartBeat");
}
}));
return createInt32Result(static_cast<int32_t>(true));
}

ScriptBridgeInMultiProcess::ScriptBridgeInMultiProcess() {
set_script_side(new bridge::script::ScriptSideInMultiProcess);
set_core_side(new CoreSideInScript);
Expand Down Expand Up @@ -1070,6 +1073,10 @@ void ScriptBridgeInMultiProcess::RegisterIPCCallback(IPCHandler *handler) {
OnReceivedResult);
handler->registerHandler(static_cast<uint32_t>(IPCProxyMsg::UPDATECOMPONENTDATA),
UpdateComponentData);
handler->registerHandler(static_cast<uint32_t>(IPCProxyMsg::TLOGMSG),
Tlog);
handler->registerHandler(static_cast<uint32_t>(IPCProxyMsg::HEARTBEAT),
HeartBeat);
}

} // namespace WeexCore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//

#include <object/weex_env.h>
#include <object/tlog.h>
#include "script_side_in_queue.h"

#include "android/jsengine/task/impl/init_framework_task.h"
Expand Down Expand Up @@ -244,6 +245,7 @@ int ScriptSideInQueue::CreateInstance(const char *instanceId,

auto string = String::fromUTF8(script);
if (string.isEmpty()) {
Weex::TLog::tlog("%s id CreateInstance's script is null", instanceId);
return 0;
}
CreateInstanceTask *task = new CreateInstanceTask(String::fromUTF8(instanceId),
Expand Down
53 changes: 53 additions & 0 deletions weex_core/Source/android/jsengine/object/tlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
//
// Created by Darin on 2019-07-01.
//

#ifndef WEEX_PROJECT_TLOG_H
#define WEEX_PROJECT_TLOG_H

#include "weex_env.h"

namespace Weex {
class TLog {
public: static void tlog(const char* fmt, ...) {
va_list arg_list;
int size;
va_start(arg_list, fmt);
size = vsnprintf(nullptr, 0, fmt, arg_list);
int byte_count = size + 1;
char * buffer = (char*)malloc(byte_count);
memset(buffer, 0, byte_count);
va_end(arg_list);
if (size > 0) {
va_start(arg_list, fmt);
vsnprintf(const_cast<char*>(buffer), byte_count, fmt, arg_list);
va_end(arg_list);
}
WeexEnv::getEnv()->sendTLog("JSEngine", buffer);

free(buffer);
}
};


}

#endif //WEEX_PROJECT_TLOG_H
17 changes: 16 additions & 1 deletion weex_core/Source/android/jsengine/object/weex_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//

#include "weex_env.h"
#include "tlog.h"

WeexEnv *WeexEnv::env_ = nullptr;

Expand Down Expand Up @@ -71,7 +72,11 @@ void WeexEnv::init_crash_handler(std::string crashFileName) {
bool WeexEnv::is_app_crashed() {
if(!isMultiProcess)
return false;
return crashHandler->is_crashed();
bool crashed = crashHandler->is_crashed();
if(crashed) {
Weex::TLog::tlog("%s", "AppCrashed");
}
return crashed;
}
volatile bool WeexEnv::can_m_cache_task_() const {
return m_cache_task_;
Expand All @@ -82,3 +87,13 @@ void WeexEnv::set_m_cache_task_(volatile bool m_cache_task_) {
WeexEnv::~WeexEnv() {
wson::destory();
}

void WeexEnv::sendTLog(const char *tag, const char *log) {
if(m_back_to_weex_core_thread.get()) {
BackToWeexCoreQueue::IPCTask *ipc_task = new BackToWeexCoreQueue::IPCTask(
IPCProxyMsg::TLOGMSG);
ipc_task->addParams(tag);
ipc_task->addParams(log);
m_back_to_weex_core_thread->addTask(ipc_task);
}
}
5 changes: 4 additions & 1 deletion weex_core/Source/android/jsengine/object/weex_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class WeexEnv {
void init_crash_handler(std::string crashFileName);

bool is_app_crashed();
public:

void sendTLog(const char *tag, const char *log);

public:
std::unique_ptr<BackToWeexCoreQueue> m_back_to_weex_core_thread;
volatile bool isMultiProcess = false;
std::unique_ptr<WeexIPCClient> m_ipc_client_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
//
// Created by 董亚运 on 2019/1/8.
// Created by Darin on 2019/1/8.
//

#include <base/android/log_utils.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
//
// Created by 董亚运 on 2019/1/8.
// Created by Darin on 2019/1/8.
//

#ifndef WEEX_PROJECT_BACK_TO_WEEX_CORE_QUEUE_H
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// Created by Darin on 20/07/2018.
//

#include <object/weex_env.h>
#include "create_instance_task.h"

void CreateInstanceTask::addExtraArg(String arg) {
Expand All @@ -37,5 +38,13 @@ void CreateInstanceTask::run(WeexRuntime *runtime) {

runtime->createInstance(instanceId, extraArgs.at(0), this->script, extraArgs.at(1), extraArgs.at(2),
extraArgs.at(3), initExtraArgs->params);


if(WeexEnv::getEnv()->m_back_to_weex_core_thread.get()) {
BackToWeexCoreQueue::IPCTask *ipc_task = new BackToWeexCoreQueue::IPCTask(
IPCProxyMsg::HEARTBEAT);
ipc_task->addParams(instanceId.utf8().data());
WeexEnv::getEnv()->m_back_to_weex_core_thread.get()->addTask(ipc_task);
}
}

Loading

0 comments on commit 4695a70

Please sign in to comment.