use of android.util.SparseArray in project android_frameworks_base by DirtyUnicorns.
the class ActivityManagerService method noteUidProcessState.
private void noteUidProcessState(final int uid, final int state) {
mBatteryStatsService.noteUidProcessState(uid, state);
if (mTrackingAssociations) {
for (int i1 = 0, N1 = mAssociations.size(); i1 < N1; i1++) {
ArrayMap<ComponentName, SparseArray<ArrayMap<String, Association>>> targetComponents = mAssociations.valueAt(i1);
for (int i2 = 0, N2 = targetComponents.size(); i2 < N2; i2++) {
SparseArray<ArrayMap<String, Association>> sourceUids = targetComponents.valueAt(i2);
ArrayMap<String, Association> sourceProcesses = sourceUids.get(uid);
if (sourceProcesses != null) {
for (int i4 = 0, N4 = sourceProcesses.size(); i4 < N4; i4++) {
Association ass = sourceProcesses.valueAt(i4);
if (ass.mNesting >= 1) {
// currently associated
long uptime = SystemClock.uptimeMillis();
ass.mStateTimes[ass.mLastState - ActivityManager.MIN_PROCESS_STATE] += uptime - ass.mLastStateUptime;
ass.mLastState = state;
ass.mLastStateUptime = uptime;
}
}
}
}
}
}
}
use of android.util.SparseArray in project android_frameworks_base by AOSPA.
the class MenuBuilder method dispatchSaveInstanceState.
private void dispatchSaveInstanceState(Bundle outState) {
if (mPresenters.isEmpty())
return;
SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
final int id = presenter.getId();
if (id > 0) {
final Parcelable state = presenter.onSaveInstanceState();
if (state != null) {
presenterStates.put(id, state);
}
}
}
}
outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
}
use of android.util.SparseArray in project android_frameworks_base by AOSPA.
the class ProcessStats method writeToParcel.
/** @hide */
public void writeToParcel(Parcel out, long now, int flags) {
out.writeInt(MAGIC);
out.writeInt(PARCEL_VERSION);
out.writeInt(STATE_COUNT);
out.writeInt(ADJ_COUNT);
out.writeInt(PSS_COUNT);
out.writeInt(SYS_MEM_USAGE_COUNT);
out.writeInt(SparseMappingTable.ARRAY_SIZE);
mCommonStringToIndex = new ArrayMap<String, Integer>(mProcesses.size());
// First commit all running times.
ArrayMap<String, SparseArray<ProcessState>> procMap = mProcesses.getMap();
final int NPROC = procMap.size();
for (int ip = 0; ip < NPROC; ip++) {
SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
uids.valueAt(iu).commitStateTime(now);
}
}
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
final int NPKG = pkgMap.size();
for (int ip = 0; ip < NPKG; ip++) {
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
for (int iu = 0; iu < NUID; iu++) {
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
final int NVERS = vpkgs.size();
for (int iv = 0; iv < NVERS; iv++) {
PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (proc.getCommonProcess() != proc) {
proc.commitStateTime(now);
}
}
final int NSRVS = pkgState.mServices.size();
for (int isvc = 0; isvc < NSRVS; isvc++) {
pkgState.mServices.valueAt(isvc).commitStateTime(now);
}
}
}
}
out.writeLong(mTimePeriodStartClock);
out.writeLong(mTimePeriodStartRealtime);
out.writeLong(mTimePeriodEndRealtime);
out.writeLong(mTimePeriodStartUptime);
out.writeLong(mTimePeriodEndUptime);
out.writeString(mRuntime);
out.writeInt(mHasSwappedOutPss ? 1 : 0);
out.writeInt(mFlags);
mTableData.writeToParcel(out);
if (mMemFactor != STATE_NOTHING) {
mMemFactorDurations[mMemFactor] += now - mStartTime;
mStartTime = now;
}
writeCompactedLongArray(out, mMemFactorDurations, mMemFactorDurations.length);
mSysMemUsage.writeToParcel(out);
out.writeInt(NPROC);
for (int ip = 0; ip < NPROC; ip++) {
writeCommonString(out, procMap.keyAt(ip));
final SparseArray<ProcessState> uids = procMap.valueAt(ip);
final int NUID = uids.size();
out.writeInt(NUID);
for (int iu = 0; iu < NUID; iu++) {
out.writeInt(uids.keyAt(iu));
final ProcessState proc = uids.valueAt(iu);
writeCommonString(out, proc.getPackage());
out.writeInt(proc.getVersion());
proc.writeToParcel(out, now);
}
}
out.writeInt(NPKG);
for (int ip = 0; ip < NPKG; ip++) {
writeCommonString(out, pkgMap.keyAt(ip));
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
final int NUID = uids.size();
out.writeInt(NUID);
for (int iu = 0; iu < NUID; iu++) {
out.writeInt(uids.keyAt(iu));
final SparseArray<PackageState> vpkgs = uids.valueAt(iu);
final int NVERS = vpkgs.size();
out.writeInt(NVERS);
for (int iv = 0; iv < NVERS; iv++) {
out.writeInt(vpkgs.keyAt(iv));
final PackageState pkgState = vpkgs.valueAt(iv);
final int NPROCS = pkgState.mProcesses.size();
out.writeInt(NPROCS);
for (int iproc = 0; iproc < NPROCS; iproc++) {
writeCommonString(out, pkgState.mProcesses.keyAt(iproc));
final ProcessState proc = pkgState.mProcesses.valueAt(iproc);
if (proc.getCommonProcess() == proc) {
// This is the same as the common process we wrote above.
out.writeInt(0);
} else {
// There is separate data for this package's process.
out.writeInt(1);
proc.writeToParcel(out, now);
}
}
final int NSRVS = pkgState.mServices.size();
out.writeInt(NSRVS);
for (int isvc = 0; isvc < NSRVS; isvc++) {
out.writeString(pkgState.mServices.keyAt(isvc));
final ServiceState svc = pkgState.mServices.valueAt(isvc);
writeCommonString(out, svc.getProcessName());
svc.writeToParcel(out, now);
}
}
}
}
// Fragmentation info (/proc/pagetypeinfo)
final int NPAGETYPES = mPageTypeLabels.size();
out.writeInt(NPAGETYPES);
for (int i = 0; i < NPAGETYPES; i++) {
out.writeInt(mPageTypeZones.get(i));
out.writeString(mPageTypeLabels.get(i));
out.writeIntArray(mPageTypeSizes.get(i));
}
mCommonStringToIndex = null;
}
use of android.util.SparseArray in project android_frameworks_base by AOSPA.
the class ProcessStats method add.
public void add(ProcessStats other) {
ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = other.mPackages.getMap();
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
final SparseArray<SparseArray<PackageState>> uids = pkgMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
final int uid = uids.keyAt(iu);
final SparseArray<PackageState> versions = uids.valueAt(iu);
for (int iv = 0; iv < versions.size(); iv++) {
final int vers = versions.keyAt(iv);
final PackageState otherState = versions.valueAt(iv);
final int NPROCS = otherState.mProcesses.size();
final int NSRVS = otherState.mServices.size();
for (int iproc = 0; iproc < NPROCS; iproc++) {
ProcessState otherProc = otherState.mProcesses.valueAt(iproc);
if (otherProc.getCommonProcess() != otherProc) {
if (DEBUG)
Slog.d(TAG, "Adding pkg " + pkgName + " uid " + uid + " vers " + vers + " proc " + otherProc.getName());
ProcessState thisProc = getProcessStateLocked(pkgName, uid, vers, otherProc.getName());
if (thisProc.getCommonProcess() == thisProc) {
if (DEBUG)
Slog.d(TAG, "Existing process is single-package, splitting");
thisProc.setMultiPackage(true);
long now = SystemClock.uptimeMillis();
final PackageState pkgState = getPackageStateLocked(pkgName, uid, vers);
thisProc = thisProc.clone(now);
pkgState.mProcesses.put(thisProc.getName(), thisProc);
}
thisProc.add(otherProc);
}
}
for (int isvc = 0; isvc < NSRVS; isvc++) {
ServiceState otherSvc = otherState.mServices.valueAt(isvc);
if (DEBUG)
Slog.d(TAG, "Adding pkg " + pkgName + " uid " + uid + " service " + otherSvc.getName());
ServiceState thisSvc = getServiceStateLocked(pkgName, uid, vers, otherSvc.getProcessName(), otherSvc.getName());
thisSvc.add(otherSvc);
}
}
}
}
ArrayMap<String, SparseArray<ProcessState>> procMap = other.mProcesses.getMap();
for (int ip = 0; ip < procMap.size(); ip++) {
SparseArray<ProcessState> uids = procMap.valueAt(ip);
for (int iu = 0; iu < uids.size(); iu++) {
int uid = uids.keyAt(iu);
ProcessState otherProc = uids.valueAt(iu);
final String name = otherProc.getName();
final String pkg = otherProc.getPackage();
final int vers = otherProc.getVersion();
ProcessState thisProc = mProcesses.get(name, uid);
if (DEBUG)
Slog.d(TAG, "Adding uid " + uid + " proc " + name);
if (thisProc == null) {
if (DEBUG)
Slog.d(TAG, "Creating new process!");
thisProc = new ProcessState(this, pkg, uid, vers, name);
mProcesses.put(name, uid, thisProc);
PackageState thisState = getPackageStateLocked(pkg, uid, vers);
if (!thisState.mProcesses.containsKey(name)) {
thisState.mProcesses.put(name, thisProc);
}
}
thisProc.add(otherProc);
}
}
for (int i = 0; i < ADJ_COUNT; i++) {
if (DEBUG)
Slog.d(TAG, "Total duration #" + i + " inc by " + other.mMemFactorDurations[i] + " from " + mMemFactorDurations[i]);
mMemFactorDurations[i] += other.mMemFactorDurations[i];
}
mSysMemUsage.mergeStats(other.mSysMemUsage);
if (other.mTimePeriodStartClock < mTimePeriodStartClock) {
mTimePeriodStartClock = other.mTimePeriodStartClock;
mTimePeriodStartClockStr = other.mTimePeriodStartClockStr;
}
mTimePeriodEndRealtime += other.mTimePeriodEndRealtime - other.mTimePeriodStartRealtime;
mTimePeriodEndUptime += other.mTimePeriodEndUptime - other.mTimePeriodStartUptime;
mHasSwappedOutPss |= other.mHasSwappedOutPss;
}
use of android.util.SparseArray in project android_frameworks_base by AOSPA.
the class ProcessStats method collectProcessesLocked.
public ArrayList<ProcessState> collectProcessesLocked(int[] screenStates, int[] memStates, int[] procStates, int[] sortProcStates, long now, String reqPackage, boolean activeOnly) {
final ArraySet<ProcessState> foundProcs = new ArraySet<ProcessState>();
final ArrayMap<String, SparseArray<SparseArray<PackageState>>> pkgMap = mPackages.getMap();
for (int ip = 0; ip < pkgMap.size(); ip++) {
final String pkgName = pkgMap.keyAt(ip);
final SparseArray<SparseArray<PackageState>> procs = pkgMap.valueAt(ip);
for (int iu = 0; iu < procs.size(); iu++) {
final SparseArray<PackageState> vpkgs = procs.valueAt(iu);
final int NVERS = vpkgs.size();
for (int iv = 0; iv < NVERS; iv++) {
final PackageState state = vpkgs.valueAt(iv);
final int NPROCS = state.mProcesses.size();
final boolean pkgMatch = reqPackage == null || reqPackage.equals(pkgName);
for (int iproc = 0; iproc < NPROCS; iproc++) {
final ProcessState proc = state.mProcesses.valueAt(iproc);
if (!pkgMatch && !reqPackage.equals(proc.getName())) {
continue;
}
if (activeOnly && !proc.isInUse()) {
continue;
}
foundProcs.add(proc.getCommonProcess());
}
}
}
}
ArrayList<ProcessState> outProcs = new ArrayList<ProcessState>(foundProcs.size());
for (int i = 0; i < foundProcs.size(); i++) {
ProcessState proc = foundProcs.valueAt(i);
if (proc.computeProcessTimeLocked(screenStates, memStates, procStates, now) > 0) {
outProcs.add(proc);
if (procStates != sortProcStates) {
proc.computeProcessTimeLocked(screenStates, memStates, sortProcStates, now);
}
}
}
Collections.sort(outProcs, ProcessState.COMPARATOR);
return outProcs;
}
Aggregations