mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 06:47:46 +00:00
Add a system to easily trace jobs.
This commit is contained in:

committed by
Alan Evans

parent
4b8d02fdba
commit
fcbd594def
@@ -104,6 +104,11 @@ public final class AttachmentCompressionJob extends BaseJob {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTrace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws Exception {
|
||||
Log.d(TAG, "Running for: " + attachmentId);
|
||||
|
@@ -68,6 +68,11 @@ public class AttachmentCopyJob extends BaseJob {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTrace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRun() throws Exception {
|
||||
AttachmentDatabase database = DatabaseFactory.getAttachmentDatabase(context);
|
||||
|
@@ -88,6 +88,11 @@ public final class AttachmentUploadJob extends BaseJob {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTrace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws Exception {
|
||||
Data inputData = getInputData();
|
||||
|
@@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.core.util.tracing.Tracer;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobLogger;
|
||||
@@ -21,6 +22,10 @@ public abstract class BaseJob extends Job {
|
||||
|
||||
@Override
|
||||
public @NonNull Result run() {
|
||||
if (shouldTrace()) {
|
||||
Tracer.getInstance().start(getClass().getSimpleName());
|
||||
}
|
||||
|
||||
try {
|
||||
onRun();
|
||||
return Result.success(outputData);
|
||||
@@ -35,6 +40,10 @@ public abstract class BaseJob extends Job {
|
||||
Log.w(TAG, JobLogger.format(this, "Encountered a failing exception."), e);
|
||||
return Result.failure();
|
||||
}
|
||||
} finally {
|
||||
if (shouldTrace()) {
|
||||
Tracer.getInstance().end(getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +51,13 @@ public abstract class BaseJob extends Job {
|
||||
|
||||
protected abstract boolean onShouldRetry(@NonNull Exception e);
|
||||
|
||||
/**
|
||||
* Whether or not the job should be traced with the {@link org.signal.core.util.tracing.Tracer}.
|
||||
*/
|
||||
protected boolean shouldTrace() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this job is part of a {@link Chain}, data set here will be passed as input data to the next
|
||||
* job(s) in the chain.
|
||||
|
@@ -61,6 +61,11 @@ public class DirectoryRefreshJob extends BaseJob {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTrace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws IOException {
|
||||
Log.i(TAG, "DirectoryRefreshJob.onRun()");
|
||||
|
@@ -108,6 +108,11 @@ public abstract class PushSendJob extends SendJob {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTrace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Optional<byte[]> getProfileKey(@NonNull Recipient recipient) {
|
||||
if (!recipient.resolve().isSystemContact() && !recipient.resolve().isProfileSharing()) {
|
||||
return Optional.absent();
|
||||
|
@@ -230,6 +230,11 @@ public class RetrieveProfileJob extends BaseJob {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldTrace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun() throws IOException, RetryLaterException {
|
||||
Stopwatch stopwatch = new Stopwatch("RetrieveProfile");
|
||||
|
Reference in New Issue
Block a user