PerfTimer.java 1.66 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.dps.impl.ui;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PerfTimer {
    final Logger logger;
    final String name;
    long timer = 0;
    String interimName = null;
    long interimTimer = 0;

    public static PerfTimer startTimer(Object object, String name) {
        PerfTimer timer = new PerfTimer(object, name);
        timer.start();
        return timer;
    }

    private PerfTimer(Object object, String name) {
        this.name = name;
        this.logger = LoggerFactory.getLogger((String)("PERF." + object.getClass().getName()));
    }

    public void start() {
        this.timer = System.currentTimeMillis();
        this.logger.debug(this.name + " START ");
    }

    public void startInterim(String interimName) {
        if (this.interimTimer > 0) {
            this.logger.warn("Interim timer already started for " + interimName);
        }
        this.interimName = interimName;
        this.interimTimer = System.currentTimeMillis();
        this.logger.debug(this.name + ":" + this.interimName + " START ");
    }

    public void endInterim() {
        if (this.interimTimer == 0) {
            this.logger.warn("Interim timer not started");
        } else {
            this.logger.debug(this.name + ":" + this.interimName + " DONE " + (System.currentTimeMillis() - this.interimTimer) + "ms");
            this.interimTimer = 0;
        }
    }

    public void end() {
        this.logger.debug(this.name + " DONE " + (System.currentTimeMillis() - this.timer) + "ms");
    }
}