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

cz.cuni.mff.d3s.spl.data.readers.PlainDataReader Maven / Gradle / Ivy

Go to download

Stochastice Performance Logic is a formalism for capturing performance assumptions. It is, for example, possible to capture assumption that newer version of a function bar is faster than the previous version or that library foobar is faster than library barfoo when rendering antialiased text. The purpose of this framework is to allow evaluation of SPL formulas inside Java applications.

There is a newer version: 1.0.4
Show newest version
package cz.cuni.mff.d3s.spl.data.readers;

import cz.cuni.mff.d3s.spl.data.DataInfo;
import cz.cuni.mff.d3s.spl.data.DataSource;
import cz.cuni.mff.d3s.spl.data.Revision;
import cz.cuni.mff.d3s.spl.utils.Factory;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Data reader from plain text formats. See readData() documentation for
 * more info about requested data format, hierarchical structure and revision
 * reader requirements.
 */
public class PlainDataReader implements DataReader {
	/**
	 * Revision reader instance.
	 */
	private T reader;

	/**
	 * Constructor which creates revision reader instance.
	 *
	 * @param readerFactory Factory for creating instance of revision reader.
	 *                      The instance must be of the same type as generic
	 *                      type T.
	 */
	public PlainDataReader(Factory readerFactory) {
		reader = readerFactory.getInstance();
	}

	/**
	 * Reads multiple revision data from files. Each argument is directory containing
	 * multiple files, one file per benchmark run. Runs in each directory are joined
	 * to a single revision. Revision order preserves input arguments order. Revision
	 * name is set as corresponding directory name. RevisionReader of T type is expected
	 * to return map with "default" key and single DataSource value.
	 *
	 * @param args Array of 1 string with path to root directory of measured data.
	 * @return Map with name of measured unit as key and list of revisions for that
	 *          unit as value.
	 */
	@Override
	public Map> readData(String[] args) throws ReaderException {
		Map> data = new HashMap<>();
		data.put(DataInfo.defaultInstance, new LinkedList<>());

		for (String dirname : args) {
			File dir = new File(dirname);

			System.out.printf("Reading data from %s...", dirname);
			Map revision = reader.readRevision(dir.listFiles());
			System.out.printf(" ok, %d run(s).\n", revision.get(DataInfo.defaultInstance).makeSnapshot().getRunCount());

			data.get(DataInfo.defaultInstance).add(new Revision(dir.getName(), revision.get(DataInfo.defaultInstance)));
		}

		return data;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy