return information about the plotted sequences
this information can be used for tests
This commit is contained in:
@@ -2,6 +2,9 @@ package org.lucares.recommind.logs;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataSeries {
|
||||
public static final Comparator<? super DataSeries> BY_VALUES = (a, b) -> {
|
||||
@@ -46,4 +49,16 @@ public class DataSeries {
|
||||
public int getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public static Map<String, Integer> toMap(final List<DataSeries> dataSeries) {
|
||||
final Map<String, Integer> result = new LinkedHashMap<>();
|
||||
|
||||
for (final DataSeries dataSerie : dataSeries) {
|
||||
|
||||
result.put(dataSerie.getTitle(), dataSerie.values);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GnuplotFileGenerator {
|
||||
|
||||
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
||||
|
||||
appendfln(result, "set output \"%s\"", settings.getOutput().getAbsolutePath());
|
||||
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath());
|
||||
appendf(result, "plot ");
|
||||
|
||||
for (final DataSeries dataSerie : dataSeries) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.lucares.recommind.logs;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class GnuplotSettings {
|
||||
private String terminal = "png";
|
||||
@@ -21,12 +21,12 @@ public class GnuplotSettings {
|
||||
private String ylabel = "Duration in ms";
|
||||
|
||||
// set output "datausage.png"
|
||||
private File output = new File("/tmp/out.png");
|
||||
private final Path output;
|
||||
|
||||
// set xtics rotate by 80
|
||||
private int rotateXAxisLabel = -80;
|
||||
|
||||
public GnuplotSettings(final File output) {
|
||||
public GnuplotSettings(final Path output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@@ -102,14 +102,10 @@ public class GnuplotSettings {
|
||||
this.ylabel = ylabel;
|
||||
}
|
||||
|
||||
public File getOutput() {
|
||||
public Path getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setOutput(final File output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.lucares.recommind.logs;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class PlotResult {
|
||||
private final Path imageName;
|
||||
private final List<DataSeries> dataSeries;
|
||||
|
||||
public PlotResult(final Path imageName, final List<DataSeries> dataSeries) {
|
||||
super();
|
||||
this.imageName = imageName;
|
||||
this.dataSeries = dataSeries;
|
||||
}
|
||||
|
||||
public Path getImageName() {
|
||||
return imageName;
|
||||
}
|
||||
|
||||
public List<DataSeries> getDataSeries() {
|
||||
return dataSeries;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -29,7 +28,6 @@ import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.plot.api.Limit;
|
||||
import org.lucares.pdb.plot.api.PlotSettings;
|
||||
import org.lucares.performance.db.FileUtils;
|
||||
import org.lucares.performance.db.Grouping;
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -59,7 +57,7 @@ public class Plotter {
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
public File plot(final PlotSettings plotSettings) throws InternalPlottingException {
|
||||
public PlotResult plot(final PlotSettings plotSettings) throws InternalPlottingException {
|
||||
|
||||
final String tmpSubDir = uniqueDirectoryName();
|
||||
final Path tmpDir = tmpBaseDir.resolve(tmpSubDir);
|
||||
@@ -102,14 +100,15 @@ public class Plotter {
|
||||
|
||||
sortAndLimit(dataSeries, plotSettings);
|
||||
|
||||
final File outputFile = File.createTempFile("out", ".png", outputDir.toFile());
|
||||
final Path outputFile = Files.createTempFile(outputDir, "out", ".png");
|
||||
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);
|
||||
final GnuplotSettings gnuplotSettings = new GnuplotSettings(outputFile);
|
||||
gnuplotSettings.setHeight(height);
|
||||
gnuplotSettings.setWidth(width);
|
||||
gnuplotSettings.setFormatX(getFormatX(minDate, maxDate));
|
||||
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||
return outputFile;
|
||||
|
||||
return new PlotResult(outputFile.getFileName(), dataSeries);
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Plotting was interrupted.");
|
||||
@@ -176,34 +175,6 @@ public class Plotter {
|
||||
|
||||
}
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
final Path dataDirectory = Paths.get(args[0]);
|
||||
final Path outputDirectory = Paths.get(args[1]);
|
||||
final String query = args[2];
|
||||
final Path tmpBaseDir = Paths.get(args[0], "tmp", "gnuplot");
|
||||
Files.createDirectories(tmpBaseDir);
|
||||
Files.createDirectories(outputDirectory);
|
||||
try {
|
||||
|
||||
try (PerformanceDb db = new PerformanceDb(dataDirectory)) {
|
||||
final Plotter plotter = new Plotter(db, tmpBaseDir, outputDirectory);
|
||||
// query, 1600, 1200, Grouping.NO_GROUPING
|
||||
|
||||
final PlotSettings plotSettings = new PlotSettings();
|
||||
plotSettings.setQuery(query);
|
||||
plotSettings.setWidth(1600);
|
||||
plotSettings.setHeight(1200);
|
||||
plotSettings.setGroupBy(Grouping.NO_GROUPING);
|
||||
|
||||
final File image = plotter.plot(plotSettings);
|
||||
LOGGER.trace("plotted image: {}", image);
|
||||
}
|
||||
|
||||
} finally {
|
||||
FileUtils.delete(tmpBaseDir);
|
||||
}
|
||||
}
|
||||
|
||||
private static CsvSummary toCsv(final Stream<Entry> entries, final File dataFile, final OffsetDateTime dateFrom,
|
||||
final OffsetDateTime dateTo) throws IOException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user