Debug info: running time

pull/208/head
M66B 3 years ago
parent d756db14a7
commit b409f8b3b8

@ -71,6 +71,7 @@ import android.os.Debug;
import android.os.OperationCanceledException;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintJob;
@ -6190,6 +6191,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
" no=" + (tvNoEmail.getVisibility() == View.VISIBLE));
}
private Long lastCpu = null;
private Long lastTime = null;
private void updateDebugInfo() {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
@ -6199,7 +6203,21 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
long hmax = rt.maxMemory();
long nheap = Debug.getNativeHeapAllocatedSize();
int perc = Math.round(hused * 100f / hmax);
tvDebug.setText(perc + "% " + (nheap / (1024 * 1024)) + "M");
int utilization = 0;
long cpu = android.os.Process.getElapsedCpuTime();
long time = SystemClock.elapsedRealtime();
if (lastCpu != null) {
int cpuDelta = (int) (cpu - lastCpu);
int timeDelta = (int) (time - lastTime);
if (timeDelta != 0)
utilization = 100 * cpuDelta / timeDelta / rt.availableProcessors();
}
lastCpu = cpu;
lastTime = time;
tvDebug.setText(perc + "% " + (nheap / (1024 * 1024)) + "M" + " " + utilization + "%");
}
private boolean handleThreadActions(

@ -1677,6 +1677,14 @@ public class Helper {
return DateUtils.getRelativeTimeSpanString(context, millis);
}
static String formatDuration(long ms) {
int days = (int) (ms / (24 * 3600 * 1000L));
ms = ms % (24 * 3600 * 1000L);
long seconds = ms / 1000;
ms = ms % 1000;
return (days > 0 ? days + " " : "") + DateUtils.formatElapsedTime(seconds) + "." + ms;
}
static String formatNumber(Integer number, long max, NumberFormat nf) {
if (number == null)
return null;

@ -57,6 +57,7 @@ import android.os.LocaleList;
import android.os.OperationCanceledException;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.TransactionTooLargeException;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
@ -1888,7 +1889,15 @@ public class Log {
sb.append("\r\n");
sb.append(String.format("Processors: %d\r\n", Runtime.getRuntime().availableProcessors()));
int cpus = Runtime.getRuntime().availableProcessors();
sb.append(String.format("Processors: %d\r\n", cpus));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
long running = SystemClock.uptimeMillis() - android.os.Process.getStartUptimeMillis();
long cpu = android.os.Process.getElapsedCpuTime();
int util = (int) (running == 0 ? 0 : 100 * cpu / running / cpus);
sb.append(String.format("Uptime: %s CPU: %s %d%%\r\n",
Helper.formatDuration(running), Helper.formatDuration(cpu), util));
}
ActivityManager am = Helper.getSystemService(context, ActivityManager.class);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();

Loading…
Cancel
Save