Merge "Don\'t assume kernel tick is 100Hz" into mnc-dr1.5-dev
am: 0064c4c793
* commit '0064c4c79341bcb47bcb5b9ff568871f34f1dc63':
Don't assume kernel tick is 100Hz
This commit is contained in:
@@ -16,8 +16,11 @@
|
|||||||
package com.android.internal.os;
|
package com.android.internal.os;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.system.OsConstants;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import libcore.io.Libcore;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -29,7 +32,7 @@ import java.util.Arrays;
|
|||||||
*
|
*
|
||||||
* freq time
|
* freq time
|
||||||
*
|
*
|
||||||
* where time is measured in 1/100 seconds.
|
* where time is measured in jiffies.
|
||||||
*/
|
*/
|
||||||
public class KernelCpuSpeedReader {
|
public class KernelCpuSpeedReader {
|
||||||
private static final String TAG = "KernelCpuSpeedReader";
|
private static final String TAG = "KernelCpuSpeedReader";
|
||||||
@@ -38,6 +41,9 @@ public class KernelCpuSpeedReader {
|
|||||||
private final long[] mLastSpeedTimes;
|
private final long[] mLastSpeedTimes;
|
||||||
private final long[] mDeltaSpeedTimes;
|
private final long[] mDeltaSpeedTimes;
|
||||||
|
|
||||||
|
// How long a CPU jiffy is in milliseconds.
|
||||||
|
private final long mJiffyMillis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cpuNumber The cpu (cpu0, cpu1, etc) whose state to read.
|
* @param cpuNumber The cpu (cpu0, cpu1, etc) whose state to read.
|
||||||
*/
|
*/
|
||||||
@@ -46,6 +52,8 @@ public class KernelCpuSpeedReader {
|
|||||||
cpuNumber);
|
cpuNumber);
|
||||||
mLastSpeedTimes = new long[numSpeedSteps];
|
mLastSpeedTimes = new long[numSpeedSteps];
|
||||||
mDeltaSpeedTimes = new long[numSpeedSteps];
|
mDeltaSpeedTimes = new long[numSpeedSteps];
|
||||||
|
long jiffyHz = Libcore.os.sysconf(OsConstants._SC_CLK_TCK);
|
||||||
|
mJiffyMillis = 1000/jiffyHz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,8 +70,7 @@ public class KernelCpuSpeedReader {
|
|||||||
splitter.setString(line);
|
splitter.setString(line);
|
||||||
Long.parseLong(splitter.next());
|
Long.parseLong(splitter.next());
|
||||||
|
|
||||||
// The proc file reports time in 1/100 sec, so convert to milliseconds.
|
long time = Long.parseLong(splitter.next()) * mJiffyMillis;
|
||||||
long time = Long.parseLong(splitter.next()) * 10;
|
|
||||||
if (time < mLastSpeedTimes[speedIndex]) {
|
if (time < mLastSpeedTimes[speedIndex]) {
|
||||||
// The stats reset when the cpu hotplugged. That means that the time
|
// The stats reset when the cpu hotplugged. That means that the time
|
||||||
// we read is offset from 0, so the time is the delta.
|
// we read is offset from 0, so the time is the delta.
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ public class ProcessCpuTracker {
|
|||||||
static final int PROCESS_STAT_UTIME = 2;
|
static final int PROCESS_STAT_UTIME = 2;
|
||||||
static final int PROCESS_STAT_STIME = 3;
|
static final int PROCESS_STAT_STIME = 3;
|
||||||
|
|
||||||
/** Stores user time and system time in 100ths of a second. */
|
/** 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 100ths of a second. Used for
|
/** Stores user time and system time in jiffies. Used for
|
||||||
* public API to retrieve CPU use for a process. Must lock while in use. */
|
* public API to retrieve CPU use for a process. Must lock while in use. */
|
||||||
private final long[] mSinglePidStatsData = new long[4];
|
private final long[] mSinglePidStatsData = new long[4];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user