Skip to content

Commit 7d4a2e1

Browse files
authoredAug 29, 2017
Merge pull request #318 from cundong/dev
Support detail runtime info dump
2 parents f050f5c + 11c3654 commit 7d4a2e1

File tree

12 files changed

+328
-32
lines changed

12 files changed

+328
-32
lines changed
 

‎replugin-host-library/replugin-host-lib/src/main/aidl/com/qihoo360/loader2/IPluginClient.aidl

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,14 @@ interface IPluginClient {
3131
* @param Intent 广播的 Intent 数据
3232
*/
3333
void onReceive(String plugin, String receiver, in Intent intent);
34-
}
34+
35+
/**
36+
* dump通过插件化框架启动起来的Service信息
37+
*/
38+
String dumpServices();
39+
40+
/**
41+
* dump插件化框架中存储的详细Activity坑位映射表
42+
*/
43+
String dumpActivities();
44+
}

‎replugin-host-library/replugin-host-lib/src/main/aidl/com/qihoo360/loader2/IPluginHost.aidl

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ interface IPluginHost {
109109
* 通过PID来获取进程名
110110
*/
111111
String getProcessNameByPid(int pid);
112-
}
112+
113+
/**
114+
* dump详细的运行时信息
115+
*/
116+
String dump();
117+
}

‎replugin-host-library/replugin-host-lib/src/main/aidl/com/qihoo360/replugin/component/service/server/IPluginServiceServer.aidl

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ interface IPluginServiceServer {
1717

1818
int bindService(in Intent intent, in IServiceConnection conn, int flags, in Messenger client);
1919
boolean unbindService(in IServiceConnection conn);
20-
}
20+
21+
String dump();
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2005-2017 Qihoo 360 Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.qihoo360.loader2;
18+
19+
import android.os.IBinder;
20+
import android.util.Log;
21+
22+
import com.qihoo360.replugin.RePluginInternal;
23+
24+
import java.io.FileDescriptor;
25+
import java.io.PrintWriter;
26+
27+
/**
28+
* 运行时 dump 工具类
29+
*
30+
* @author RePlugin Team
31+
*/
32+
public class DumpUtils {
33+
34+
private static final String TAG = RePluginInternal.FOR_DEV ? DumpUtils.class.getSimpleName() : "DumpUtils";
35+
36+
/**
37+
* dump RePlugin框架运行时的详细信息,包括:Activity 坑位映射表,正在运行的 Service,以及详细的插件信息
38+
*
39+
* @param fd
40+
* @param writer
41+
* @param args
42+
*/
43+
public static void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
44+
45+
IBinder binder = PluginProviderStub.proxyFetchHostBinder(RePluginInternal.getAppContext());
46+
47+
if (binder == null) {
48+
return;
49+
}
50+
51+
IPluginHost pluginHost = IPluginHost.Stub.asInterface(binder);
52+
53+
try {
54+
String dumpInfo = pluginHost.dump();
55+
56+
if (RePluginInternal.FOR_DEV) {
57+
Log.d(TAG, "dumpInfo:" + dumpInfo);
58+
}
59+
60+
if (writer != null) {
61+
writer.println(dumpInfo);
62+
}
63+
} catch (Throwable e) {
64+
e.printStackTrace();
65+
}
66+
}
67+
}

‎replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginContainers.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
import com.qihoo360.replugin.base.IPC;
2828
import com.qihoo360.replugin.component.process.PluginProcessHost;
2929
import com.qihoo360.replugin.helper.HostConfigHelper;
30+
import com.qihoo360.replugin.helper.JSONHelper;
3031
import com.qihoo360.replugin.helper.LogDebug;
3132
import com.qihoo360.replugin.helper.LogRelease;
3233

34+
import org.json.JSONArray;
35+
import org.json.JSONObject;
36+
3337
import java.lang.ref.WeakReference;
3438
import java.util.ArrayList;
3539
import java.util.HashMap;
@@ -41,6 +45,7 @@
4145
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
4246
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
4347
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
48+
import static com.qihoo360.loader2.PluginContainers.ActivityState.toName;
4449
import static com.qihoo360.replugin.helper.LogDebug.LOG;
4550
import static com.qihoo360.replugin.helper.LogDebug.PLUGIN_TAG;
4651
import static com.qihoo360.replugin.helper.LogRelease.LOGR;
@@ -771,4 +776,28 @@ final ActivityState lookupByContainer(String container) {
771776

772777
return null;
773778
}
774-
}
779+
780+
final String dump() {
781+
782+
JSONArray activityArr = new JSONArray();
783+
JSONObject activityObj;
784+
785+
for (Map.Entry<String, ActivityState> entry : mStates.entrySet()) {
786+
String container = entry.getKey();
787+
ActivityState state = entry.getValue();
788+
789+
if (!TextUtils.isEmpty(state.plugin) && !TextUtils.isEmpty(state.activity)) {
790+
activityObj = new JSONObject();
791+
JSONHelper.putNoThrows(activityObj, "process", IPC.getCurrentProcessName());
792+
JSONHelper.putNoThrows(activityObj, "className", container);
793+
JSONHelper.putNoThrows(activityObj, "plugin", state.plugin);
794+
JSONHelper.putNoThrows(activityObj, "realClassName", state.activity);
795+
JSONHelper.putNoThrows(activityObj, "state", toName(state.state));
796+
JSONHelper.putNoThrows(activityObj, "refs", state.refs != null ? state.refs.size() : 0);
797+
activityArr.put(activityObj);
798+
}
799+
}
800+
801+
return activityArr.toString();
802+
}
803+
}

‎replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginProcessMain.java

+71
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
import com.qihoo360.replugin.packages.PluginManagerProxy;
3636
import com.qihoo360.replugin.packages.PluginManagerServer;
3737

38+
import org.json.JSONArray;
39+
import org.json.JSONException;
40+
import org.json.JSONObject;
41+
3842
import java.io.FileDescriptor;
3943
import java.io.PrintWriter;
4044
import java.util.HashMap;
@@ -229,6 +233,10 @@ public String toString() {
229233
}
230234
return super.toString();
231235
}
236+
237+
public IPluginClient getClient() {
238+
return client;
239+
}
232240
}
233241

234242
static final void reportStatus() {
@@ -242,6 +250,69 @@ static final void reportStatus() {
242250
}
243251
}
244252

253+
static final String dump() {
254+
255+
// 1.dump Activity映射表, service列表
256+
JSONArray activityArr = new JSONArray();
257+
JSONArray serviceArr = new JSONArray();
258+
259+
for (ProcessClientRecord clientRecord : ALL.values()) {
260+
try {
261+
IPluginClient pluginClient = clientRecord.getClient();
262+
if (pluginClient == null) {
263+
continue;
264+
}
265+
266+
String activityDumpInfo = pluginClient.dumpActivities();
267+
JSONArray activityList = new JSONArray(activityDumpInfo);
268+
int activityCount = activityList.length();
269+
if (activityCount > 0) {
270+
for (int i = 0; i < activityCount; i++) {
271+
activityArr.put(activityList.getJSONObject(i));
272+
}
273+
}
274+
275+
String serviceDumpInfo = pluginClient.dumpServices();
276+
JSONArray serviceList = new JSONArray(serviceDumpInfo);
277+
int serviceCount = serviceList.length();
278+
if (serviceCount > 0) {
279+
for (int i = 0; i < serviceCount; i++) {
280+
serviceArr.put(serviceList.getJSONObject(i));
281+
}
282+
}
283+
} catch (Throwable e) {
284+
e.printStackTrace();
285+
}
286+
}
287+
288+
// 2.dump 插件信息表
289+
JSONArray pluginArr = new JSONArray();
290+
List<PluginInfo> pluginList = MP.getPlugins(false);
291+
if (pluginList != null) {
292+
JSONObject pluginObj;
293+
for (PluginInfo pluginInfo : pluginList) {
294+
try {
295+
pluginObj = new JSONObject();
296+
pluginObj.put(pluginInfo.getName(), pluginInfo.toString());
297+
pluginArr.put(pluginObj);
298+
} catch (JSONException e) {
299+
e.printStackTrace();
300+
}
301+
}
302+
}
303+
304+
JSONObject detailObj = new JSONObject();
305+
try {
306+
detailObj.put("activity", activityArr);
307+
detailObj.put("service", serviceArr);
308+
detailObj.put("plugin", pluginArr);
309+
} catch (JSONException e) {
310+
e.printStackTrace();
311+
}
312+
313+
return detailObj.toString();
314+
}
315+
245316
static final void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
246317
if (LogDebug.DUMP_ENABLED) {
247318
writer.println("--- ALL.length = " + ALL.size() + " ---");

‎replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PluginProcessPer.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,29 @@ final String bindActivity(String plugin, int process, String activity, Intent in
330330
public void onReceive(String plugin, final String receiver, final Intent intent) {
331331
PluginReceiverHelper.onPluginReceiverReceived(plugin, receiver, mReceivers, intent);
332332
}
333-
}
333+
334+
@Override
335+
public String dumpServices() {
336+
try {
337+
IPluginServiceServer pss = fetchServiceServer();
338+
if (pss != null) {
339+
try {
340+
return pss.dump();
341+
} catch (Throwable e) {
342+
if (LOGR) {
343+
LogRelease.e(PLUGIN_TAG, "psc.sts: pss e", e);
344+
}
345+
}
346+
}
347+
} catch (RemoteException e) {
348+
e.printStackTrace();
349+
}
350+
351+
return null;
352+
}
353+
354+
@Override
355+
public String dumpActivities() {
356+
return mACM.dump();
357+
}
358+
}

‎replugin-host-library/replugin-host-lib/src/main/java/com/qihoo360/loader2/PmHostSvc.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,9 @@ public int getPidByProcessName(String processName) throws RemoteException {
621621
public String getProcessNameByPid(int pid) throws RemoteException {
622622
return PluginProcessMain.getProcessNameByPid(pid);
623623
}
624-
}
624+
625+
@Override
626+
public String dump() {
627+
return PluginProcessMain.dump();
628+
}
629+
}

0 commit comments

Comments
 (0)
Please sign in to comment.