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

Commit

Permalink
[Android] dump ipc mmap page flag when white screen (#2903)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-chen authored and Darin726 committed Sep 16, 2019
1 parent 7ea24be commit c06d42e
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ private void checkWhiteScreen(){
if (!isWS){
return;
}
WXErrorCode errorCode = WXErrorCode.WX_ERROR_WHITE_SCREEN;
WXErrorCode errorCode = createInstanceHeartBeat?WXErrorCode.WX_ERROR_WHITE_SCREEN:WXErrorCode.WHITE_SCREEN_RESPONSE_TIMEOUT;
Map<String,String> args = new HashMap<>(1);
String vieTreeMsg = WhiteScreenUtils.takeViewTreeSnapShot(this);
args.put("viewTree",null == vieTreeMsg?"null viewTreeMsg":vieTreeMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public class WXBridge implements IWXBridge {

public native void nativeOnInteractionTimeUpdate(String instanceId);

public native String nativeDumpIpcPageQueueInfo();

/**
* Update Init Framework Params
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ public WXDebugJsBridge getWXDebugJsBridge() {
}
}

public String dumpIpcPageInfo(){
if (mWXBridge instanceof WXBridge){
return ((WXBridge)mWXBridge).nativeDumpIpcPageQueueInfo();
}
return "";
}

public void stopRemoteDebug() {
if (mWxDebugProxy != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public enum WXErrorCode {
WX_ERR_RELOAD_PAGE_EXCEED_LIMIT("-2114", "RELOAD_PAGE_EXCEED_LIMIT",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

WX_ERROR_WHITE_SCREEN("-2116", "WHITE_SCREEN",ErrorType.RENDER_ERROR,ErrorGroup.JS),
WHITE_SCREEN_RESPONSE_TIMEOUT("-2117", "WHITE_SCREEN_RESPONSE_TIMEOUT",ErrorType.RENDER_ERROR,ErrorGroup.JS),


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.concurrent.ConcurrentLinkedQueue;

import android.support.annotation.NonNull;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXConfigAdapter;
import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.ui.IFComponentHolder;
import com.taobao.weex.utils.WXUtils;
Expand Down Expand Up @@ -145,6 +147,10 @@ public Map<String, String> getStateInfo() {
Collections.sort(reportTimeLineInfo);
stateInfo.put("stateInfoList",reportTimeLineInfo.toString());

IWXConfigAdapter adapter = WXSDKManager.getInstance().getWxConfigAdapter();
if (null != adapter && "true".equalsIgnoreCase(adapter.getConfig("wxapm","dumpIpcPageInfo","true"))){
stateInfo.put("pageQueueInfo",WXBridgeManager.getInstance().dumpIpcPageInfo());
}
return stateInfo;
}

Expand Down
4 changes: 4 additions & 0 deletions weex_core/Source/android/multiprocess/weex_js_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,15 @@ static void *newIPCServer(void *_td) {
std::unique_ptr<IPCSender> sender(createIPCSender(futexPageQueue.get(), handler));
std::unique_ptr<IPCListener> listener =std::move(createIPCListener(futexPageQueue.get(), handler)) ;
newThreadStatus = SUCCESS;
WeexCore::WeexCoreManager::Instance()->server_queue_=futexPageQueue.get();

try {
futexPageQueue->spinWaitPeer();
listener->listen();
} catch (IPCException &e) {
LOGE("IPCException server died %s",e.msg());
base::android::DetachFromVM();
WeexCore::WeexCoreManager::Instance()->server_queue_= nullptr;
pthread_exit(NULL);
}
return nullptr;
Expand All @@ -207,6 +209,7 @@ IPCSender *WeexJSConnection::start(bool reinit) {
m_impl->serverSender = std::move(sender);
m_impl->futexPageQueue = std::move(futexPageQueue);

WeexCore::WeexCoreManager::Instance()->client_queue_=m_impl->futexPageQueue.get();
pthread_attr_t threadAttr;
newThreadStatus = UNFINISH;

Expand Down Expand Up @@ -295,6 +298,7 @@ IPCSender *WeexJSConnection::start(bool reinit) {

void WeexJSConnection::end() {
try {
WeexCoreManager::Instance()->client_queue_ = nullptr;
m_impl->serverSender.reset();
m_impl->futexPageQueue.reset();
} catch (IPCException &e) {
Expand Down
15 changes: 15 additions & 0 deletions weex_core/Source/android/wrap/wx_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "third_party/json11/json11.hpp"
#include "core/moniter/render_performance.h"
#include "core/render/page/render_page_base.h"
#include "third_party/IPC/IPCFutexPageQueue.h"

using namespace WeexCore;
jlongArray jFirstScreenRenderTime = nullptr;
Expand Down Expand Up @@ -286,6 +287,20 @@ static void SetLogType(JNIEnv* env, jobject jcaller, jfloat logLevel,
->core_side()
->SetLogType(l, flag);
}

static jstring nativeDumpIpcPageQueueInfo(JNIEnv* env, jobject jcaller){
std::string client_quene_msg;
if (WeexCoreManager::Instance()->client_queue_ != nullptr){
WeexCoreManager::Instance()->client_queue_->dumpPageInfo(client_quene_msg);
}
std::string server_quene_msg;
if (WeexCoreManager::Instance()->server_queue_ != nullptr){
WeexCoreManager::Instance()->server_queue_->dumpPageInfo(server_quene_msg);
}
std::string result ;
result = "{client:"+client_quene_msg+"}\n"+"{server:"+server_quene_msg+"}";
return env->NewStringUTF(result.c_str());
}
static void ReloadPageLayout(JNIEnv *env, jobject jcaller,
jstring instanceId){
WeexCoreManager::Instance()->getPlatformBridge()->core_side()->RelayoutUsingRawCssStyles(jString2StrFast(env,instanceId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ static void SetPageArgument(JNIEnv *env, jobject jcaller,
static void SetLogType(JNIEnv* env, jobject jcaller, jfloat type,
jfloat isPerf);

static jstring nativeDumpIpcPageQueueInfo(JNIEnv* env, jobject jcaller);
static void ReloadPageLayout(JNIEnv *env, jobject jcaller,
jstring instanceId);
static void SetDeviceDisplayOfPage(JNIEnv *env, jobject jcaller,
Expand Down Expand Up @@ -1396,6 +1397,10 @@ static const JNINativeMethod kMethodsWXBridge[] = {
"F"
")"
"V", reinterpret_cast<void *>(SetLogType)},
{ "nativeDumpIpcPageQueueInfo",
"("
")"
"Ljava/lang/String;", reinterpret_cast<void*>(nativeDumpIpcPageQueueInfo) },
{"nativeReloadPageLayout",
"("
"Ljava/lang/String;"
Expand Down
9 changes: 8 additions & 1 deletion weex_core/Source/core/manager/weex_core_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "core/bridge/script_bridge.h"
#include "base/message_loop/message_loop.h"

class IPCFutexPageQueue;

namespace WeexCore {
class WeexCoreManager {
public:
Expand Down Expand Up @@ -70,6 +72,9 @@ class WeexCoreManager {

inline weex::base::Thread *script_thread() { return script_thread_; }

IPCFutexPageQueue* client_queue_;
IPCFutexPageQueue* server_queue_;

private:
PlatformBridge *platform_bridge_;
MeasureFunctionAdapter *measure_function_adapter_;
Expand All @@ -82,7 +87,9 @@ class WeexCoreManager {
measure_function_adapter_(nullptr),
script_bridge_(nullptr),
project_mode_(COMMON),
script_thread_(nullptr){};
script_thread_(nullptr),
client_queue_(nullptr),
server_queue_(nullptr){};
~WeexCoreManager(){};
};
} // namespace WeexCore
Expand Down
13 changes: 13 additions & 0 deletions weex_core/Source/third_party/IPC/IPCFutexPageQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,16 @@ void IPCFutexPageQueue::clearFinishedTag()
pageRead[1] = 0;
__atomic_thread_fence(__ATOMIC_SEQ_CST);
}

void IPCFutexPageQueue::dumpPageInfo(std::string &info) {
std::string builder;

for (size_t i = 0; i < m_pagesCount ; ++i) {
uint32_t* pageStart = static_cast<uint32_t*>(getPage(i));
auto tmp = new IPCException("[%zu,%zu,%zu]",*pageStart,*(pageStart+1),*(pageStart+2));
builder+= tmp->msg();
delete(tmp);
}
auto msg = new IPCException("tid:%d,readId:%zu,writeId:%zu,info:%s",m_tid,m_currentRead,m_currentWrite,builder.c_str());
info.assign(msg->msg());
}
2 changes: 2 additions & 0 deletions weex_core/Source/third_party/IPC/IPCFutexPageQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define IPCFUTEXPAGEQUEUE_H

#include <stdint.h>
#include <string>

// shared memory page layout:
// futex uint32_t
Expand All @@ -50,6 +51,7 @@ class IPCFutexPageQueue {
inline size_t getPageSize() const { return m_pageSize - sizeof(uint32_t) * 2; }

static const size_t ipc_size = 2 * 1024 * 1024;
void dumpPageInfo(std::string& info);

private:
void unlock(size_t id);
Expand Down

0 comments on commit c06d42e

Please sign in to comment.