package com.google.firebase.perf.util; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; import java.util.concurrent.TimeUnit; /* loaded from: classes3.dex */ public class Timer implements Parcelable { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { // from class: com.google.firebase.perf.util.Timer.1 @Override // android.os.Parcelable.Creator public Timer createFromParcel(Parcel parcel) { return new Timer(parcel); } @Override // android.os.Parcelable.Creator public Timer[] newArray(int i) { return new Timer[i]; } }; public long elapsedRealtimeMicros; public long wallClockMicros; @Override // android.os.Parcelable public int describeContents() { return 0; } public long getMicros() { return this.wallClockMicros; } public static Timer ofElapsedRealtime(long j) { long micros = TimeUnit.MILLISECONDS.toMicros(j); return new Timer(wallClockMicros() + (micros - elapsedRealtimeMicros()), micros); } public static long wallClockMicros() { return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); } public static long elapsedRealtimeMicros() { return TimeUnit.NANOSECONDS.toMicros(SystemClock.elapsedRealtimeNanos()); } public Timer() { this(wallClockMicros(), elapsedRealtimeMicros()); } public Timer(long j, long j2) { this.wallClockMicros = j; this.elapsedRealtimeMicros = j2; } public Timer(Parcel parcel) { this(parcel.readLong(), parcel.readLong()); } public void reset() { this.wallClockMicros = wallClockMicros(); this.elapsedRealtimeMicros = elapsedRealtimeMicros(); } public long getDurationMicros() { return getDurationMicros(new Timer()); } public long getDurationMicros(Timer timer) { return timer.elapsedRealtimeMicros - this.elapsedRealtimeMicros; } public long getCurrentTimestampMicros() { return this.wallClockMicros + getDurationMicros(); } @Override // android.os.Parcelable public void writeToParcel(Parcel parcel, int i) { parcel.writeLong(this.wallClockMicros); parcel.writeLong(this.elapsedRealtimeMicros); } }