Add the ability to trace methods in internal builds.

Currently only for internal builds. Use the @Trace annotation to trace
methods for viewing in Perfetto.
This commit is contained in:
Greyson Parrelli
2020-11-10 12:40:50 -05:00
committed by Cody Henthorne
parent c3b5323010
commit 0b77b33902
52 changed files with 720 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
package org.thoughtcrime.securesms.logsubmit;
import android.content.Context;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.tracing.Tracer;
import org.thoughtcrime.securesms.util.Base64;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
public class LogSectionTrace implements LogSection {
@Override
public @NonNull String getTitle() {
return "TRACE";
}
@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream compressedStream = new GZIPOutputStream(outputStream))
{
compressedStream.write(Tracer.getInstance().serialize());
compressedStream.flush();
compressedStream.close();
outputStream.flush();
outputStream.close();
return Base64.encodeBytes(outputStream.toByteArray());
} catch (IOException e) {
return "";
}
}
}

View File

@@ -23,6 +23,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class SubmitDebugLogAdapter extends RecyclerView.Adapter<SubmitDebugLogAdapter.LineViewHolder> {
private static final int MAX_LINE_LENGTH = 1000;
private final List<LogLine> lines;
private final ScrollManager scrollManager;
private final Listener listener;
@@ -68,6 +70,7 @@ public class SubmitDebugLogAdapter extends RecyclerView.Adapter<SubmitDebugLogAd
this.lines.addAll(lines);
this.longestLine = Stream.of(lines).reduce(0, (currentMax, line) -> Math.max(currentMax, line.getText().length()));
this.longestLine = Math.min(longestLine, MAX_LINE_LENGTH);
notifyDataSetChanged();
}
@@ -122,7 +125,9 @@ public class SubmitDebugLogAdapter extends RecyclerView.Adapter<SubmitDebugLogAd
void bind(@NonNull LogLine line, int longestLine, boolean editing, @NonNull ScrollManager scrollManager, @NonNull Listener listener) {
Context context = itemView.getContext();
if (line.getText().length() < longestLine) {
if (line.getText().length() > longestLine) {
text.setText(line.getText().substring(0, longestLine));
} else if (line.getText().length() < longestLine) {
text.setText(padRight(line.getText(), longestLine));
} else {
text.setText(line.getText());

View File

@@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.logsubmit.util.Scrubber;
import org.thoughtcrime.securesms.net.StandardUserAgentInterceptor;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.tracing.Tracer;
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
import org.whispersystems.libsignal.util.guava.Optional;
@@ -60,6 +61,9 @@ public class SubmitDebugLogRepository {
add(new LogSectionCapabilities());
add(new LogSectionFeatureFlags());
add(new LogSectionPermissions());
if (Tracer.getInstance().isEnabled()) {
add(new LogSectionTrace());
}
add(new LogSectionThreads());
add(new LogSectionLogcat());
add(new LogSectionLogger());