package com.bytedance.ttnet.diagnosis;

import X.C0142R5m;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;

public class TTGameDiagnosisService {
    public static final String TAG = TTGameDiagnosisService.class.getSimpleName();
    public static volatile TTGameDiagnosisService sInstance = null;
    public IDiagnosisCallback mDiagnosisCallback = C0142R5m.LIZ;
    public volatile boolean mIsMonitoring;
    public IDiagnosisRequest mRequest;

    public boolean isMonitoring() {
        return this.mIsMonitoring;
    }

    public void monitorEnd() {
        monitorEnd((String) null);
    }

    static {
        Covode.recordClassIndex(38900);
    }

    public static TTGameDiagnosisService inst() {
        MethodCollector.i(5148);
        if (sInstance == null) {
            synchronized (TTGameDiagnosisService.class) {
                try {
                    if (sInstance == null) {
                        sInstance = new TTGameDiagnosisService();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(5148);
                    throw th;
                }
            }
        }
        TTGameDiagnosisService tTGameDiagnosisService = sInstance;
        MethodCollector.o(5148);
        return tTGameDiagnosisService;
    }

    public void doDiagnosisDuringGaming(String str) {
        MethodCollector.i(5274);
        synchronized (this) {
            try {
                if (this.mIsMonitoring) {
                    this.mRequest.doExtraCommand("diagnosis", str);
                    MethodCollector.o(5274);
                }
            } finally {
                MethodCollector.o(5274);
            }
        }
    }

    public void monitorEnd(String str) {
        MethodCollector.i(5215);
        synchronized (this) {
            try {
                if (this.mIsMonitoring) {
                    if (str != null) {
                        this.mRequest.doExtraCommand("extra_info", str);
                    }
                    this.mRequest.doExtraCommand("finish", "");
                    this.mIsMonitoring = false;
                    MethodCollector.o(5215);
                }
            } finally {
                MethodCollector.o(5215);
            }
        }
    }

    public void monitorBegin(String str, String str2) {
        MethodCollector.i(5212);
        synchronized (this) {
            try {
                if (!this.mIsMonitoring) {
                    IDiagnosisRequest createRequest = TTNetDiagnosisService.createRequest(4, str, 0, Integer.MAX_VALUE);
                    this.mRequest = createRequest;
                    createRequest.start(this.mDiagnosisCallback);
                    this.mRequest.doExtraCommand("extra_info", str2);
                    this.mIsMonitoring = true;
                    MethodCollector.o(5212);
                }
            } finally {
                MethodCollector.o(5212);
            }
        }
    }
}
