mirror of https://github.com/M66B/FairEmail.git
Improved task logging
This commit is contained in:
parent
0a8d831bdc
commit
13d52b806e
|
@ -56,6 +56,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
private long started;
|
private long started;
|
||||||
private boolean reported;
|
private boolean reported;
|
||||||
private boolean interrupted;
|
private boolean interrupted;
|
||||||
|
private Lifecycle.State state;
|
||||||
private Future<?> future;
|
private Future<?> future;
|
||||||
private ExecutorService localExecutor;
|
private ExecutorService localExecutor;
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Lifecycle.State state = owner.getLifecycle().getCurrentState();
|
state = owner.getLifecycle().getCurrentState();
|
||||||
if (state.equals(Lifecycle.State.DESTROYED)) {
|
if (state.equals(Lifecycle.State.DESTROYED)) {
|
||||||
// No delivery
|
// No delivery
|
||||||
cleanup(context);
|
cleanup(context);
|
||||||
|
@ -195,7 +196,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||||
public void onAny() {
|
public void onAny() {
|
||||||
Lifecycle.State state = owner.getLifecycle().getCurrentState();
|
state = owner.getLifecycle().getCurrentState();
|
||||||
if (state.equals(Lifecycle.State.DESTROYED)) {
|
if (state.equals(Lifecycle.State.DESTROYED)) {
|
||||||
Log.i("Destroyed task " + name);
|
Log.i("Destroyed task " + name);
|
||||||
owner.getLifecycle().removeObserver(this);
|
owner.getLifecycle().removeObserver(this);
|
||||||
|
@ -275,20 +276,24 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTaskCount(Context context) {
|
private void updateTaskCount(Context context) {
|
||||||
|
// Check tasks
|
||||||
long now = new Date().getTime();
|
long now = new Date().getTime();
|
||||||
synchronized (tasks) {
|
synchronized (tasks) {
|
||||||
for (SimpleTask task : tasks) {
|
for (SimpleTask task : tasks)
|
||||||
|
if (!BuildConfig.PLAY_STORE_RELEASE ||
|
||||||
|
(task.future != null && !task.future.isDone())) {
|
||||||
long elapsed = now - task.started;
|
long elapsed = now - task.started;
|
||||||
if (elapsed > CANCEL_AFTER && !task.interrupted && task.started > 0) {
|
if (elapsed > CANCEL_AFTER && !task.interrupted) {
|
||||||
task.interrupted = true;
|
task.interrupted = true;
|
||||||
if (task.future != null && !task.future.isDone())
|
if (task.future != null && !task.future.isDone()) {
|
||||||
|
Log.e("Interrupting task " + task +
|
||||||
|
" tasks=" + getCountLocked() + "/" + tasks.size());
|
||||||
task.future.cancel(true);
|
task.future.cancel(true);
|
||||||
|
}
|
||||||
} else if (elapsed > REPORT_AFTER && !task.reported) {
|
} else if (elapsed > REPORT_AFTER && !task.reported) {
|
||||||
task.reported = true;
|
task.reported = true;
|
||||||
Log.e("Long running task " + task.name +
|
Log.e("Long running task " + task +
|
||||||
" elapsed=" + (task.started == 0 ? null : elapsed / 1000) +
|
" tasks=" + getCountLocked() + "/" + tasks.size());
|
||||||
" done=" + (task.future == null ? null : task.future.isDone()) +
|
|
||||||
" cancelled=" + (task.future == null ? null : task.future.isCancelled()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,17 +324,22 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
|
||||||
return name +
|
return name +
|
||||||
" elapsed=" + (started == 0 ? null : elapsed / 1000) +
|
" elapsed=" + (started == 0 ? null : elapsed / 1000) +
|
||||||
" done=" + (future == null ? null : future.isDone()) +
|
" done=" + (future == null ? null : future.isDone()) +
|
||||||
" cancelled=" + (future == null ? null : future.isCancelled());
|
" cancelled=" + (future == null ? null : future.isCancelled() +
|
||||||
|
" state=" + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getCount() {
|
static int getCount() {
|
||||||
int executing = 0;
|
|
||||||
synchronized (tasks) {
|
synchronized (tasks) {
|
||||||
|
return getCountLocked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getCountLocked() {
|
||||||
|
int executing = 0;
|
||||||
for (SimpleTask task : tasks)
|
for (SimpleTask task : tasks)
|
||||||
if (task.count &&
|
if (task.count &&
|
||||||
task.future != null && !task.future.isDone())
|
task.future != null && !task.future.isDone())
|
||||||
executing++;
|
executing++;
|
||||||
}
|
|
||||||
return executing;
|
return executing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue