package com.atlassian.stash.internal.process;

import com.atlassian.bitbucket.util.Timer;
import com.atlassian.bitbucket.util.TimerUtils;
import com.atlassian.utils.process.ExternalProcess;
import com.atlassian.utils.process.ProcessMonitor;

/**
 * {@link com.atlassian.utils.process.ProcessMonitor} implementation that adds each ExternalProcess invocation to the
 * profiling log.
 *
 * @since 2.0
 */
public class ProfilingProcessMonitor implements ProcessMonitor {
    private Timer timer;

    @Override
    public void onAfterFinished(ExternalProcess externalProcess) {
        timer.close();
    }

    @Override
    public void onBeforeStart(ExternalProcess externalProcess) {
        timer = TimerUtils.start(externalProcess.getCommandLine());
    }
}
