Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 4c10b34

Browse files
committed
based off the review
1 parent 14fb080 commit 4c10b34

18 files changed

+531
-245
lines changed

analyze.js

Lines changed: 0 additions & 242 deletions
This file was deleted.

analyze.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
});

analyze/config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.servers = exports.formattedServerNames = void 0;
4+
exports.formattedServerNames = {
5+
tailcall: "Tailcall",
6+
gqlgen: "Gqlgen",
7+
apollo: "Apollo GraphQL",
8+
netflixdgs: "Netflix DGS",
9+
caliban: "Caliban",
10+
async_graphql: "async-graphql",
11+
hasura: "Hasura",
12+
graphql_jit: "GraphQL JIT",
13+
};
14+
exports.servers = ["apollo", "caliban", "netflixdgs", "gqlgen", "tailcall", "async_graphql", "hasura", "graphql_jit"];

analyze/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { FormattedServerNames } from './types';
2+
3+
export const formattedServerNames: FormattedServerNames = {
4+
tailcall: "Tailcall",
5+
gqlgen: "Gqlgen",
6+
apollo: "Apollo GraphQL",
7+
netflixdgs: "Netflix DGS",
8+
caliban: "Caliban",
9+
async_graphql: "async-graphql",
10+
hasura: "Hasura",
11+
graphql_jit: "GraphQL JIT",
12+
};
13+
14+
export const servers: string[] = ["apollo", "caliban", "netflixdgs", "gqlgen", "tailcall", "async_graphql", "hasura", "graphql_jit"];

analyze/dataFileWriter.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.writeMetricsDataFiles = writeMetricsDataFiles;
4+
var fileUtils_1 = require("./fileUtils");
5+
function writeMetricsDataFiles(serverMetrics, servers) {
6+
var reqSecData = "/tmp/reqSec.dat";
7+
var latencyData = "/tmp/latency.dat";
8+
(0, fileUtils_1.writeDataFile)(reqSecData, "Server Value\n" + servers.map(function (server) { return "".concat(server, " ").concat(serverMetrics[server].reqSec); }).join('\n'));
9+
(0, fileUtils_1.writeDataFile)(latencyData, "Server Value\n" + servers.map(function (server) { return "".concat(server, " ").concat(serverMetrics[server].latency); }).join('\n'));
10+
}

analyze/dataFileWriter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { writeDataFile } from './fileUtils';
2+
import { ServerMetrics } from './types';
3+
4+
export function writeMetricsDataFiles(serverMetrics: Record<string, ServerMetrics>, servers: string[]): void {
5+
const reqSecData = "/tmp/reqSec.dat";
6+
const latencyData = "/tmp/latency.dat";
7+
8+
writeDataFile(reqSecData, "Server Value\n" + servers.map(server => `${server} ${serverMetrics[server].reqSec}`).join('\n'));
9+
writeDataFile(latencyData, "Server Value\n" + servers.map(server => `${server} ${serverMetrics[server].latency}`).join('\n'));
10+
}

0 commit comments

Comments
 (0)