/** * Method will save aggregate statistics as CSV. For now I put it here. Not * sure if it should go in the newer SaveService instead of here. if we ever * decide to get rid of this class, we'll need to move this method to the * new save service. * * @param data * List of data rows * @param writer * output writer * @throws IOException * when writing to <code>writer</code> fails */ public static void saveCSVStats(List<?> data, Writer writer) throws IOException { saveCSVStats(data, writer, null); }
/** * Generates the field names for the output file * * @return the field names as a string */ public static String printableFieldNamesToString() { return printableFieldNamesToString(_saveConfig); }
/** * Reads from String and splits into strings according to the delimiter, * taking note of quoted strings. * * Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally. * * @param line * input line - not {@code null} * @param delim * delimiter (e.g. comma) * @return array of strings * @throws IOException * also for unexpected quote characters */ public static String[] csvSplitString(String line, char delim) throws IOException { return csvReadFile(new BufferedReader(new StringReader(line)), delim); }
/** * Convert a result into a string, where the fields of the result are * separated by the default delimiter. * * @param event * the sample event to be converted * @return the separated value representation of the result */ public static String resultToDelimitedString(SampleEvent event) { return resultToDelimitedString(event, event.getResult().getSaveConfig() .getDelimiter()); }
.getSampleSaveConfiguration(line, filename); if (saveConfig == null) {// not a valid header log.info("{} does not appear to have a valid header. Using default configuration.", filename); while ((parts = csvReadFile(dataReader, delim)).length != 0) { lineNumber++; SampleEvent event = CSVSaveService.makeResultFromDelimitedString(parts, saveConfig, lineNumber); if (event != null) { final SampleResult result = event.getResult();
return new int[]{}; String[] arguments = CSVSaveService.csvSplitString(getQueryArguments(), COMMA_CHAR); String[] argumentsTypes = getQueryArgumentsTypes().split(COMMA); if (arguments.length != argumentsTypes.length) {
String delim = saveConfig.getDelimiter(); appendFields(saveConfig.saveTimestamp(), text, delim, TIME_STAMP); appendFields(saveConfig.saveTime(), text, delim, CSV_ELAPSED); appendFields(saveConfig.saveLabel(), text, delim, LABEL); appendFields(saveConfig.saveCode(), text, delim, RESPONSE_CODE); appendFields(saveConfig.saveMessage(), text, delim, RESPONSE_MESSAGE); appendFields(saveConfig.saveThreadName(), text, delim, THREAD_NAME); appendFields(saveConfig.saveDataType(), text, delim, DATA_TYPE); appendFields(saveConfig.saveSuccess(), text, delim, SUCCESSFUL); appendFields(saveConfig.saveAssertionResultsFailureMessage(), text, delim, FAILURE_MESSAGE); appendFields(saveConfig.saveBytes(), text, delim, CSV_BYTES); appendFields(saveConfig.saveSentBytes(), text, delim, CSV_SENT_BYTES); appendFields(saveConfig.saveThreadCounts(), text, delim, CSV_THREAD_COUNT1, CSV_THREAD_COUNT2); appendFields(saveConfig.saveUrl(), text, delim, CSV_URL); appendFields(saveConfig.saveFileName(), text, delim, CSV_FILENAME); appendFields(saveConfig.saveLatency(), text, delim, CSV_LATENCY); appendFields(saveConfig.saveEncoding(), text, delim, CSV_ENCODING); appendFields(saveConfig.saveSampleCount(), text, delim, CSV_SAMPLE_COUNT, CSV_ERROR_COUNT); appendFields(saveConfig.saveHostname(), text, delim, CSV_HOSTNAME); appendFields(saveConfig.saveIdleTime(), text, delim, CSV_IDLETIME); appendFields(saveConfig.saveConnectTime(), text, delim, CSV_CONNECT_TIME);
&& CSVSaveService.getSampleSaveConfiguration( line, file.getAbsolutePath()) == null) {
/** * Convert a result into a string, where the fields of the result are * separated by a specified String. * * @param event * the sample event to be converted * @param delimiter * the separation string * @return the separated value representation of the result */ public static String resultToDelimitedString(SampleEvent event, final String delimiter) { return resultToDelimitedString(event, event.getResult(), event.getResult().getSaveConfig(), delimiter); }
String header = server.reserveFile(fileName, getFileEncoding(), alias, true); try { vars = CSVSaveService.csvSplitString(header, delim.charAt(0)); firstLineIsNames = true; } catch (IOException e) {
/** * Method saves aggregate statistics (with header names) as CSV from a table * model. Same as {@link #saveCSVStats(List, Writer, String[])} except * that there is no need to create a List containing the data. * * @param model * table model containing the data * @param writer * output file * @throws IOException * when writing to <code>writer</code> fails */ public static void saveCSVStats(DefaultTableModel model, FileWriter writer) throws IOException { saveCSVStats(model, writer, true); }
/** * @param event {@link SampleEvent} * @param out {@link PrintWriter} to which samples will be written */ public static void saveSampleResult(SampleEvent event, PrintWriter out) { SampleSaveConfiguration saveConfiguration = event.getResult().getSaveConfig(); String delimiter = saveConfiguration.getDelimiter(); String savee = resultToDelimitedString(event, event.getResult(), saveConfiguration, delimiter); out.println(savee); if(saveConfiguration.saveSubresults()) { SampleResult result = event.getResult(); for (SampleResult subResult : result.getSubResults()) { savee = resultToDelimitedString(event, subResult, saveConfiguration, delimiter); out.println(savee); } } } }
private static void writeFileStart(PrintWriter writer, SampleSaveConfiguration saveConfig) { if (saveConfig.saveAsXml()) { writer.print(XML_HEADER); // Write the EOL separately so we generate LF line ends on Unix and Windows writer.print("\n"); // $NON-NLS-1$ String pi=saveConfig.getXmlPi(); if (pi.length() > 0) { writer.println(pi); } // Can't do it as a static initialisation, because SaveService // is being constructed when this is called writer.print(TESTRESULTS_START_V1_1_PREVER); writer.print(SaveService.getVERSION()); writer.print(TESTRESULTS_START_V1_1_POSTVER); // Write the EOL separately so we generate LF line ends on Unix and Windows writer.print("\n"); // $NON-NLS-1$ } else if (saveConfig.saveFieldNames()) { writer.println(CSVSaveService.printableFieldNamesToString(saveConfig)); } }
/** * * @param alias the file name or alias * @param recycle whether the file should be re-started on EOF * @param ignoreFirstLine whether the file contains a file header which will be ignored * @param delim the delimiter to use for parsing * @return the parsed line, will be empty if the file is at EOF * @throws IOException when reading of the aliased file fails, or the file was not reserved properly */ public synchronized String[] getParsedLine(String alias, boolean recycle, boolean ignoreFirstLine, char delim) throws IOException { BufferedReader reader = getReader(alias, recycle, ignoreFirstLine); return CSVSaveService.csvReadFile(reader, delim); }
@Override public void actionPerformed(ActionEvent ev) { if (ev.getSource() == saveTable) { JFileChooser chooser = FileDialoger.promptToSaveFile("summary.csv");//$NON-NLS-1$ if (chooser == null) { return; } try (FileOutputStream fo = new FileOutputStream(chooser.getSelectedFile()); OutputStreamWriter writer = new OutputStreamWriter(fo, Charset.forName("UTF-8"))) { CSVSaveService.saveCSVStats(StatGraphVisualizer.getAllTableData(model, FORMATS),writer, saveHeaders.isSelected() ? StatGraphVisualizer.getLabels(COLUMNS) : null); } catch (IOException e) { JMeterUtils.reportErrorToUser(e.getMessage(), "Error saving data"); } } } }
public void mergeSamples(CorrectedResultCollector crc, List<SampleResult> samples) { SampleEvent event; try { initializeFileOutput(crc.getFilename(), crc.getSaveConfig()); } catch (IOException e) { log.warn("Error trying to initialize output file " + e.toString()); } for (SampleResult result : samples) { SampleSaveConfiguration config = crc.getSaveConfig(); event = new SampleEvent(result, null); try { if (config.saveAsXml()) { SaveService.saveSampleResult(event, out); } else { // !saveAsXml String savee = CSVSaveService .resultToDelimitedString(event); out.println(savee); } } catch (Exception err) { log.error("Error trying to record a sample", err); // should throw exception back to caller } } finalizeFileOutput(); }
private static void writeFileStart(PrintWriter writer, SampleSaveConfiguration saveConfig) { if (saveConfig.saveAsXml()) { writer.print(XML_HEADER); // Write the EOL separately so we generate LF line ends on Unix and // Windows writer.print("\n"); String pi = saveConfig.getXmlPi(); if (pi.length() > 0) { writer.println(pi); } writer.print(TESTRESULTS_START_V1_1_PREVER); writer.print(SaveService.getVERSION()); writer.print(TESTRESULTS_START_V1_1_POSTVER); // Write the EOL separately so we generate LF line ends on Unix and // Windows writer.print("\n"); } else if (saveConfig.saveFieldNames()) { writer.println(CSVSaveService .printableFieldNamesToString(saveConfig)); } }
private Sample nextSample() { String[] data; try { data = CSVSaveService.csvReadFile(reader, separator); Sample sample = null; if (data.length > 0) { if (data.length != columnCount+numberOfSampleVariablesInCsv) { throw new SampleException("Mismatch between expected number of columns:"+columnCount+" and columns in CSV file:"+data.length+ ", check your jmeter.save.saveservice.* configuration or check line is complete"); } sample = new Sample(row++, metadata, data); } return sample; } catch (IOException e) { throw new SampleException("Could not read sample <" + row + ">", e); } }
@Override public void saveGraphToCSV(File file) throws IOException { log.info("Saving CSV to " + file.getAbsolutePath()); FileWriter writer = null; try { writer = new FileWriter(file); CSVSaveService.saveCSVStats(SynthesisReportGui.getAllDataAsTable(statModel, FORMATS, getLabels(COLUMNS)), writer, saveHeaders.isSelected()); } catch (IOException e) { log.warn(e.getMessage()); } finally { try { writer.close(); } catch (IOException ex) { log.warn("There was problem closing file stream", ex); } } }
public void mergeSamples(CorrectedResultCollector crc, List<SampleResult> samples) { SampleEvent event; try { initializeFileOutput(crc.getFilename(), crc.getSaveConfig()); } catch (IOException e) { log.warn("Error trying to initialize output file " + e.toString()); } for (SampleResult result : samples) { SampleSaveConfiguration config = crc.getSaveConfig(); event = new SampleEvent(result, null); try { if (config.saveAsXml()) { SaveService.saveSampleResult(event, out); } else { // !saveAsXml String savee = CSVSaveService .resultToDelimitedString(event); out.println(savee); } } catch (Exception err) { log.error("Error trying to record a sample", err); // should throw exception back to caller } } finalizeFileOutput(); }