forked from ocurrent/current-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added cb-schema inside pipeline * Using cb-schema in the frontend * Using cb-schema in cobench * Added cb-check! with explanation in README
- Loading branch information
1 parent
2708340
commit 761e97f
Showing
32 changed files
with
648 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,19 @@ To be able to run your benchmarks, current-bench assumes certain things about yo | |
⚠️ The benchmarks are run on a single core (for now), so either don't include parallel benchmarks, or don't take the results at face value. | ||
|
||
### JSon format | ||
To be able to draw graphs from your results, they need to follow this format: | ||
To be able to draw graphs from your results, they need to follow a specific format. | ||
You can automatically check that your output conforms to that format by calling `cb-check`: | ||
|
||
<!-- remove the pin when cb-check hits opam --> | ||
```bash | ||
opam pin -n cb-check [email protected]:ocurrent/current-bench.git | ||
opam install cb-check | ||
your_executable | cb-check | ||
# OR, if your_executable writes in some_file.json | ||
cb-check some_file.json | ||
``` | ||
|
||
A description of that format is also specified below for convenience: | ||
|
||
```json | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
synopsis: "Json schema checker for current-bench" | ||
maintainer: ["Ambre Austen Suhamy <[email protected]>"] | ||
authors: ["Ambre Austen Suhamy <[email protected]>"] | ||
homepage: "https://github.com/ocurrent/current-bench" | ||
bug-reports: "https://github.com/ocurrent/current-bench/issues" | ||
depends: [ | ||
"dune" {>= "2.9"} | ||
"ocaml" {>= "4.13.0"} | ||
"yojson" | ||
"odoc" {with-doc} | ||
] | ||
build: [ | ||
["dune" "subst"] {dev} | ||
[ | ||
"dune" | ||
"build" | ||
"-p" | ||
name | ||
"-j" | ||
jobs | ||
"--promote-install-files=false" | ||
"@install" | ||
"@runtest" {with-test} | ||
"@doc" {with-doc} | ||
] | ||
["dune" "install" "-p" name "--create-install-files" name] | ||
] | ||
dev-repo: "git+https://github.com/ocurrent/current-bench.git" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(executable | ||
(name main) | ||
(package cb-check) | ||
(public_name cb-check) | ||
(libraries yojson)) | ||
|
||
(copy_files ../pipeline/cb-schema/*.ml) | ||
|
||
(copy_files ../pipeline/lib/json_parsing.ml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
let read_all ic = | ||
let b = Buffer.create 80 in | ||
let rec loop () = | ||
let line = input_line ic in | ||
Buffer.add_string b (line ^ "\n"); | ||
loop () | ||
in | ||
try loop () | ||
with End_of_file -> | ||
close_in ic; | ||
Buffer.contents b | ||
|
||
let pp = Yojson.Safe.pretty_print ~std:false | ||
|
||
let validate l = | ||
let aux (str, _) = | ||
match Yojson.Safe.from_string str with | ||
| j -> ( | ||
match Cb_schema.S.of_json j with | ||
| s -> Some s | ||
| exception Invalid_argument s -> | ||
Format.eprintf | ||
"Some valid json didn't conform to the schema with error: \ | ||
%[email protected] json: %a@." | ||
s pp j; | ||
None) | ||
| exception Yojson.Json_error s -> | ||
Format.eprintf "\x1b[91mJson parsing failure, please report: \x1b[0m%s" | ||
s; | ||
exit 1 | ||
in | ||
match List.filter_map aux l with | ||
| [] -> | ||
Format.printf "No schema-valid results were parsed.@."; | ||
exit 1 | ||
| validated -> | ||
Format.printf "Correctly parsed some benchmarks:@."; | ||
Cb_schema.S.merge [] validated | ||
|> List.map Cb_schema.S.to_json | ||
|> List.iter (fun j -> Format.printf "%a@." pp j) | ||
|
||
let () = | ||
let ic = if Array.length Sys.argv >= 2 then open_in Sys.argv.(1) else stdin in | ||
let contents = read_all ic in | ||
match Json_parsing.full contents with | ||
| [] -> | ||
Format.eprintf | ||
"\x1b[91mCouldn't parse anything, verify that you output correct \ | ||
json.\x1b[0m@."; | ||
exit 1 | ||
| l -> validate (List.rev l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,13 @@ | |
(and | ||
(>= 1.0.0) | ||
:with-test)))) | ||
|
||
(package | ||
(name cb-check) | ||
(synopsis "Json schema checker for current-bench") | ||
(authors "Ambre Austen Suhamy <[email protected]>") | ||
(maintainers "Ambre Austen Suhamy <[email protected]>") | ||
(depends | ||
(ocaml | ||
(>= 4.13.0)) | ||
yojson)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../pipeline/cb-schema/json.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../pipeline/cb-schema/schema.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(* Warning: This library is used in the pipeline, the checker, AND the frontend. | ||
* It must remain compatible with Rescript ~= OCaml 4.06 with a few missing stdlib modules | ||
* and must have no external dependency. | ||
*) | ||
|
||
module Json = Json | ||
module S = Schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(library | ||
(name cb_schema) | ||
(public_name cb-schema)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
type t = | ||
(* Yojson.Safe.t = *) | ||
[ `Null | ||
| `Bool of bool | ||
| `Int of int | ||
| `Intlit of string | ||
| `Float of float | ||
| `String of string | ||
| `Assoc of (string * t) list | ||
| `List of t list | ||
| `Tuple of t list | ||
| `Variant of string * t option ] | ||
|
||
let error key value_type value = | ||
match value with | ||
| `Null -> invalid_arg @@ Format.sprintf "Mandatory key %S not found." key | ||
| _ -> | ||
invalid_arg | ||
@@ Format.sprintf | ||
"The value of key %S had an expected type of `%s`, but the value \ | ||
didn't fit." | ||
key value_type | ||
|
||
let get_opt key = function | ||
| `Assoc obj -> ( | ||
match List.assoc_opt key obj with None -> `Null | Some x -> x) | ||
| _ -> `Null | ||
|
||
let to_string_option = function `String s -> Some s | _ -> None | ||
let to_int_option = function `Int s -> Some s | _ -> None | ||
let to_list_option = function `List xs -> Some xs | _ -> None | ||
let to_list key = function `List xs -> xs | j -> error key "list" j | ||
|
||
let get ?(context = "") key j = | ||
let err () = | ||
error | ||
(if context = "" then key else context ^ "/" ^ key) | ||
"json object" `Null | ||
in | ||
match get_opt key j with `Null -> err () | x -> x | ||
|
||
let to_string key = function `String s -> s | j -> error key "string" j | ||
|
||
let to_float key = function | ||
| `Float x -> x | ||
| `Int x -> float_of_int x | ||
| j -> error key "float" j |
Oops, something went wrong.