Update logging to be size-limited and more performant.

This commit is contained in:
Greyson Parrelli
2021-07-23 07:39:16 -04:00
parent 3c748b2df6
commit 15a5f5966d
18 changed files with 253 additions and 167 deletions

View File

@@ -18,4 +18,11 @@ interface LogSection {
* one line at a time.
*/
@NonNull CharSequence getContent(@NonNull Context context);
/**
* Whether or not this section has content.
*/
default boolean hasContent() {
return true;
}
}

View File

@@ -18,4 +18,9 @@ public class LogSectionLoggerHeader implements LogSection {
public @NonNull CharSequence getContent(@NonNull Context context) {
return "";
}
@Override
public boolean hasContent() {
return false;
}
}

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -24,14 +25,19 @@ import org.thoughtcrime.securesms.logsubmit.util.Scrubber;
import org.thoughtcrime.securesms.net.StandardUserAgentInterceptor;
import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.util.ByteUnit;
import org.thoughtcrime.securesms.util.Stopwatch;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.util.guava.Optional;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.zip.GZIPOutputStream;
@@ -135,6 +141,8 @@ public class SubmitDebugLogRepository {
}
try {
Stopwatch stopwatch = new Stopwatch("log-upload");
ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
Uri gzipUri = BlobProvider.getInstance()
.forData(new ParcelFileDescriptor.AutoCloseInputStream(fds[0]), 0)
@@ -145,15 +153,19 @@ public class SubmitDebugLogRepository {
gzipOutput.write(prefixStringBuilder.toString().getBytes());
stopwatch.split("front-matter");
try (LogDatabase.Reader reader = LogDatabase.getInstance(context).getAllBeforeTime(untilTime)) {
while (reader.hasNext()) {
gzipOutput.write(Scrubber.scrub(reader.next()).toString().getBytes());
gzipOutput.write(reader.next().getBytes());
gzipOutput.write("\n".getBytes());
}
}
StreamUtil.close(gzipOutput);
stopwatch.split("body");
String logUrl = uploadContent("application/gzip", new RequestBody() {
@Override
public @NonNull MediaType contentType() {
@@ -171,6 +183,9 @@ public class SubmitDebugLogRepository {
}
});
stopwatch.split("upload");
stopwatch.stop(TAG);
BlobProvider.getInstance().delete(context, gzipUri);
return Optional.of(logUrl);
@@ -258,14 +273,16 @@ public class SubmitDebugLogRepository {
List<LogLine> out = new ArrayList<>();
out.add(new SimpleLogLine(formatTitle(section.getTitle(), maxTitleLength), LogLine.Style.NONE, LogLine.Placeholder.NONE));
CharSequence content = Scrubber.scrub(section.getContent(context));
if (section.hasContent()) {
CharSequence content = Scrubber.scrub(section.getContent(context));
List<LogLine> lines = Stream.of(Pattern.compile("\\n").split(content))
.map(s -> new SimpleLogLine(s, LogStyleParser.parseStyle(s), LogStyleParser.parsePlaceholderType(s)))
.map(line -> (LogLine) line)
.toList();
List<LogLine> lines = Stream.of(Pattern.compile("\\n").split(content))
.map(s -> new SimpleLogLine(s, LogStyleParser.parseStyle(s), LogStyleParser.parsePlaceholderType(s)))
.map(line -> (LogLine) line)
.toList();
out.addAll(lines);
out.addAll(lines);
}
Log.d(TAG, "[" + section.getTitle() + "] Took " + (System.currentTimeMillis() - startTime) + " ms");

View File

@@ -13,6 +13,7 @@ import org.signal.paging.PagedData;
import org.signal.paging.PagingConfig;
import org.signal.paging.PagingController;
import org.signal.paging.ProxyPagingController;
import org.thoughtcrime.securesms.database.LogDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.whispersystems.libsignal.util.guava.Optional;
@@ -42,6 +43,8 @@ public class SubmitDebugLogViewModel extends ViewModel {
repo.getPrefixLogLines(staticLines -> {
this.staticLines.addAll(staticLines);
LogDatabase.getInstance(ApplicationDependencies.getApplication()).trimToSize();
LogDataSource dataSource = new LogDataSource(ApplicationDependencies.getApplication(), staticLines, firstViewTime);
PagingConfig config = new PagingConfig.Builder().setPageSize(100)
.setBufferPages(3)