0

我正在做一个项目,对android手机上的系统进行实时分析。我想知道在给定的时间点有多少客户端绑定到任何远程服务。

例如:绑定到 LocationManager 服务的客户端数量。

这将帮助我识别对系统服务施加压力的应用程序。此外,它还将帮助我识别它的系统服务是否写得不好,或者系统服务的客户端是否表现不佳。

例如:我发现当您不断查询/更新/删除联系人内容提供者时,系统显示 com.android.acore 正在消耗更多的 cpu,但实际上它是表现不佳的第三方应用程序。

我正在开发自定义 ROM,并且可以访问代码以进行任何修改。

我知道活页夹是引用计数的,并且每个引用活页夹的 BinderProxy 构成对该活页夹的引用。但我不确定它是如何在代码中完成的。

如果有人已经对此进行了一些研究,请分享您的知识。

4

1 回答 1

0

发现有 ServiceRecord 类维护与服务相关的所有信息。请参阅- http://androidxref.com/4.4.4_r1/xref/frameworks/base/services/java/com/android/server/am/ServiceRecord .java

一些字段如下:

                     // all information about the service.
final ApplicationInfo appInfo;
                        // information about service's app.
final int userId;       // user that this service is running as
final String packageName; // the package implementing intent's component
final String processName; // process where this component wants to run
final String permission;// permission needed to access service
final String baseDir;   // where activity source (resources etc) located
final String resDir;   // where public activity source (public resources etc) located
final String dataDir;   // where activity data should go
final boolean exported; // from ServiceInfo.exported
final Runnable restarter; // used to schedule retries of starting the service
final long createTime;  // when this service was created
final ArrayMap<Intent.FilterComparison, IntentBindRecord> bindings
        = new ArrayMap<Intent.FilterComparison, IntentBindRecord>();
                        // All active bindings to the service.
final ArrayMap<IBinder, ArrayList<ConnectionRecord>> connections
        = new ArrayMap<IBinder, ArrayList<ConnectionRecord>>();
                        // IBinder -> ConnectionRecord of all bound clients

ProcessRecord app;      // where this service is running or null.
ProcessRecord isolatedProc; // keep track of isolated process, if requested
ProcessStats.ServiceState tracker; // tracking service execution, may be null
ProcessStats.ServiceState restartTracker; // tracking service restart
boolean delayed;        // are we waiting to start this service in the background?
boolean isForeground;   // is service currently in foreground mode?
int foregroundId;       // Notification ID of last foreground req.
Notification foregroundNoti; // Notification record of foreground state.
long lastActivity;      // last time there was some activity on the service.
long startingBgTimeout;  // time at which we scheduled this for a delayed start.
boolean startRequested; // someone explicitly called start?
boolean delayedStop;    // service has been stopped but is in a delayed start?
boolean stopIfKilled;   // last onStart() said to stop if service killed?
boolean callStart;      // last onStart() has asked to alway be called on restart.
int executeNesting;     // number of outstanding operations keeping foreground.
boolean executeFg;      // should we be executing in the foreground?
long executingStart;    // start time of last execute request.
boolean createdFromFg;  // was this service last created due to a foreground process call?
int crashCount;         // number of times proc has crashed with service running
int totalRestartCount;  // number of times we have had to restart.
int restartCount;       // number of restarts performed in a row.
long restartDelay;      // delay until next restart attempt.
long restartTime;       // time of last restart.
long nextRestartTime;   // time when restartDelay will expire.

String stringName;      // caching of toString

private int lastStartId;    // identifier of most recent start request.
于 2014-08-15T15:17:05.767 回答