Skip to content

Commit 8df769c

Browse files
authored
Merge pull request #9 from cryspen/wysiwys/parse-metadata
Use new metadata format
2 parents 3ec378e + b82396f commit 8df769c

File tree

11 files changed

+338
-71
lines changed

11 files changed

+338
-71
lines changed

.github/workflows/build-and-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ jobs:
1919
- uses: ./ # local action in repo
2020
with:
2121
tool: 'cargo'
22-
platform: 'default'
22+
os: 'ubuntu-latest'
2323
output-file-path: ./test/data/extract/cargo_output.txt
2424
data-out-path: output.txt
2525
- uses: ./ # local action in repo
2626
with:
2727
tool: 'cargo'
28-
platform: 'default'
28+
os: 'ubuntu-latest'
2929
output-file-path: ./test/data/extract/cargo_output2.txt
3030
data-out-path: output.txt
3131
- uses: ./ # local action in repo
3232
with:
3333
tool: 'cargo'
34-
platform: 'default'
34+
os: 'ubuntu-latest'
3535
output-file-path: ./test/data/extract/cargo_output3.txt
3636
data-out-path: output.txt
3737
- uses: ./ # local action in repo
3838
with:
3939
tool: 'cargo'
40-
platform: 'default'
40+
os: 'ubuntu-latest'
4141
output-file-path: ./test/data/extract/criterion_output.txt
4242
data-out-path: output.txt

.github/workflows/minimal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ jobs:
1616
- uses: ./ # local action in repo
1717
with:
1818
tool: 'cargo'
19-
platform: 'default'
19+
os: 'ubuntu-latest'
2020
output-file-path: ./test/data/extract/cargo_output.txt
2121
data-out-path: output.txt

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,29 @@ Currently supported sources:
99
## Fields
1010
- `name` (required): name of the benchmark
1111
- `tool` (required): tool used to get benchmark output. One of `["cargo"]`
12-
- `platform` (required): a string describing the platform
12+
- `os` (required): a string describing the os
1313
- `output-file-path` (required): a path to a file containing the output of the benchmark tool
1414
- `data-out-path` (required): the path where the output of the action should be written
1515

16+
## Metadata format
17+
18+
The benchmark name in the `cargo` benchmarks can be provided as a `/`-separated string with the format `category/key size/name/platform/api`. The key size should be an integer. Some fields in this string can be left blank. Any unspecified or invalid fields will be parsed to `undefined`.
19+
1620
## Output data format
1721

1822
The output will be written to `data-out-path` in a standardized JSON format:
1923
```json
2024
[
21-
{
22-
"name": "My Custom Smaller Is Better Benchmark - Memory Used",
23-
"unit": "Megabytes",
24-
"platform": "ubuntu-latest",
25-
"value": 100,
26-
"range": "3",
27-
}
25+
{
26+
"api": "unpacked",
27+
"category": "ML-KEM",
28+
"keySize": 768,
29+
"name": "PK Validation",
30+
"os": "ubuntu-latest",
31+
"platform": "neon",
32+
"range": "± 123",
33+
"unit": "ns/iter",
34+
"value": 12314,
35+
},
2836
]
2937
```

action-types.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
type: enum
66
allowed-values:
77
- cargo
8-
platform:
8+
os:
99
type: string
1010
output-file-path:
1111
type: string

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ inputs:
1313
tool:
1414
description: 'Tool to use to get benchmark output. One of "cargo"...'
1515
required: true
16-
platform:
17-
description: 'A string describing the platform'
16+
os:
17+
description: 'A string describing the os'
1818
required: true
1919
output-file-path:
2020
description: 'A path to file which contains the benchmark output'

src/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66
export type ToolType = typeof VALID_TOOLS[number];
77
export interface Config {
88
name: string;
9-
platform: string;
9+
os: string;
1010
tool: ToolType;
1111
outputFilePath: string;
1212
dataOutPath: string;
@@ -71,22 +71,22 @@ function validateName(name: string) {
7171
}
7272
throw new Error('Name must not be empty');
7373
}
74-
function validatePlatform(platform: string) {
75-
if (platform) {
74+
function validateOs(os: string) {
75+
if (os) {
7676
return;
7777
}
78-
throw new Error('Platform must not be empty');
78+
throw new Error('Os must not be empty');
7979
}
8080

8181
export async function configFromJobInput(): Promise<Config> {
8282
const tool: string = core.getInput('tool');
8383
let outputFilePath: string = core.getInput('output-file-path');
8484
let dataOutPath: string = core.getInput('data-out-path');
8585
const name: string = core.getInput('name');
86-
const platform: string = core.getInput('platform');
86+
const os: string = core.getInput('os');
8787

8888
validateName(name);
89-
validatePlatform(platform);
89+
validateOs(os);
9090
validateToolType(tool);
9191
outputFilePath = await validateOutputFilePath(outputFilePath);
9292
dataOutPath = await validateDataOutPath(dataOutPath);
@@ -96,6 +96,6 @@ export async function configFromJobInput(): Promise<Config> {
9696
tool,
9797
outputFilePath,
9898
dataOutPath,
99-
platform,
99+
os,
100100
};
101101
}

src/extract.ts

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,61 @@ import { promises as fs } from 'fs';
33
import { Config } from './config';
44

55
export interface BenchmarkResult {
6-
name: string;
76
value: number;
87
range?: string;
98
unit: string;
109
extra?: string;
11-
platform: string;
10+
os: string;
11+
12+
// from NameMetadata
13+
category: string | undefined;
14+
keySize: number | undefined;
15+
name: string;
16+
platform: string | undefined;
17+
api: string | undefined;
18+
}
19+
20+
interface NameMetadata {
21+
category: string | undefined;
22+
keySize: number | undefined;
23+
name: string;
24+
platform: string | undefined;
25+
api: string | undefined;
26+
}
27+
function extractMetadataFromName(name_string: string): NameMetadata {
28+
// split by separator
29+
const values = name_string.split('/');
30+
31+
// if only one arg provided, just return name
32+
if (values.length === 1) {
33+
const name = name_string;
34+
return { name, keySize: undefined, category: undefined, platform: undefined, api: undefined };
35+
}
36+
37+
// extract by position
38+
const category = values[0] === '' ? undefined : values[0];
39+
40+
// If keySize not a number, use `undefined`
41+
const keySizeParsed = parseInt(values[1]);
42+
43+
const keySize = isNaN(keySizeParsed) ? undefined : keySizeParsed;
44+
45+
// if name is not defined, keep entire name_string as name
46+
let name = values[2];
47+
if (name === undefined || name === '') {
48+
name = name_string;
49+
}
50+
51+
const platform = values[3] === '' ? undefined : values[3];
52+
const api = values[4] === '' ? undefined : values[4];
53+
54+
return {
55+
category,
56+
keySize,
57+
name,
58+
platform,
59+
api,
60+
};
1261
}
1362

1463
function extractCargoResult(config: Config, output: string): BenchmarkResult[] {
@@ -23,17 +72,24 @@ function extractCargoResult(config: Config, output: string): BenchmarkResult[] {
2372
continue;
2473
}
2574

26-
const name = m[1].trim();
75+
const name_string = m[1].trim();
2776
const value = parseFloat(m[2].replace(reComma, ''));
2877
const unit = m[3].trim();
2978
const range = m[4].replace(reComma, '');
3079

80+
// TODO: error handling
81+
const { category, keySize, name, platform, api } = extractMetadataFromName(name_string);
82+
3183
ret.push({
32-
name,
3384
value,
3485
range: ${range}`,
3586
unit: unit,
36-
platform: config.platform,
87+
os: config.os,
88+
category,
89+
keySize,
90+
name,
91+
platform,
92+
api,
3793
});
3894
}
3995

0 commit comments

Comments
 (0)