diff --git a/packages/SystemUI/src/com/android/systemui/CPUInfoService.java b/packages/SystemUI/src/com/android/systemui/CPUInfoService.java index 9a7b3b28c31ff..4e89370075014 100644 --- a/packages/SystemUI/src/com/android/systemui/CPUInfoService.java +++ b/packages/SystemUI/src/com/android/systemui/CPUInfoService.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -57,6 +57,7 @@ public class CPUInfoService extends Service { private String[] mCpu = null; private String[] mCurrFreq = null; private String[] mCurrGov = null; + private String[] mCurrLoad = null; private int CPU_TEMP_DIVIDER = 1; private String CPU_TEMP_SENSOR = ""; @@ -72,7 +73,11 @@ public class CPUInfoService extends Service { private static final String CPU_ROOT = "/sys/devices/system/cpu/cpu"; private static final String CPU_CUR_TAIL = "/cpufreq/scaling_cur_freq"; private static final String CPU_GOV_TAIL = "/cpufreq/scaling_governor"; - private static final String GPU_FREQ_PATH = "/sys/class/kgsl/kgsl-3d0/gpuclk"; + private static final String GPU_FREQ_PATH = "/sys/class/kgsl/kgsl-3d0/clock_mhz"; + private static final String GPU_LOAD_PATH = "/sys/class/kgsl/kgsl-3d0/gpu_busy_percentage"; + private static final String THERMAL_DIR = "/sys/class/thermal/"; + private static final String[] BATTERY_TYPES = {"battery"}; + private static final String[] GPU_TYPES = {"gpu-0"}; private class CPUView extends View { private Paint mOnlinePaint; @@ -87,6 +92,7 @@ public class CPUInfoService extends Service { private String mGpuTemp; private String mBatTemp; private String mGpuFreq; + private String mGpuLoad; private boolean mDataAvail; @@ -103,17 +109,20 @@ public class CPUInfoService extends Service { mGpuTemp = parts[1]; mBatTemp = parts[2]; mGpuFreq = parts[3]; + mGpuLoad = parts[4]; - String[] cpuParts=parts[4].split("\\|"); + String[] cpuParts=parts[5].split("\\|"); for(int i=0; i 10000) { + return String.format("%.2f", temp / 1000.0f); + } if (CPU_TEMP_DIVIDER > 1) { return String.format("%.2f", temp / CPU_TEMP_DIVIDER); } else { @@ -203,33 +216,23 @@ public class CPUInfoService extends Service { return; } - final int W = mNeededWidth; final int RIGHT = getWidth()-1; - - int x = RIGHT - mPaddingRight; - int top = mPaddingTop + 2; - int bottom = mPaddingTop + mFH - 2; - int y = mPaddingTop - (int)mAscent; if(!mCpuTemp.equals("0")) { - canvas.drawText("CPU: " + getTemp(mCpuTemp) + "°C", + canvas.drawText("CPU: " + getTemp(mCpuTemp) + " °C", RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint); y += mFH; } if(!mGpuTemp.equals("0")) { - String gpuText = "GPU: " + getTemp(mGpuTemp) + "°C"; - if(!mGpuFreq.equals("0")) { - gpuText += " " + toMHzGPU(mGpuFreq); - } - canvas.drawText(gpuText, + canvas.drawText("GPU: " + getTemp(mGpuTemp) + " °C", RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint); y += mFH; } if(!mBatTemp.equals("0")) { - canvas.drawText("BAT: " + getTemp(mBatTemp) + "°C", + canvas.drawText("BAT: " + getTemp(mBatTemp) + " °C", RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint); y += mFH; } @@ -241,11 +244,17 @@ public class CPUInfoService extends Service { canvas.drawText(s, RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint); } else { - canvas.drawText("cpu" + mCpu[i] + ": offline", RIGHT-mPaddingRight-mMaxWidth, + canvas.drawText("Core " + mCpu[i] + ": offline", RIGHT-mPaddingRight-mMaxWidth, y-1, mOfflinePaint); } y += mFH; } + + if(!mGpuFreq.equals("0") || !mGpuLoad.equals("0%")) { + String gpuStats = "GPU: " + mGpuLoad + " " + mGpuFreq + " MHz"; + canvas.drawText(gpuStats, RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint); + y += mFH; + } } void updateDisplay() { @@ -254,9 +263,24 @@ public class CPUInfoService extends Service { } final int NW = mNumCpus; + int maxW = 0; + if(!mCpuTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("CPU: " + getTemp(mCpuTemp) + "°C")); + if(!mGpuTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("GPU: " + getTemp(mGpuTemp) + "°C")); + if(!mBatTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("BAT: " + getTemp(mBatTemp) + "°C")); + + for(int i=0; i 10000000) { - return (val / 1000000) + " MHz"; - } - return (val / 1000) + " MHz"; - } catch (Exception e) { - return ""; - } - } - public Handler getHandler(){ return mCurCPUHandler; } @@ -294,10 +306,14 @@ public class CPUInfoService extends Service { protected class CurCPUThread extends Thread { private boolean mInterrupt = false; private Handler mHandler; + private long[] mLastTotal = null; + private long[] mLastIdle = null; public CurCPUThread(Handler handler, int numCpus){ mHandler=handler; mNumCpus = numCpus; + mLastTotal = new long[numCpus]; + mLastIdle = new long[numCpus]; } public void interrupt() { @@ -323,19 +339,30 @@ public class CPUInfoService extends Service { String gpuFreq = CPUInfoService.readOneLine(GPU_FREQ_PATH); sb.append(gpuFreq == null ? "0" : gpuFreq).append(";"); + String gpuLoadStr = "0%"; + String gpuBusy = CPUInfoService.readOneLine(GPU_LOAD_PATH); + if (gpuBusy != null) { + gpuLoadStr = gpuBusy.replaceAll("[^0-9]", "") + "%"; + } + sb.append(gpuLoadStr).append(";"); + + String[] cpuLoads = getCpuLoad(); + for(int i=0; i= mNumCpus) continue; + + long idle = Long.parseLong(tokens[4]); + long total = 0; + for (int k=1; k 0) { + load = (int)((diffTotal - diffIdle) * 100 / diffTotal); + } + + mLastIdle[cpuId] = idle; + mLastTotal[cpuId] = total; + results[cpuId] = load + "%"; + } + reader.close(); + } catch (Exception e) { + for(int j=0; j