ProfilerUtil.java 1.33 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.cq.dam.s7imaging.impl;

public class ProfilerUtil {
    private long processStart = 0;
    private long methodStart = 0;
    private StringBuilder logBuffer = new StringBuilder();

    private void startTotalProcess() {
        if (this.processStart == 0) {
            this.processStart = System.currentTimeMillis();
        }
    }

    public void start(String method) {
        this.startTotalProcess();
        boolean result = this.closeMethod();
        if (result) {
            this.logBuffer.append(",");
        }
        this.logBuffer.append(" ").append(method).append(":");
        this.methodStart = System.currentTimeMillis();
    }

    private boolean closeMethod() {
        if (this.methodStart > 0) {
            this.logBuffer.append(System.currentTimeMillis() - this.methodStart).append(" ms");
            return true;
        }
        return false;
    }

    private void closeProcess() {
        if (this.processStart > 0) {
            this.logBuffer.append(" Total:").append(System.currentTimeMillis() - this.processStart).append(" ms");
        }
    }

    public String print() {
        boolean result = this.closeMethod();
        if (result) {
            this.logBuffer.append(",");
        }
        this.closeProcess();
        return this.logBuffer.toString();
    }
}