Rabbit-R1/switch port/java/sources/okhttp3/internal/concurrent/TaskLoggerKt.java
2024-05-21 17:08:36 -04:00

91 lines
5.1 KiB
Java

package okhttp3.internal.concurrent;
import androidx.exifinterface.media.ExifInterface;
import io.sentry.HttpStatusCodeRange;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import kotlin.Metadata;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.InlineMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.StringCompanionObject;
/* compiled from: TaskLogger.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000*\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0004\u001a\u000e\u0010\u0000\u001a\u00020\u00012\u0006\u0010\u0002\u001a\u00020\u0003\u001a \u0010\u0004\u001a\u00020\u00052\u0006\u0010\u0006\u001a\u00020\u00072\u0006\u0010\b\u001a\u00020\t2\u0006\u0010\n\u001a\u00020\u0001H\u0002\u001a5\u0010\u000b\u001a\u0002H\f\"\u0004\b\u0000\u0010\f2\u0006\u0010\u0006\u001a\u00020\u00072\u0006\u0010\b\u001a\u00020\t2\f\u0010\r\u001a\b\u0012\u0004\u0012\u0002H\f0\u000eH\u0080\\u0001\u0000¢\u0006\u0002\u0010\u000f\u001a*\u0010\u0010\u001a\u00020\u00052\u0006\u0010\u0006\u001a\u00020\u00072\u0006\u0010\b\u001a\u00020\t2\f\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\u00010\u000eH\u0080\\u0001\u0000\u0082\u0002\u0007\n\u0005\b\u009920\u0001¨\u0006\u0012"}, d2 = {"formatDuration", "", "ns", "", "log", "", "task", "Lokhttp3/internal/concurrent/Task;", "queue", "Lokhttp3/internal/concurrent/TaskQueue;", "message", "logElapsed", ExifInterface.GPS_DIRECTION_TRUE, "block", "Lkotlin/Function0;", "(Lokhttp3/internal/concurrent/Task;Lokhttp3/internal/concurrent/TaskQueue;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;", "taskLog", "messageBlock", "okhttp"}, k = 2, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class TaskLoggerKt {
public static final /* synthetic */ void access$log(Task task, TaskQueue taskQueue, String str) {
log(task, taskQueue, str);
}
public static final void taskLog(Task task, TaskQueue queue, Function0<String> messageBlock) {
Intrinsics.checkNotNullParameter(task, "task");
Intrinsics.checkNotNullParameter(queue, "queue");
Intrinsics.checkNotNullParameter(messageBlock, "messageBlock");
if (TaskRunner.INSTANCE.getLogger().isLoggable(Level.FINE)) {
log(task, queue, messageBlock.invoke());
}
}
public static final <T> T logElapsed(Task task, TaskQueue queue, Function0<? extends T> block) {
long j;
Intrinsics.checkNotNullParameter(task, "task");
Intrinsics.checkNotNullParameter(queue, "queue");
Intrinsics.checkNotNullParameter(block, "block");
boolean isLoggable = TaskRunner.INSTANCE.getLogger().isLoggable(Level.FINE);
if (isLoggable) {
j = queue.getTaskRunner().getBackend().nanoTime();
log(task, queue, "starting");
} else {
j = -1;
}
try {
T invoke = block.invoke();
InlineMarker.finallyStart(1);
if (isLoggable) {
log(task, queue, "finished run in " + formatDuration(queue.getTaskRunner().getBackend().nanoTime() - j));
}
InlineMarker.finallyEnd(1);
return invoke;
} catch (Throwable th) {
InlineMarker.finallyStart(1);
if (isLoggable) {
log(task, queue, "failed a run in " + formatDuration(queue.getTaskRunner().getBackend().nanoTime() - j));
}
InlineMarker.finallyEnd(1);
throw th;
}
}
/* JADX INFO: Access modifiers changed from: private */
public static final void log(Task task, TaskQueue taskQueue, String str) {
Logger logger = TaskRunner.INSTANCE.getLogger();
StringBuilder append = new StringBuilder().append(taskQueue.getName()).append(' ');
StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
String format = String.format("%-22s", Arrays.copyOf(new Object[]{str}, 1));
Intrinsics.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)");
logger.fine(append.append(format).append(": ").append(task.getName()).toString());
}
public static final String formatDuration(long j) {
String str;
if (j <= -999500000) {
str = ((j - 500000000) / 1000000000) + " s ";
} else if (j <= -999500) {
str = ((j - 500000) / 1000000) + " ms";
} else if (j <= 0) {
str = ((j - HttpStatusCodeRange.DEFAULT_MIN) / 1000) + " µs";
} else if (j < 999500) {
str = ((j + HttpStatusCodeRange.DEFAULT_MIN) / 1000) + " µs";
} else if (j < 999500000) {
str = ((j + 500000) / 1000000) + " ms";
} else {
str = ((j + 500000000) / 1000000000) + " s ";
}
StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE;
String format = String.format("%6s", Arrays.copyOf(new Object[]{str}, 1));
Intrinsics.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)");
return format;
}
}