Add a system to easily trace jobs.

This commit is contained in:
Greyson Parrelli
2020-12-20 01:04:03 -05:00
committed by Alan Evans
parent 4b8d02fdba
commit fcbd594def
7 changed files with 46 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();

View File

@@ -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.

View File

@@ -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()");

View File

@@ -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();

View File

@@ -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");