Skip to content

Commit

Permalink
Merge pull request #3 from noir-lang/mv/compilation-report
Browse files Browse the repository at this point in the history
feat: Compilation report
  • Loading branch information
vezenovm authored Dec 16, 2024
2 parents 1725958 + 0d7464a commit 5fb7f20
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 6 deletions.
84 changes: 82 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,72 @@
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 6423:
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.computeCompilationDiff = exports.formatCompilationReport = exports.compilationReports = void 0;
const compilationReports = (content) => {
return JSON.parse(content).compilation_reports;
};
exports.compilationReports = compilationReports;
const formatCompilationReport = (compilationReports) => {
let markdown = "## Compilation Sample\n | Program | Compilation Time |\n | --- | --- |\n";
for (let i = 0; i < compilationReports.length; i++) {
markdown = markdown.concat(" | ", compilationReports[i].artifact_name, " | ", compilationReports[i].time, " |\n");
}
return markdown;
};
exports.formatCompilationReport = formatCompilationReport;
const computeCompilationDiff = (refReports, compilationReports) => {
let markdown = "";
const diff_percentage = [];
let diff_column = false;
if (refReports.length === compilationReports.length) {
for (let i = 0; i < refReports.length; i++) {
let diff_str = "N/A";
if (refReports[i].artifact_name === compilationReports[i].artifact_name) {
const compTimeString = compilationReports[i].time;
const refTimeString = refReports[i].time;
const compTimeSegments = compTimeString.split("m");
const refTimeSegments = refTimeString.split("m");
const minutesString = compTimeSegments[0];
const refMinutesString = refTimeSegments[0];
const compMinutesValue = parseInt(minutesString);
const refMinutesValue = parseInt(refMinutesString);
const secondsString = compTimeSegments[1];
const compSecondsValue = parseFloat(secondsString.substring(0, secondsString.length - 1));
const compSeconds = compMinutesValue * 60 + compSecondsValue;
const refSecondsString = refTimeSegments[1];
const refSecondsValue = parseFloat(refSecondsString.substring(0, refSecondsString.length - 1));
const refSeconds = refMinutesValue * 60 + refSecondsValue;
const diff = Math.floor(((compSeconds - refSeconds) / refSeconds) * 100);
if (diff != 0) {
diff_column = true;
}
diff_str = diff.toString() + "%";
}
diff_percentage.push(diff_str);
}
}
if (diff_column == true) {
markdown = "## Compilation Sample\n | Program | Compilation Time | % |\n | --- | --- | --- |\n";
for (let i = 0; i < diff_percentage.length; i++) {
markdown = markdown.concat(" | ", compilationReports[i].artifact_name, " | ", compilationReports[i].time, " | ", diff_percentage[i], " |\n");
}
}
else {
markdown = (0, exports.formatCompilationReport)(compilationReports);
}
return markdown;
};
exports.computeCompilationDiff = computeCompilationDiff;


/***/ }),

/***/ 4822:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

Expand Down Expand Up @@ -55,6 +121,7 @@ const path_1 = __nccwpck_require__(1017);
const artifact = __importStar(__nccwpck_require__(2605));
const core = __importStar(__nccwpck_require__(2186));
const github_1 = __nccwpck_require__(5438);
const compilation_report_1 = __nccwpck_require__(6423);
const report_1 = __nccwpck_require__(8269);
const token = process.env.GITHUB_TOKEN || core.getInput("token");
const report = core.getInput("report");
Expand Down Expand Up @@ -153,13 +220,22 @@ function run() {
try {
core.startGroup("Load reports");
referenceContent !== null && referenceContent !== void 0 ? referenceContent : (referenceContent = compareContent); // if no source reports were loaded, defaults to the current reports
if (memory_report) {
core.info("About to check memory reports");
const isMemoryReport = memory_report === "true";
if (isMemoryReport) {
core.info(`Format Memory markdown rows`);
const memoryContent = (0, report_1.memoryReports)(compareContent);
const referenceReports = (0, report_1.memoryReports)(referenceContent);
const markdown = (0, report_1.computeMemoryDiff)(referenceReports, memoryContent);
core.setOutput("markdown", markdown);
}
else {
core.info(`Format Compilation report markdown rows`);
const compilationContent = (0, report_1.compilationReports)(compareContent);
const referenceReports = (0, report_1.compilationReports)(referenceContent);
const markdown = (0, compilation_report_1.computeCompilationDiff)(referenceReports, compilationContent);
core.setOutput("markdown", markdown);
}
core.endGroup();
}
catch (error) {
Expand Down Expand Up @@ -192,7 +268,7 @@ run();
"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.computeMemoryDiff = exports.formatMemoryReport = exports.memoryReports = exports.variation = void 0;
exports.computeMemoryDiff = exports.formatMemoryReport = exports.compilationReports = exports.memoryReports = exports.variation = void 0;
const variation = (current, previous) => {
const delta = current - previous;
return {
Expand All @@ -207,6 +283,10 @@ const memoryReports = (content) => {
return JSON.parse(content).memory_reports;
};
exports.memoryReports = memoryReports;
const compilationReports = (content) => {
return JSON.parse(content).compilation_reports;
};
exports.compilationReports = compilationReports;
const formatMemoryReport = (memReports) => {
let markdown = "## Peak Memory Sample\n | Program | Peak Memory |\n | --- | --- |\n";
for (let i = 0; i < memReports.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions src/compilation_report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { CompilationReport } from "./types";

export const compilationReports = (content: string): CompilationReport[] => {
return JSON.parse(content).compilation_reports;
};

export const formatCompilationReport = (compilationReports: CompilationReport[]): string => {
let markdown = "## Compilation Sample\n | Program | Compilation Time |\n | --- | --- |\n";
for (let i = 0; i < compilationReports.length; i++) {
markdown = markdown.concat(
" | ",
compilationReports[i].artifact_name,
" | ",
compilationReports[i].time,
" |\n"
);
}
return markdown;
};

export const computeCompilationDiff = (
refReports: CompilationReport[],
compilationReports: CompilationReport[]
): string => {
let markdown = "";
const diff_percentage = [];
let diff_column = false;
if (refReports.length === compilationReports.length) {
for (let i = 0; i < refReports.length; i++) {
let diff_str = "N/A";
if (refReports[i].artifact_name === compilationReports[i].artifact_name) {
const compTimeString = compilationReports[i].time;
const refTimeString = refReports[i].time;
const compTimeSegments = compTimeString.split("m");
const refTimeSegments = refTimeString.split("m");

const minutesString = compTimeSegments[0];
const refMinutesString = refTimeSegments[0];

const compMinutesValue = parseInt(minutesString);
const refMinutesValue = parseInt(refMinutesString);

const secondsString = compTimeSegments[1];
const compSecondsValue = parseFloat(secondsString.substring(0, secondsString.length - 1));
const compSeconds = compMinutesValue * 60 + compSecondsValue;

const refSecondsString = refTimeSegments[1];
const refSecondsValue = parseFloat(
refSecondsString.substring(0, refSecondsString.length - 1)
);
const refSeconds = refMinutesValue * 60 + refSecondsValue;

const diff = Math.floor(((compSeconds - refSeconds) / refSeconds) * 100);
if (diff != 0) {
diff_column = true;
}
diff_str = diff.toString() + "%";
}

diff_percentage.push(diff_str);
}
}

if (diff_column == true) {
markdown = "## Compilation Sample\n | Program | Compilation Time | % |\n | --- | --- | --- |\n";
for (let i = 0; i < diff_percentage.length; i++) {
markdown = markdown.concat(
" | ",
compilationReports[i].artifact_name,
" | ",
compilationReports[i].time,
" | ",
diff_percentage[i],
" |\n"
);
}
} else {
markdown = formatCompilationReport(compilationReports);
}

return markdown;
};
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as artifact from "@actions/artifact";
import * as core from "@actions/core";
import { context, getOctokit } from "@actions/github";

import { memoryReports, computeMemoryDiff } from "./report";
import { computeCompilationDiff } from "./compilation_report";
import { memoryReports, computeMemoryDiff, compilationReports } from "./report";

const token = process.env.GITHUB_TOKEN || core.getInput("token");
const report = core.getInput("report");
Expand Down Expand Up @@ -101,13 +102,21 @@ async function run() {
try {
core.startGroup("Load reports");
referenceContent ??= compareContent; // if no source reports were loaded, defaults to the current reports
core.info("About to check memory reports");

if (memory_report) {
const isMemoryReport = memory_report === "true";
if (isMemoryReport) {
core.info(`Format Memory markdown rows`);
const memoryContent = memoryReports(compareContent);
const referenceReports = memoryReports(referenceContent);
const markdown = computeMemoryDiff(referenceReports, memoryContent);
core.setOutput("markdown", markdown);
} else {
core.info(`Format Compilation report markdown rows`);
const compilationContent = compilationReports(compareContent);
const referenceReports = compilationReports(referenceContent);
const markdown = computeCompilationDiff(referenceReports, compilationContent);
core.setOutput("markdown", markdown);
}

core.endGroup();
Expand Down
6 changes: 5 additions & 1 deletion src/report.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _orderBy from "lodash/orderBy";

import { MemoryReport } from "./types";
import { CompilationReport, MemoryReport } from "./types";

export const variation = (current: number, previous: number) => {
const delta = current - previous;
Expand All @@ -17,6 +17,10 @@ export const memoryReports = (content: string): MemoryReport[] => {
return JSON.parse(content).memory_reports;
};

export const compilationReports = (content: string): CompilationReport[] => {
return JSON.parse(content).compilation_reports;
};

export const formatMemoryReport = (memReports: MemoryReport[]): string => {
let markdown = "## Peak Memory Sample\n | Program | Peak Memory |\n | --- | --- |\n";
for (let i = 0; i < memReports.length; i++) {
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ export interface MemoryReport {
export interface MemoryReports {
memory_reports: MemoryReport[];
}

export interface CompilationReport {
artifact_name: string;
time: string;
}

export interface CompilationReports {
compilation_reports: CompilationReport[];
}
28 changes: 28 additions & 0 deletions tests/compilation_report.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as fs from "fs";

import { computeCompilationDiff, formatCompilationReport } from "../src/compilation_report";
import { compilationReports } from "../src/report";

const srcContent = fs.readFileSync("tests/mocks/1-1-compilation-report.json", "utf8");
const ref_1_Content = fs.readFileSync("tests/mocks/1-1-compilation-report.json", "utf8");
const ref_2_Content = fs.readFileSync("tests/mocks/1-2-compilation-report.json", "utf8");

const compReports = compilationReports(srcContent);

describe("Markdown format", () => {
it("should generate markdown format", () => {
expect(compReports.length).toBeGreaterThan(0);
const markdown = formatCompilationReport(compReports);
expect(markdown.length).toBeGreaterThan(0);
});

it("should generate diff report format", () => {
const ref_1_Reports = compilationReports(ref_1_Content);
const ref_2_Reports = compilationReports(ref_2_Content);
expect(ref_1_Reports.length).toBeGreaterThan(0);
expect(ref_1_Reports.length).toBe(ref_2_Reports.length);
const markdown = computeCompilationDiff(ref_1_Reports, ref_2_Reports);
fs.writeFileSync("tests/mocks/1-2-compilation.md", markdown);
expect(markdown.length).toBeGreaterThan(0);
});
});
22 changes: 22 additions & 0 deletions tests/mocks/1-1-compilation-report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{"compilation_reports": [
{
"artifact_name":"keccak256",
"time":"0m0.280s"

},
{
"artifact_name":"workspace",
"time":"0m0.271s"

},
{
"artifact_name":"regression_4709",
"time":"0m1.796s"

},
{
"artifact_name":"ram_blowup_regression",
"time":"0m20.566s"

}
]}
22 changes: 22 additions & 0 deletions tests/mocks/1-2-compilation-report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{"compilation_reports": [
{
"artifact_name":"keccak256",
"time":"0m0.325s"

},
{
"artifact_name":"workspace",
"time":"0m0.300s"

},
{
"artifact_name":"regression_4709",
"time":"0m1.842s"

},
{
"artifact_name":"ram_blowup_regression",
"time":"0m20.526s"

}
]}
7 changes: 7 additions & 0 deletions tests/mocks/1-2-compilation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Compilation Sample
| Program | Compilation Time | % |
| --- | --- | --- |
| keccak256 | 0m0.325s | 16% |
| workspace | 0m0.300s | 10% |
| regression_4709 | 0m1.842s | 2% |
| ram_blowup_regression | 0m20.526s | -1% |

0 comments on commit 5fb7f20

Please sign in to comment.