|
| 1 | +#!/usr/bin/env node |
| 2 | +import { execSync } from 'child_process'; |
| 3 | +import * as path from 'path'; |
| 4 | +import * as fs from 'fs'; |
| 5 | +import { servers, formattedServerNames } from './analyze/config'; |
| 6 | +import { createDirectoryIfNotExists, moveFile, readFileContent } from './analyze/fileUtils'; |
| 7 | +import { parseServerMetrics } from './analyze/parser'; |
| 8 | +import { writeMetricsDataFiles } from './analyze/dataFileWriter'; |
| 9 | +import { generateGnuplotScript, writeGnuplotScript } from './analyze/gnuplotGenerator'; |
| 10 | +import { formatResults, writeResults } from './analyze/resultsFormatter'; |
| 11 | + |
| 12 | +const resultFiles: string[] = process.argv.slice(2); |
| 13 | + |
| 14 | +// Read content of result files |
| 15 | +const resultContents: string[] = resultFiles.map(file => readFileContent(file)); |
| 16 | + |
| 17 | +const serverMetrics = parseServerMetrics(servers, resultContents); |
| 18 | + |
| 19 | +writeMetricsDataFiles(serverMetrics, servers); |
| 20 | + |
| 21 | +let whichBench = 1; |
| 22 | +if (resultFiles.length > 0) { |
| 23 | + if (resultFiles[0].startsWith("bench2")) { |
| 24 | + whichBench = 2; |
| 25 | + } else if (resultFiles[0].startsWith("bench3")) { |
| 26 | + whichBench = 3; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +function getMaxValue(data: string): number { |
| 31 | + try { |
| 32 | + return Math.max(...data.split('\n') |
| 33 | + .slice(1) |
| 34 | + .map(line => { |
| 35 | + const [, valueStr] = line.split(' '); |
| 36 | + const value = parseFloat(valueStr); |
| 37 | + if (isNaN(value)) { |
| 38 | + throw new Error(`Invalid number in data: ${valueStr}`); |
| 39 | + } |
| 40 | + return value; |
| 41 | + })); |
| 42 | + } catch (error) { |
| 43 | + console.error(`Error getting max value: ${(error as Error).message}`); |
| 44 | + return 0; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +const reqSecMax = getMaxValue(readFileContent('/tmp/reqSec.dat')) * 1.2; |
| 49 | +const latencyMax = getMaxValue(readFileContent('/tmp/latency.dat')) * 1.2; |
| 50 | + |
| 51 | +const gnuplotScript = generateGnuplotScript(whichBench, reqSecMax, latencyMax); |
| 52 | +writeGnuplotScript(gnuplotScript); |
| 53 | + |
| 54 | +try { |
| 55 | + execSync(`gnuplot /tmp/gnuplot_script.gp`, { stdio: 'inherit' }); |
| 56 | + console.log('Gnuplot executed successfully'); |
| 57 | +} catch (error) { |
| 58 | + console.error('Error executing gnuplot:', (error as Error).message); |
| 59 | +} |
| 60 | + |
| 61 | +const assetsDir = path.join(__dirname, "assets"); |
| 62 | +createDirectoryIfNotExists(assetsDir); |
| 63 | + |
| 64 | +moveFile(`req_sec_histogram${whichBench}.png`, path.join(assetsDir, `req_sec_histogram${whichBench}.png`)); |
| 65 | +moveFile(`latency_histogram${whichBench}.png`, path.join(assetsDir, `latency_histogram${whichBench}.png`)); |
| 66 | + |
| 67 | +const resultsTable = formatResults(serverMetrics, formattedServerNames, whichBench); |
| 68 | +writeResults(resultsTable, whichBench); |
| 69 | + |
| 70 | +resultFiles.forEach((file) => { |
| 71 | + try { |
| 72 | + fs.unlinkSync(file); |
| 73 | + } catch (error) { |
| 74 | + console.error(`Error deleting file ${file}: ${(error as Error).message}`); |
| 75 | + } |
| 76 | +}); |
0 commit comments