All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.epsilon.eol.launch.ProfilableIEolModule Maven / Gradle / Ivy

The newest version!
/*********************************************************************
 * Copyright (c) 2018 The University of York.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.epsilon.eol.launch;

import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.eclipse.epsilon.eol.IEolModule;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.function.*;
import org.eclipse.epsilon.common.util.profiling.*;

/**
 * Convenience interface for profiling methods in an {@linkplain IEolModule}.
 * @author Sina Madani
 * @since 1.6
 */
public interface ProfilableIEolModule extends IEolModule {
	
	Collection getProfiledStages();
	
	default void profileExecution(Consumer exceptionHandler) {
		try {
			profileExecution();
		}
		catch (EolRuntimeException | RuntimeException rx) {
			exceptionHandler.accept(EolRuntimeException.findCause(rx));
		}
	}
	
	default void addProfileInfo(String stage, long nanos, long memory) {
		BenchmarkUtils.addProfileInfo(getProfiledStages(), stage, nanos, memory);
	}
	
	default Object profileExecution() throws EolRuntimeException {
		final String stage = "executeImpl";
		Object result = profileExecutionStage(stage, this::execute);
		BenchmarkUtils.removeGCTimeFromStage(getProfiledStages(), stage);
		return result;
	}
	
	// UNCHECKED
	
	default  R profileExecutionStage(String description, Function code, T argument) {
		return BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code, argument);
	}
	default  R profileExecutionStage(String description, Supplier code) {
		return BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code);
	}
	default  void profileExecutionStage(String description, Consumer code, T argument) {
		BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code, argument);
	}
	default void profileExecutionStage(String description, Runnable code) {
		BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code);
	}
	
	// CHECKED
	
	default  R profileExecutionStage(String description, CheckedEolFunction code, T argument) throws EolRuntimeException {
		return BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code, argument);
	}
	default  R profileExecutionStage(String description, CheckedEolSupplier code) throws EolRuntimeException {
		return BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code);
	}
	default  void profileExecutionStage(String description, CheckedEolConsumer code, T argument) throws EolRuntimeException {
		BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code, argument);
	}
	default void profileExecutionStage(String description, CheckedEolRunnable code) throws EolRuntimeException {
		BenchmarkUtils.profileExecutionStage(getProfiledStages(), description, code);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy