1package com.bumptech.glide.util;
2
3import android.annotation.TargetApi;
4import android.os.Build;
5import android.os.SystemClock;
6
7/**
8 * A class for logging elapsed real time in millis.
9 */
10public final class LogTime {
11    private static final double MILLIS_MULTIPLIER =
12            Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT ? 1d / Math.pow(10, 6) : 1d;
13
14    private LogTime() {
15        // Utility class.
16    }
17
18    /**
19     * Returns the current time in either millis or nanos depending on the api level to be used with
20     * {@link #getElapsedMillis(long)}.
21     */
22    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
23    public static long getLogTime() {
24        if (Build.VERSION_CODES.JELLY_BEAN_MR1 <= Build.VERSION.SDK_INT) {
25            return SystemClock.elapsedRealtimeNanos();
26        } else {
27            return System.currentTimeMillis();
28        }
29    }
30
31    /**
32     * Returns the time elapsed since the given logTime in millis.
33     *
34     * @param logTime The start time of the event.
35     */
36    public static double getElapsedMillis(long logTime) {
37        return (getLogTime() - logTime) * MILLIS_MULTIPLIER;
38    }
39}
40