openllet.profiler.ResultList Maven / Gradle / Ivy
// Copyright (c) 2006 - 2008, Clark & Parsia, LLC.
// This source code is available under the terms of the Affero General Public License v3.
//
// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions.
// Questions, comments, or requests for clarification: [email protected]
package openllet.profiler;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
*
* Copyright: Copyright (c) 2007
*
*
* Company: Clark & Parsia, LLC.
*
*
* @author Evren Sirin
*/
public class ResultList
{
private final int _colCount;
private int _colWidth = 8;
private final Map>> _results = new LinkedHashMap<>();
public ResultList(final int colCount, final int colWidth)
{
this._colCount = colCount;
this._colWidth = colWidth;
}
public void addResult(final String nameParam, final Collection> currResults)
{
String name = nameParam;
name = ProfileUtils.formatFileName(name, 2 * _colWidth);
final Collection> prevResults = _results.get(name);
if (prevResults == null)
_results.put(name, currResults);
else
{
final Iterator> prev = prevResults.iterator();
final Iterator> curr = currResults.iterator();
while (prev.hasNext())
prev.next().addIteration(curr.next());
}
}
public void print()
{
printHeader(_results.values().iterator().next());
for (final Map.Entry>> entry : _results.entrySet())
{
final String name = entry.getKey();
final Collection> result = entry.getValue();
printDataset(name, result);
}
System.out.println();
}
private void printDataset(final String name, final Collection> results)
{
System.out.format("%-" + 2 * _colWidth + "s|", name);
for (final Result result : results)
{
System.out.format("%" + _colWidth + ".2f |", result.getAvgTime());
if (_colCount > 1)
System.out.format("%" + _colWidth + ".2f |", result.getAvgMemory());
}
System.out.println();
}
private void printHeader(final Collection> results)
{
System.out.println();
System.out.println();
System.out.format("%-" + (2 * _colWidth) + "s|", " ");
final int headerWidth = (_colCount * _colWidth);
for (final Result result : results)
{
String colHeader = result.getTask().toString();
if (colHeader.length() > headerWidth)
colHeader = colHeader.substring(0, headerWidth - 1) + '.';
System.out.format(" %-" + headerWidth + "s", colHeader);
for (int i = 0; i < 2 * (_colCount - 1); i++)
System.out.print(" ");
System.out.print("|");
}
System.out.println();
System.out.format("%-" + (2 * _colWidth) + "s|", " ");
for (int i = 0; i < results.size(); i++)
{
System.out.format(" %-" + _colWidth + "s|", "Time");
if (_colCount > 1)
System.out.format(" %-" + _colWidth + "s|", "Mem");
}
System.out.println();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy