Merge "AppProfiler: don't hold lock for CPU times" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
627b877cb1
@@ -80,10 +80,6 @@ public class ProcessCpuTracker {
|
|||||||
/** Stores user time and system time in jiffies. */
|
/** Stores user time and system time in jiffies. */
|
||||||
private final long[] mProcessStatsData = new long[4];
|
private final long[] mProcessStatsData = new long[4];
|
||||||
|
|
||||||
/** Stores user time and system time in jiffies. Used for
|
|
||||||
* public API to retrieve CPU use for a process. Must lock while in use. */
|
|
||||||
private final long[] mSinglePidStatsData = new long[4];
|
|
||||||
|
|
||||||
private static final int[] PROCESS_FULL_STATS_FORMAT = new int[] {
|
private static final int[] PROCESS_FULL_STATS_FORMAT = new int[] {
|
||||||
PROC_SPACE_TERM,
|
PROC_SPACE_TERM,
|
||||||
PROC_SPACE_TERM|PROC_PARENS|PROC_OUT_STRING, // 2: name
|
PROC_SPACE_TERM|PROC_PARENS|PROC_OUT_STRING, // 2: name
|
||||||
@@ -629,17 +625,15 @@ public class ProcessCpuTracker {
|
|||||||
* executing in both user and system code. Safe to call without lock held.
|
* executing in both user and system code. Safe to call without lock held.
|
||||||
*/
|
*/
|
||||||
public long getCpuTimeForPid(int pid) {
|
public long getCpuTimeForPid(int pid) {
|
||||||
synchronized (mSinglePidStatsData) {
|
final String statFile = "/proc/" + pid + "/stat";
|
||||||
final String statFile = "/proc/" + pid + "/stat";
|
final long[] statsData = new long[4];
|
||||||
final long[] statsData = mSinglePidStatsData;
|
if (Process.readProcFile(statFile, PROCESS_STATS_FORMAT,
|
||||||
if (Process.readProcFile(statFile, PROCESS_STATS_FORMAT,
|
null, statsData, null)) {
|
||||||
null, statsData, null)) {
|
long time = statsData[PROCESS_STAT_UTIME]
|
||||||
long time = statsData[PROCESS_STAT_UTIME]
|
|
||||||
+ statsData[PROCESS_STAT_STIME];
|
+ statsData[PROCESS_STAT_STIME];
|
||||||
return time * mJiffyMillis;
|
return time * mJiffyMillis;
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -647,15 +641,13 @@ public class ProcessCpuTracker {
|
|||||||
* in the runqueue. Safe to call without lock held.
|
* in the runqueue. Safe to call without lock held.
|
||||||
*/
|
*/
|
||||||
public long getCpuDelayTimeForPid(int pid) {
|
public long getCpuDelayTimeForPid(int pid) {
|
||||||
synchronized (mSinglePidStatsData) {
|
final String statFile = "/proc/" + pid + "/schedstat";
|
||||||
final String statFile = "/proc/" + pid + "/schedstat";
|
final long[] statsData = new long[4];
|
||||||
final long[] statsData = mSinglePidStatsData;
|
if (Process.readProcFile(statFile, PROCESS_SCHEDSTATS_FORMAT,
|
||||||
if (Process.readProcFile(statFile, PROCESS_SCHEDSTATS_FORMAT,
|
null, statsData, null)) {
|
||||||
null, statsData, null)) {
|
return statsData[PROCESS_SCHEDSTAT_CPU_DELAY_TIME] / 1_000_000;
|
||||||
return statsData[PROCESS_SCHEDSTAT_CPU_DELAY_TIME] / 1_000_000;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1892,15 +1892,11 @@ public class AppProfiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long getCpuTimeForPid(int pid) {
|
long getCpuTimeForPid(int pid) {
|
||||||
synchronized (mProcessCpuTracker) {
|
return mProcessCpuTracker.getCpuTimeForPid(pid);
|
||||||
return mProcessCpuTracker.getCpuTimeForPid(pid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long getCpuDelayTimeForPid(int pid) {
|
long getCpuDelayTimeForPid(int pid) {
|
||||||
synchronized (mProcessCpuTracker) {
|
return mProcessCpuTracker.getCpuDelayTimeForPid(pid);
|
||||||
return mProcessCpuTracker.getCpuDelayTimeForPid(pid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ProcessCpuTracker.Stats> getCpuStats(Predicate<ProcessCpuTracker.Stats> predicate) {
|
List<ProcessCpuTracker.Stats> getCpuStats(Predicate<ProcessCpuTracker.Stats> predicate) {
|
||||||
|
|||||||
Reference in New Issue
Block a user