package com.ss.android.ugc.aweme.live.livehostimpl;

import X.0aP;
import X.4UV;
import X.AnonymousClass9EH;
import X.AnonymousClass9Q9;
import X.AnonymousClass9QA;
import X.AnonymousClass9V4;
import X.AnonymousClass9VF;
import X.C29588lB;
import X.C29598lC;
import X.C45499Pw;
import X.H9r;
import android.content.Context;
import android.os.BatteryManager;
import com.bytedance.android.livesdkapi.host.IHostPerformanceMonitor;
import com.bytedance.apm.l.a.a;
import com.bytedance.common.graphics.GraphicsMonitor;
import com.bytedance.covode.number.Covode;
import com.ss.b.c;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public class LiveHostPerformanceMonitor implements IHostPerformanceMonitor {
    public double LIZ;
    public JSONObject LIZIZ;
    public AnonymousClass9VF LIZJ;
    public C45499Pw LIZLLL = new C45499Pw("live_frs_tracer", true);
    public AnonymousClass9QA LJ = new AnonymousClass9QA() {
        static {
            Covode.recordClassIndex(91229);
        }

        public final void LIZ(double d) {
            LiveHostPerformanceMonitor.this.LIZ = d;
        }
    };
    public AnonymousClass9Q9 LJFF = new AnonymousClass9Q9() {
        static {
            Covode.recordClassIndex(91230);
        }

        public final void LIZ(JSONObject jSONObject) {
            LiveHostPerformanceMonitor.this.LIZIZ = jSONObject;
            LiveHostPerformanceMonitor liveHostPerformanceMonitor = LiveHostPerformanceMonitor.this;
            if (liveHostPerformanceMonitor.LIZJ != null) {
                liveHostPerformanceMonitor.LIZJ.LIZ(liveHostPerformanceMonitor.LIZ, liveHostPerformanceMonitor.LIZIZ);
                liveHostPerformanceMonitor.LIZ = 0.0d;
                liveHostPerformanceMonitor.LIZIZ = null;
            }
        }
    };

    static {
        Covode.recordClassIndex(91228);
    }

    public void onInit() {
    }

    public final void LIZLLL() {
        GraphicsMonitor.init();
    }

    public final double LJFF() {
        return GraphicsMonitor.getByteGpu();
    }

    public final void LJ() {
        try {
            GraphicsMonitor.start();
        } catch (Throwable th) {
            0aP.LIZ("ALogger", th);
        }
    }

    public final Map<String, Double> LIZ() {
        HashMap hashMap = new HashMap();
        a LIZ2 = C29588lB.LIZ();
        hashMap.put("cpu_rate", Double.valueOf(LIZ2.LIZ));
        hashMap.put("cpu_speed", Double.valueOf(LIZ2.LIZIZ));
        return hashMap;
    }

    public final void LIZJ() {
        try {
            this.LIZLLL.LIZ();
        } catch (Throwable unused) {
        }
        this.LIZLLL.LIZ(this.LJ);
        this.LIZLLL.LIZ(this.LJFF);
    }

    public final void LJI() {
        try {
            if (GraphicsMonitor.isStart()) {
                GraphicsMonitor.stop();
            }
        } catch (Throwable th) {
            0aP.LIZ("ALogger", th);
        }
    }

    public final Map<String, Long> LIZIZ() {
        HashMap hashMap = new HashMap();
        C29598lC LIZ2 = C29588lB.LIZ(AnonymousClass9EH.LJJIFFI.LIZ());
        hashMap.put("mem_java_total", Long.valueOf(LIZ2.LIZ));
        hashMap.put("mem_java_free", Long.valueOf(LIZ2.LIZIZ));
        hashMap.put("mem_java_used", Long.valueOf(LIZ2.LIZJ));
        hashMap.put("mem_pss_dalvik", Long.valueOf(LIZ2.LIZLLL));
        hashMap.put("mem_pss_native", Long.valueOf(LIZ2.LJ));
        hashMap.put("mem_pss_total", Long.valueOf(LIZ2.LJFF));
        hashMap.put("mem_graphics", Long.valueOf(LIZ2.LJI));
        hashMap.put("mem_vmsize", Long.valueOf(LIZ2.LJII));
        return hashMap;
    }

    public final void LIZ(AnonymousClass9VF r2) {
        this.LIZJ = r2;
        this.LIZLLL.LIZIZ();
    }

    public final Map<String, String> LIZ(Context context) {
        HashMap hashMap = new HashMap(4);
        if (context == null) {
            return hashMap;
        }
        hashMap.put("thor_galvanic_now", String.valueOf(c.LIZJ(context)));
        float f = -1.0f;
        BatteryManager LIZ2 = c.LIZ(context);
        if (LIZ2 != null) {
            float longProperty = (float) LIZ2.getLongProperty(3);
            if (4UV.LIZIZ() || 4UV.LIZJ()) {
                if (longProperty >= -1.0E7f && longProperty <= 1.0E7f) {
                    if (longProperty < -10000.0f) {
                        longProperty /= 1000.0f;
                    }
                    f = -longProperty;
                }
            } else if (4UV.LIZ()) {
                if (longProperty > 10000.0f) {
                    longProperty /= 1000.0f;
                }
                f = longProperty;
            } else {
                f = longProperty / 1000.0f;
            }
        }
        hashMap.put("thor_galvanic_avg", String.valueOf(f));
        hashMap.put("thor_use_battery", String.valueOf((((double) c.LIZJ(context)) * 0.5d) / 3600.0d));
        double d = -1.0d;
        BatteryManager LIZ3 = c.LIZ(context);
        if (LIZ3 != null) {
            d = (((double) LIZ3.getLongProperty(5)) / 1.0E9d) / 1000.0d;
        }
        hashMap.put("thor_energy", String.valueOf(d));
        return hashMap;
    }

    public final H9r LIZ(String str, boolean z) {
        return new AnonymousClass9V4(str, z, (byte) 0);
    }
}
