Search in sources :

Example 1 with CsvSampleWriter

use of org.apache.jmeter.report.core.CsvSampleWriter in project jmeter by apache.

the class ExternalSampleSorter method sortAndDump.

private File sortAndDump(final List<Sample> samples, final SampleMetadata sampleMetadata) {
    long start = 0;
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): Sorting " + samples.size() + " samples...");
        start = System.currentTimeMillis();
    }
    final List<Sample> sortedSamples = sortSamplesParallel(samples);
    if (sortedSamples.size() != samples.size()) {
        throw new SampleException("sort failed ! " + sortedSamples.size() + " != " + samples.size());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): in " + (System.currentTimeMillis() - start) / 1000f + " s. Sorted  " + samples.size() + " samples.");
    }
    File out = getChunkFile();
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): Dumping chunk " + out);
        start = System.currentTimeMillis();
    }
    try (CsvSampleWriter csvWriter = new CsvSampleWriter(out, sampleMetadata)) {
        for (Sample sample : sortedSamples) {
            csvWriter.write(sample);
            chunkedSampleCount.incrementAndGet();
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): in " + (System.currentTimeMillis() - start) / 1000f + " s : Dumped chunk " + out.getAbsolutePath());
    }
    return out;
}
Also used : SampleException(org.apache.jmeter.report.core.SampleException) Sample(org.apache.jmeter.report.core.Sample) CsvSampleWriter(org.apache.jmeter.report.core.CsvSampleWriter) File(java.io.File) CsvFile(org.apache.jmeter.report.core.CsvFile)

Example 2 with CsvSampleWriter

use of org.apache.jmeter.report.core.CsvSampleWriter in project jmeter by apache.

the class SampleWriterConsumer method startConsuming.

@Override
public void startConsuming() {
    if (outputFile == null) {
        File wd = getWorkingDirectory();
        wd.mkdir();
        if (LOG.isInfoEnabled()) {
            LOG.info("startConsuming(): No output file set, writing to work directory :" + wd.getAbsolutePath());
        }
        outputFile = new File(wd, "samples.csv");
    }
    outputFile.getParentFile().mkdirs();
    channelsCount = getConsumedChannelCount();
    csvWriters = new CsvSampleWriter[channelsCount];
    for (int i = 0; i < channelsCount; i++) {
        csvWriters[i] = new CsvSampleWriter(getOutputFile(i), getConsumedMetadata(i));
        if (shouldWriteHeader) {
            csvWriters[i].writeHeader();
        }
    }
}
Also used : CsvSampleWriter(org.apache.jmeter.report.core.CsvSampleWriter) File(java.io.File)

Example 3 with CsvSampleWriter

use of org.apache.jmeter.report.core.CsvSampleWriter in project jmeter by apache.

the class ExternalSampleSorter method mergeFiles.

private void mergeFiles(SampleMetadata metadata, File left, File right, File out, boolean writeHeader) {
    if (out == null) {
        out = getChunkFile();
    }
    try (CsvSampleWriter csvWriter = new CsvSampleWriter(out, metadata);
        CsvSampleReader l = new CsvSampleReader(left, metadata);
        CsvSampleReader r = new CsvSampleReader(right, metadata)) {
        if (writeHeader) {
            csvWriter.writeHeader();
        }
        while (l.hasNext() || r.hasNext()) {
            if (l.hasNext() && r.hasNext()) {
                Sample firstLeft = l.peek();
                Sample firstRight = r.peek();
                if (leftBeforeRight(firstLeft, firstRight)) {
                    csvWriter.write(firstLeft);
                    l.readSample();
                } else {
                    csvWriter.write(firstRight);
                    r.readSample();
                }
            } else if (l.hasNext()) {
                csvWriter.write(l.readSample());
            } else if (r.hasNext()) {
                csvWriter.write(r.readSample());
            }
        }
    }
}
Also used : Sample(org.apache.jmeter.report.core.Sample) CsvSampleWriter(org.apache.jmeter.report.core.CsvSampleWriter) CsvSampleReader(org.apache.jmeter.report.core.CsvSampleReader)

Aggregations

CsvSampleWriter (org.apache.jmeter.report.core.CsvSampleWriter)3 File (java.io.File)2 Sample (org.apache.jmeter.report.core.Sample)2 CsvFile (org.apache.jmeter.report.core.CsvFile)1 CsvSampleReader (org.apache.jmeter.report.core.CsvSampleReader)1 SampleException (org.apache.jmeter.report.core.SampleException)1