what-the-bank/sources/okhttp3/internal/concurrent/TaskLoggerKt.java

105 lines
3.8 KiB
Java

package okhttp3.internal.concurrent;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import o.C14957gcv;
import o.InterfaceC14890gbN;
import o.gcH;
/* loaded from: classes.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 taskQueue, InterfaceC14890gbN<String> interfaceC14890gbN) {
C14957gcv.e(task, "");
C14957gcv.e(taskQueue, "");
C14957gcv.e(interfaceC14890gbN, "");
if (TaskRunner.Companion.getLogger().isLoggable(Level.FINE)) {
log(task, taskQueue, interfaceC14890gbN.invoke());
}
}
public static final <T> T logElapsed(Task task, TaskQueue taskQueue, InterfaceC14890gbN<? extends T> interfaceC14890gbN) {
long j;
C14957gcv.e(task, "");
C14957gcv.e(taskQueue, "");
C14957gcv.e(interfaceC14890gbN, "");
boolean isLoggable = TaskRunner.Companion.getLogger().isLoggable(Level.FINE);
if (isLoggable) {
j = taskQueue.getTaskRunner$okhttp().getBackend().nanoTime();
log(task, taskQueue, "starting");
} else {
j = -1;
}
try {
T invoke = interfaceC14890gbN.invoke();
if (isLoggable) {
log(task, taskQueue, C14957gcv.c("finished run in ", (Object) formatDuration(taskQueue.getTaskRunner$okhttp().getBackend().nanoTime() - j)));
}
return invoke;
} catch (Throwable th) {
if (isLoggable) {
log(task, taskQueue, C14957gcv.c("failed a run in ", (Object) formatDuration(taskQueue.getTaskRunner$okhttp().getBackend().nanoTime() - j)));
}
throw th;
}
}
/* JADX INFO: Access modifiers changed from: private */
public static final void log(Task task, TaskQueue taskQueue, String str) {
Logger logger = TaskRunner.Companion.getLogger();
StringBuilder sb = new StringBuilder();
sb.append(taskQueue.getName$okhttp());
sb.append(' ');
gcH gch = gcH.d;
String format = String.format("%-22s", Arrays.copyOf(new Object[]{str}, 1));
C14957gcv.c((Object) format, "");
sb.append(format);
sb.append(": ");
sb.append(task.getName());
logger.fine(sb.toString());
}
public static final String formatDuration(long j) {
String obj;
if (j <= -999500000) {
StringBuilder sb = new StringBuilder();
sb.append((j - 500000000) / 1000000000);
sb.append(" s ");
obj = sb.toString();
} else if (j <= -999500) {
StringBuilder sb2 = new StringBuilder();
sb2.append((j - 500000) / 1000000);
sb2.append(" ms");
obj = sb2.toString();
} else if (j <= 0) {
StringBuilder sb3 = new StringBuilder();
sb3.append((j - 500) / 1000);
sb3.append(" µs");
obj = sb3.toString();
} else if (j < 999500) {
StringBuilder sb4 = new StringBuilder();
sb4.append((j + 500) / 1000);
sb4.append(" µs");
obj = sb4.toString();
} else if (j < 999500000) {
StringBuilder sb5 = new StringBuilder();
sb5.append((j + 500000) / 1000000);
sb5.append(" ms");
obj = sb5.toString();
} else {
StringBuilder sb6 = new StringBuilder();
sb6.append((j + 500000000) / 1000000000);
sb6.append(" s ");
obj = sb6.toString();
}
gcH gch = gcH.d;
String format = String.format("%6s", Arrays.copyOf(new Object[]{obj}, 1));
C14957gcv.c((Object) format, "");
return format;
}
}