Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d45f744e authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Move proto logging to thread pool

to avoid spending the time on the call thread to perform the logging

Bug: 327381454
Test: measure performance of the log call on the call thread"
Change-Id: Ie7b97fa17ec6114bd829baf7bad3098e4565a173
parent 869ebffa
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import perfetto.protos.PerfettoTrace.ProtoLogViewerConfig.MessageData;
@@ -90,6 +92,8 @@ public class PerfettoProtoLogImpl implements IProtoLog {
    private final ViewerConfigInputStreamProvider mViewerConfigInputStreamProvider;
    private final TreeMap<String, IProtoLogGroup> mLogGroups;

    private final ExecutorService mBackgroundLoggingService = Executors.newCachedThreadPool();

    public PerfettoProtoLogImpl(String viewerConfigFilePath,
            TreeMap<String, IProtoLogGroup> logGroups) {
        this(() -> {
@@ -134,7 +138,8 @@ public class PerfettoProtoLogImpl implements IProtoLog {

        long tsNanos = SystemClock.elapsedRealtimeNanos();
        try {
            logToProto(level, group.name(), messageHash, paramsMask, args, tsNanos);
            mBackgroundLoggingService.submit(() ->
                    logToProto(level, group.name(), messageHash, paramsMask, args, tsNanos));
            if (group.isLogToLogcat()) {
                logToLogcat(group.getTag(), level, messageHash, messageString, args);
            }