diff --git a/src/index.ts b/src/index.ts index d25dd1c..5bacc9e 100755 --- a/src/index.ts +++ b/src/index.ts @@ -15,13 +15,14 @@ import { formatShellDiff, formatShellDiffBrillig, } from "./format/program"; -import { loadReports, computeProgramDiffs } from "./report"; +import { loadReports, computeProgramDiffs, memoryReports, formatMemoryReport } from "./report"; const token = process.env.GITHUB_TOKEN || core.getInput("token"); const report = core.getInput("report"); const header = core.getInput("header"); const brillig_report = core.getInput("brillig_report"); const brillig_report_bytes = core.getInput("brillig_report_bytes"); +const memory_report = core.getInput("memory_report"); const summaryQuantile = parseFloat(core.getInput("summaryQuantile")); // const sortCriteria = core.getInput("sortCriteria").split(","); // const sortOrders = core.getInput("sortOrders").split(","); @@ -109,21 +110,30 @@ async function run() { } try { - core.startGroup("Load gas reports"); - core.info(`Loading gas reports from "${localReportPath}"`); + core.startGroup("Load reports"); + core.info(`Loading reports from "${localReportPath}"`); const compareContent = fs.readFileSync(localReportPath, "utf8"); - referenceContent ??= compareContent; // if no source gas reports were loaded, defaults to the current gas reports - core.info(`Mapping compared gas reports`); + if (memory_report) { + core.info(`Format Memory markdown rows`); + const memoryContent = memoryReports(compareContent); + const markdown = formatMemoryReport(memoryContent); + core.setOutput("markdown", markdown); + return; + } + + referenceContent ??= compareContent; // if no source reports were loaded, defaults to the current reports + + core.info(`Mapping compared reports`); const compareReports = loadReports(compareContent); core.info(`Got ${compareReports.programs.length} compare programs`); - core.info(`Mapping reference gas reports`); + core.info(`Mapping reference reports`); const referenceReports = loadReports(referenceContent); core.info(`Got ${compareReports.programs.length} reference programs`); core.endGroup(); - core.startGroup("Compute gas diff"); + core.startGroup("Compute diff"); const [diffCircuitRows, diffBrilligRows] = computeProgramDiffs( referenceReports.programs, compareReports.programs @@ -141,8 +151,6 @@ async function run() { [summaryRows, fullReportRows] = formatCircuitRows(diffCircuitRows, summaryQuantile); } - core.info(`Format markdown of ${numDiffs} diffs`); - // const [summaryRows, fullReportRows] = formatCircuitRows(diffCircuitRows, summaryQuantile); const markdown = formatMarkdownDiff( header, repository, diff --git a/src/report.ts b/src/report.ts index 6509fb8..398efed 100644 --- a/src/report.ts +++ b/src/report.ts @@ -10,6 +10,7 @@ import { ProgramReport, BrilligReport, DiffBrillig, + MemoryReport, } from "./types"; export const variation = (current: number, previous: number) => { @@ -27,6 +28,10 @@ export const loadReports = (content: string): WorkspaceReport => { return JSON.parse(content); }; +export const memoryReports = (content: string): MemoryReport[] => { + return JSON.parse(content).memory_reports; +}; + export const computedWorkspaceDiff = ( sourceReport: WorkspaceReport, compareReport: WorkspaceReport @@ -193,3 +198,18 @@ const computeContractDiff = ( functions: functionDiffs, }; }; + +export const formatMemoryReport = (memReports: MemoryReport[]): string => { + let markdown = "## Peak Memory Sample\n | Program | Peak Memory |\n | --- | --- |\n"; + expect(memReports.length).toBeGreaterThan(0); + for (let i = 0; i < memReports.length; i++) { + markdown = markdown.concat( + " | ", + memReports[i].artifact_name, + " | ", + memReports[i].peak_memory, + " |\n" + ); + } + return markdown; +}; diff --git a/src/types.ts b/src/types.ts index 6927651..9d95d98 100644 --- a/src/types.ts +++ b/src/types.ts @@ -58,6 +58,15 @@ export interface DiffCell { percentage: number; } +export interface MemoryReport { + artifact_name: string; + peak_memory: string; +} + +export interface MemoryReports { + memory_reports: MemoryReport[]; +} + export type SortCriterion = keyof DiffCircuit; export type SortOrder = "asc" | "desc"; diff --git a/tests/memory_report.test.ts b/tests/memory_report.test.ts new file mode 100644 index 0000000..093203d --- /dev/null +++ b/tests/memory_report.test.ts @@ -0,0 +1,15 @@ +import * as fs from "fs"; + +import { memoryReports, formatMemoryReport } from "../src/report"; + +const srcContent = fs.readFileSync("tests/mocks/mem_report.json", "utf8"); + +const memReports = memoryReports(srcContent); + +describe("Markdown format", () => { + it("should generate markdown format", () => { + expect(memReports.length).toBeGreaterThan(0); + const markdown = formatMemoryReport(memReports); + expect(markdown.length).toBeGreaterThan(0); + }); +}); diff --git a/tests/mocks/mem_report.json b/tests/mocks/mem_report.json new file mode 100644 index 0000000..6715774 --- /dev/null +++ b/tests/mocks/mem_report.json @@ -0,0 +1,338 @@ +{ + "memory_reports": [ + { + "artifact_name":"1327_concrete_in_generic", + "peak_memory":78.51 + } + , + { + "artifact_name":"1_mul", + "peak_memory":132.60 + } + , + { + "artifact_name":"2_div", + "peak_memory":78.45 + } + , + { + "artifact_name":"3_add", + "peak_memory":78.43 + } + , + { + "artifact_name":"4_sub", + "peak_memory":78.43 + } + , + { + "artifact_name":"5_over", + "peak_memory":78.44 + } + , + { + "artifact_name":"6", + "peak_memory":80.70 + } + , + { + "artifact_name":"6_array", + "peak_memory":78.82 + } + , + { + "artifact_name":"7", + "peak_memory":78.45 + } + , + { + "artifact_name":"7_function", + "peak_memory":78.89 + } + , + { + "artifact_name":"acir_inside_brillig_recursion", + "peak_memory":78.44 + } + , + { + "artifact_name":"aes128_encrypt", + "peak_memory":78.68 + } + , + { + "artifact_name":"arithmetic_binary_operations", + "peak_memory":78.44 + } + , + { + "artifact_name":"array_dynamic", + "peak_memory":78.57 + } + , + { + "artifact_name":"array_dynamic_blackbox_input", + "peak_memory":86.68 + } + , + { + "artifact_name":"array_dynamic_main_output", + "peak_memory":78.43 + } + , + { + "artifact_name":"array_dynamic_nested_blackbox_input", + "peak_memory":80.22 + } + , + { + "artifact_name":"array_eq", + "peak_memory":78.43 + } + , + { + "artifact_name":"array_if_cond_simple", + "peak_memory":78.47 + } + , + { + "artifact_name":"array_len", + "peak_memory":78.50 + } + , + { + "artifact_name":"array_neq", + "peak_memory":78.52 + } + , + { + "artifact_name":"array_sort", + "peak_memory":78.60 + } + , + { + "artifact_name":"array_to_slice", + "peak_memory":78.66 + } + , + { + "artifact_name":"array_to_slice_constant_length", + "peak_memory":78.43 + } + , + { + "artifact_name":"as_witness", + "peak_memory":78.41 + } + , + { + "artifact_name":"assert", + "peak_memory":78.43 + } + , + { + "artifact_name":"assert_statement", + "peak_memory":78.42 + } + , + { + "artifact_name":"assign_ex", + "peak_memory":78.45 + } + , + { + "artifact_name":"bench_ecdsa_secp256k1", + "peak_memory":78.48 + } + , + { + "artifact_name":"bigint", + "peak_memory":81.40 + } + , + { + "artifact_name":"binary_operator_overloading", + "peak_memory":79.03 + } + , + { + "artifact_name":"bit_and", + "peak_memory":78.47 + } + , + { + "artifact_name":"bit_not", + "peak_memory":78.42 + } + , + { + "artifact_name":"bit_shifts_comptime", + "peak_memory":78.49 + } + , + { + "artifact_name":"bit_shifts_runtime", + "peak_memory":79.50 + } + , + { + "artifact_name":"blake3", + "peak_memory":78.45 + } + , + { + "artifact_name":"bool_not", + "peak_memory":78.41 + } + , + { + "artifact_name":"bool_or", + "peak_memory":78.42 + } + , + { + "artifact_name":"break_and_continue", + "peak_memory":78.44 + } + , + { + "artifact_name":"brillig_acir_as_brillig", + "peak_memory":78.54 + } + , + { + "artifact_name":"brillig_arrays", + "peak_memory":78.51 + } + , + { + "artifact_name":"brillig_blake2s", + "peak_memory":78.48 + } + , + { + "artifact_name":"brillig_block_parameter_liveness", + "peak_memory":98.25 + } + , + { + "artifact_name":"brillig_calls", + "peak_memory":78.59 + } + , + { + "artifact_name":"brillig_calls_array", + "peak_memory":78.55 + } + , + { + "artifact_name":"brillig_calls_conditionals", + "peak_memory":78.49 + } + , + { + "artifact_name":"brillig_conditional", + "peak_memory":78.44 + } + , + { + "artifact_name":"brillig_constant_reference_regression", + "peak_memory":78.45 + } + , + { + "artifact_name":"brillig_cow", + "peak_memory":78.59 + } + , + { + "artifact_name":"brillig_cow_assign", + "peak_memory":78.47 + } + , + { + "artifact_name":"brillig_cow_regression", + "peak_memory":79.76 + } + , + { + "artifact_name":"brillig_fns_as_values", + "peak_memory":78.55 + } + , + { + "artifact_name":"brillig_identity_function", + "peak_memory":78.51 + } + , + { + "artifact_name":"brillig_loop_size_regression", + "peak_memory":78.45 + } + , + { + "artifact_name":"brillig_nested_arrays", + "peak_memory":78.67 + } + , + { + "artifact_name":"brillig_not", + "peak_memory":78.45 + } + , + { + "artifact_name":"brillig_oracle", + "peak_memory":78.57 + } + , + { + "artifact_name":"brillig_pedersen", + "peak_memory":78.65 + } + , + { + "artifact_name":"brillig_rc_regression_6123", + "peak_memory":78.56 + } + , + { + "artifact_name":"brillig_recursion", + "peak_memory":78.45 + } + , + { + "artifact_name":"brillig_uninitialized_arrays", + "peak_memory":78.45 + } + , + { + "artifact_name":"cast_and_shift_global", + "peak_memory":78.42 + } + , + { + "artifact_name":"cast_bool", + "peak_memory":78.42 + } + , + { + "artifact_name":"check_large_field_bits", + "peak_memory":78.55 + } + , + { + "artifact_name":"closures_mut_ref", + "peak_memory":78.49 + } + , + { + "artifact_name":"comptime_println", + "peak_memory":78.44 + } + , + { + "artifact_name":"comptime_slice_equality", + "peak_memory":78.41 + } +] +} \ No newline at end of file