1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

refactor(bench): continuous benchmarking improvements (#14821)

This commit is contained in:
Divy Srivastava 2022-06-28 17:51:05 +05:30 committed by GitHub
parent 00f4521b20
commit ab11b45d1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 531 additions and 169 deletions

43
.github/workflows/bench_cron.yml vendored Normal file
View file

@ -0,0 +1,43 @@
name: bench
on:
# Runs at minute 9 past hour 0, 6, 12, and 18.
schedule:
- cron: 9 0,6,12,18 * * *
workflow_dispatch:
jobs:
bench:
name: bench / ${{ matrix.os }} / ${{ matrix.deno-version }}
if: github.repository == 'denoland/deno'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04-xl]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
CI: true
GOOGLE_SVC_KEY: ${{ secrets.GOOGLE_SVC_KEY }}
steps:
- name: Clone repository
uses: actions/checkout@v2
with:
submodules: true
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
- name: Build release
run: cargo build --release --locked --all-targets
- name: Worker info
run: |
cat /proc/cpuinfo
cat /proc/meminfo
- name: Run and Post benchmarks
run: cargo bench --locked

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
*.orig *.orig
*.pyc *.pyc
*.swp *.swp
.env
/.cargo_home/ /.cargo_home/
/.idea/ /.idea/

269
Cargo.lock generated
View file

@ -354,6 +354,18 @@ dependencies = [
"alloc-stdlib", "alloc-stdlib",
] ]
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.10.0" version = "3.10.0"
@ -617,6 +629,28 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "csv"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
dependencies = [
"bstr",
"csv-core",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "ctor" name = "ctor"
version = "0.1.22" version = "0.1.22"
@ -735,6 +769,7 @@ dependencies = [
"clap", "clap",
"clap_complete", "clap_complete",
"clap_complete_fig", "clap_complete_fig",
"csv",
"data-url", "data-url",
"deno_ast", "deno_ast",
"deno_bench_util", "deno_bench_util",
@ -747,6 +782,7 @@ dependencies = [
"deno_snapshots", "deno_snapshots",
"deno_task_shell", "deno_task_shell",
"dissimilar", "dissimilar",
"dotenv",
"dprint-plugin-json", "dprint-plugin-json",
"dprint-plugin-markdown", "dprint-plugin-markdown",
"dprint-plugin-typescript", "dprint-plugin-typescript",
@ -756,19 +792,20 @@ dependencies = [
"fancy-regex", "fancy-regex",
"flaky_test", "flaky_test",
"fwdansi", "fwdansi",
"google-storage1",
"http", "http",
"import_map", "import_map",
"indexmap", "indexmap",
"jsonc-parser", "jsonc-parser",
"libc", "libc",
"log", "log 0.4.17",
"mitata", "mitata",
"nix", "nix",
"node_resolver", "node_resolver",
"notify", "notify",
"once_cell", "once_cell",
"os_pipe", "os_pipe",
"percent-encoding", "percent-encoding 2.1.0",
"pin-project", "pin-project",
"pretty_assertions", "pretty_assertions",
"rand", "rand",
@ -827,7 +864,7 @@ dependencies = [
"swc_ecma_utils", "swc_ecma_utils",
"swc_ecma_visit", "swc_ecma_visit",
"text_lines", "text_lines",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -836,6 +873,7 @@ version = "0.52.0"
dependencies = [ dependencies = [
"bencher", "bencher",
"deno_core", "deno_core",
"once_cell",
"tokio", "tokio",
] ]
@ -866,7 +904,7 @@ dependencies = [
"futures", "futures",
"indexmap", "indexmap",
"libc", "libc",
"log", "log 0.4.17",
"once_cell", "once_cell",
"parking_lot 0.12.1", "parking_lot 0.12.1",
"pin-project", "pin-project",
@ -875,7 +913,7 @@ dependencies = [
"serde_v8", "serde_v8",
"sourcemap", "sourcemap",
"tokio", "tokio",
"url", "url 2.2.2",
"v8", "v8",
] ]
@ -990,7 +1028,7 @@ dependencies = [
"serde_json", "serde_json",
"sourcemap", "sourcemap",
"termcolor", "termcolor",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -1008,8 +1046,8 @@ dependencies = [
"flate2", "flate2",
"fly-accept-encoding", "fly-accept-encoding",
"hyper", "hyper",
"mime", "mime 0.3.16",
"percent-encoding", "percent-encoding 2.1.0",
"phf", "phf",
"ring", "ring",
"serde", "serde",
@ -1027,7 +1065,7 @@ dependencies = [
"deno_ast", "deno_ast",
"derive_more", "derive_more",
"if_chain", "if_chain",
"log", "log 0.4.17",
"once_cell", "once_cell",
"regex", "regex",
"serde", "serde",
@ -1040,7 +1078,7 @@ version = "0.50.0"
dependencies = [ dependencies = [
"deno_core", "deno_core",
"deno_tls", "deno_tls",
"log", "log 0.4.17",
"serde", "serde",
"socket2", "socket2",
"tokio", "tokio",
@ -1088,7 +1126,7 @@ dependencies = [
"http", "http",
"hyper", "hyper",
"libc", "libc",
"log", "log 0.4.17",
"lzzzz", "lzzzz",
"netif", "netif",
"nix", "nix",
@ -1141,7 +1179,7 @@ dependencies = [
"once_cell", "once_cell",
"rustls", "rustls",
"rustls-native-certs", "rustls-native-certs",
"rustls-pemfile", "rustls-pemfile 1.0.0",
"serde", "serde",
"webpki", "webpki",
"webpki-roots", "webpki-roots",
@ -1297,6 +1335,12 @@ dependencies = [
"syn 0.15.44", "syn 0.15.44",
] ]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "dprint-core" name = "dprint-core"
version = "0.58.2" version = "0.58.2"
@ -1458,7 +1502,7 @@ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
dependencies = [ dependencies = [
"atty", "atty",
"humantime", "humantime",
"log", "log 0.4.17",
"regex", "regex",
"termcolor", "termcolor",
] ]
@ -1521,7 +1565,7 @@ dependencies = [
"sha2", "sha2",
"thiserror", "thiserror",
"tokio", "tokio",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -1654,7 +1698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191"
dependencies = [ dependencies = [
"matches", "matches",
"percent-encoding", "percent-encoding 2.1.0",
] ]
[[package]] [[package]]
@ -1850,6 +1894,23 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "google-storage1"
version = "3.1.0+20220228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "838c83adf6e1f0e35fa17b343e32762867f8ee8ea1a63e97c5ef5efda751bab9"
dependencies = [
"hyper",
"hyper-rustls",
"itertools",
"mime 0.2.6",
"serde",
"serde_derive",
"serde_json",
"url 1.7.2",
"yup-oauth2",
]
[[package]] [[package]]
name = "gpu-alloc" name = "gpu-alloc"
version = "0.5.3" version = "0.5.3"
@ -2001,7 +2062,7 @@ checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
"itoa", "itoa 1.0.2",
] ]
[[package]] [[package]]
@ -2048,7 +2109,7 @@ dependencies = [
"http-body", "http-body",
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa 1.0.2",
"pin-project-lite", "pin-project-lite",
"socket2", "socket2",
"tokio", "tokio",
@ -2065,7 +2126,9 @@ checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac"
dependencies = [ dependencies = [
"http", "http",
"hyper", "hyper",
"log 0.4.17",
"rustls", "rustls",
"rustls-native-certs",
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
] ]
@ -2076,6 +2139,17 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.2.3" version = "0.2.3"
@ -2100,10 +2174,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5247edf057fe57036112a1fec3864baa68052b52116760dbea4909115731272f" checksum = "5247edf057fe57036112a1fec3864baa68052b52116760dbea4909115731272f"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"log", "log 0.4.17",
"serde", "serde",
"serde_json", "serde_json",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -2208,6 +2282,12 @@ dependencies = [
"either", "either",
] ]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.2" version = "1.0.2"
@ -2438,6 +2518,15 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "log"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
dependencies = [
"log 0.4.17",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.17" version = "0.4.17"
@ -2467,7 +2556,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"serde_repr", "serde_repr",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -2525,10 +2614,19 @@ dependencies = [
"block", "block",
"core-graphics-types", "core-graphics-types",
"foreign-types", "foreign-types",
"log", "log 0.4.17",
"objc", "objc",
] ]
[[package]]
name = "mime"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
dependencies = [
"log 0.3.9",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.16" version = "0.3.16"
@ -2551,7 +2649,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log 0.4.17",
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.36.1", "windows-sys 0.36.1",
] ]
@ -2576,7 +2674,7 @@ dependencies = [
"codespan-reporting", "codespan-reporting",
"hexf-parse", "hexf-parse",
"indexmap", "indexmap",
"log", "log 0.4.17",
"num-traits", "num-traits",
"rustc-hash", "rustc-hash",
"serde", "serde",
@ -2893,6 +2991,12 @@ dependencies = [
"base64ct", "base64ct",
] ]
[[package]]
name = "percent-encoding"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.1.0" version = "2.1.0"
@ -3258,6 +3362,12 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.26" version = "0.6.26"
@ -3305,12 +3415,12 @@ dependencies = [
"ipnet", "ipnet",
"js-sys", "js-sys",
"lazy_static", "lazy_static",
"log", "log 0.4.17",
"mime", "mime 0.3.16",
"percent-encoding", "percent-encoding 2.1.0",
"pin-project-lite", "pin-project-lite",
"rustls", "rustls",
"rustls-pemfile", "rustls-pemfile 1.0.0",
"serde", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
@ -3318,7 +3428,7 @@ dependencies = [
"tokio-rustls", "tokio-rustls",
"tokio-util", "tokio-util",
"tower-service", "tower-service",
"url", "url 2.2.2",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",
@ -3458,7 +3568,7 @@ version = "0.20.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033"
dependencies = [ dependencies = [
"log", "log 0.4.17",
"ring", "ring",
"sct", "sct",
"webpki", "webpki",
@ -3471,11 +3581,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50"
dependencies = [ dependencies = [
"openssl-probe", "openssl-probe",
"rustls-pemfile", "rustls-pemfile 1.0.0",
"schannel", "schannel",
"security-framework", "security-framework",
] ]
[[package]]
name = "rustls-pemfile"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360"
dependencies = [
"base64 0.13.0",
]
[[package]] [[package]]
name = "rustls-pemfile" name = "rustls-pemfile"
version = "1.0.0" version = "1.0.0"
@ -3496,7 +3615,7 @@ dependencies = [
"clipboard-win", "clipboard-win",
"fd-lock", "fd-lock",
"libc", "libc",
"log", "log 0.4.17",
"memchr", "memchr",
"nix", "nix",
"radix_trie", "radix_trie",
@ -3565,6 +3684,12 @@ dependencies = [
"untrusted", "untrusted",
] ]
[[package]]
name = "seahash"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]] [[package]]
name = "sec1" name = "sec1"
version = "0.3.0" version = "0.3.0"
@ -3668,7 +3793,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"itoa", "itoa 1.0.2",
"ryu", "ryu",
"serde", "serde",
] ]
@ -3691,7 +3816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa 1.0.2",
"ryu", "ryu",
"serde", "serde",
] ]
@ -3818,7 +3943,7 @@ dependencies = [
"rustc_version 0.2.3", "rustc_version 0.2.3",
"serde", "serde",
"serde_json", "serde_json",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -3985,7 +4110,7 @@ dependencies = [
"swc_visit", "swc_visit",
"tracing", "tracing",
"unicode-width", "unicode-width",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -4421,7 +4546,7 @@ dependencies = [
"pretty_assertions", "pretty_assertions",
"pty", "pty",
"regex", "regex",
"rustls-pemfile", "rustls-pemfile 1.0.0",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
@ -4490,6 +4615,7 @@ checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd"
dependencies = [ dependencies = [
"libc", "libc",
"num_threads", "num_threads",
"serde",
] ]
[[package]] [[package]]
@ -4567,7 +4693,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e80b39df6afcc12cdf752398ade96a6b9e99c903dfdc36e53ad10b9c366bca72" checksum = "e80b39df6afcc12cdf752398ade96a6b9e99c903dfdc36e53ad10b9c366bca72"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"log", "log 0.4.17",
"rustls", "rustls",
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
@ -4631,7 +4757,7 @@ dependencies = [
"dashmap", "dashmap",
"futures", "futures",
"httparse", "httparse",
"log", "log 0.4.17",
"lsp-types", "lsp-types",
"memchr", "memchr",
"serde", "serde",
@ -4702,7 +4828,7 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"lazy_static", "lazy_static",
"log", "log 0.4.17",
"radix_trie", "radix_trie",
"rand", "rand",
"thiserror", "thiserror",
@ -4724,17 +4850,17 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-io", "futures-io",
"futures-util", "futures-util",
"idna", "idna 0.2.3",
"ipnet", "ipnet",
"lazy_static", "lazy_static",
"log", "log 0.4.17",
"rand", "rand",
"serde", "serde",
"smallvec", "smallvec",
"thiserror", "thiserror",
"tinyvec", "tinyvec",
"tokio", "tokio",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -4747,7 +4873,7 @@ dependencies = [
"futures-util", "futures-util",
"ipconfig", "ipconfig",
"lazy_static", "lazy_static",
"log", "log 0.4.17",
"lru-cache", "lru-cache",
"parking_lot 0.12.1", "parking_lot 0.12.1",
"resolv-conf", "resolv-conf",
@ -4771,7 +4897,7 @@ dependencies = [
"env_logger", "env_logger",
"futures-executor", "futures-executor",
"futures-util", "futures-util",
"log", "log 0.4.17",
"serde", "serde",
"thiserror", "thiserror",
"time 0.3.9", "time 0.3.9",
@ -4798,12 +4924,12 @@ dependencies = [
"bytes", "bytes",
"http", "http",
"httparse", "httparse",
"log", "log 0.4.17",
"rand", "rand",
"rustls", "rustls",
"sha-1 0.9.8", "sha-1 0.9.8",
"thiserror", "thiserror",
"url", "url 2.2.2",
"utf-8", "utf-8",
"webpki", "webpki",
] ]
@ -4957,6 +5083,17 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "url"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
dependencies = [
"idna 0.1.5",
"matches",
"percent-encoding 1.0.1",
]
[[package]] [[package]]
name = "url" name = "url"
version = "2.2.2" version = "2.2.2"
@ -4964,9 +5101,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"idna", "idna 0.2.3",
"matches", "matches",
"percent-encoding", "percent-encoding 2.1.0",
"serde", "serde",
] ]
@ -4980,7 +5117,7 @@ dependencies = [
"regex", "regex",
"serde", "serde",
"unic-ucd-ident", "unic-ucd-ident",
"url", "url 2.2.2",
] ]
[[package]] [[package]]
@ -5053,7 +5190,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
dependencies = [ dependencies = [
"log", "log 0.4.17",
"try-lock", "try-lock",
] ]
@ -5087,7 +5224,7 @@ checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
"log", "log 0.4.17",
"proc-macro2 1.0.39", "proc-macro2 1.0.39",
"quote 1.0.18", "quote 1.0.18",
"syn 1.0.96", "syn 1.0.96",
@ -5176,7 +5313,7 @@ dependencies = [
"codespan-reporting", "codespan-reporting",
"copyless", "copyless",
"fxhash", "fxhash",
"log", "log 0.4.17",
"naga", "naga",
"parking_lot 0.11.2", "parking_lot 0.11.2",
"profiling", "profiling",
@ -5210,7 +5347,7 @@ dependencies = [
"js-sys", "js-sys",
"khronos-egl", "khronos-egl",
"libloading", "libloading",
"log", "log 0.4.17",
"metal", "metal",
"naga", "naga",
"objc", "objc",
@ -5410,6 +5547,32 @@ dependencies = [
"toml", "toml",
] ]
[[package]]
name = "yup-oauth2"
version = "6.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87d859e5b7fb10b5956b30eb1a6da981cdf0d3195fe2c6ff1840424522ca0d51"
dependencies = [
"anyhow",
"async-trait",
"base64 0.13.0",
"futures",
"http",
"hyper",
"hyper-rustls",
"itertools",
"log 0.4.17",
"percent-encoding 2.1.0",
"rustls",
"rustls-pemfile 0.3.0",
"seahash",
"serde",
"serde_json",
"time 0.3.9",
"tokio",
"url 2.2.2",
]
[[package]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.5.5" version = "1.5.5"

View file

@ -16,6 +16,7 @@ path = "lib.rs"
[dependencies] [dependencies]
bencher = "0.1" bencher = "0.1"
deno_core = { version = "0.140.0", path = "../core" } deno_core = { version = "0.140.0", path = "../core" }
once_cell = "1.10.0"
tokio = { version = "1.19", features = ["full"] } tokio = { version = "1.19", features = ["full"] }
[[bench]] [[bench]]

View file

@ -100,8 +100,12 @@ fwdansi = "=1.1.0"
winapi = { version = "=0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] } winapi = { version = "=0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }
[dev-dependencies] [dev-dependencies]
csv = "1.1.6"
deno_bench_util = { version = "0.52.0", path = "../bench_util" } deno_bench_util = { version = "0.52.0", path = "../bench_util" }
dotenv = "0.15.0"
flaky_test = "=0.1.0" flaky_test = "=0.1.0"
google-storage1 = "3.1.0"
once_cell = "=1.12.0"
os_pipe = "=1.0.1" os_pipe = "=1.0.1"
pretty_assertions = "=1.2.1" pretty_assertions = "=1.2.1"
test_util = { path = "../test_util" } test_util = { path = "../test_util" }

10
cli/bench/README.md Normal file
View file

@ -0,0 +1,10 @@
benchmark filtering:
```
cargo bench --bench deno_bench -- bundle
```
benchmark plots:
new: https://denoland.grafana.net/d/vErC9VCnz/benchmarks?orgId=1 old:
deno.land/benchmarks

View file

@ -44,7 +44,7 @@ pub fn benchmark(
if name.starts_with("node") { if name.starts_with("node") {
// node <path> <port> // node <path> <port>
res.insert( res.insert(
name, file_stem.to_string(),
run( run(
&["node", path, &port.to_string()], &["node", path, &port.to_string()],
port, port,
@ -56,7 +56,7 @@ pub fn benchmark(
} else { } else {
// deno run -A --unstable <path> <addr> // deno run -A --unstable <path> <addr>
res.insert( res.insert(
name, file_stem.to_string(),
run( run(
&[ &[
deno_exe, deno_exe,

View file

@ -333,7 +333,7 @@ fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
} }
/// Generate benchmarks for the LSP server. /// Generate benchmarks for the LSP server.
pub fn benchmarks(deno_exe: &Path) -> Result<HashMap<String, u64>, AnyError> { pub fn benchmarks(deno_exe: &Path) -> Result<HashMap<String, i64>, AnyError> {
println!("-> Start benchmarking lsp"); println!("-> Start benchmarking lsp");
let mut exec_times = HashMap::new(); let mut exec_times = HashMap::new();
@ -343,7 +343,7 @@ pub fn benchmarks(deno_exe: &Path) -> Result<HashMap<String, u64>, AnyError> {
times.push(bench_startup_shutdown(deno_exe)?); times.push(bench_startup_shutdown(deno_exe)?);
} }
let mean = let mean =
(times.iter().sum::<Duration>() / times.len() as u32).as_millis() as u64; (times.iter().sum::<Duration>() / times.len() as u32).as_millis() as i64;
println!(" ({} runs, mean: {}ms)", times.len(), mean); println!(" ({} runs, mean: {}ms)", times.len(), mean);
exec_times.insert("startup_shutdown".to_string(), mean); exec_times.insert("startup_shutdown".to_string(), mean);
@ -353,7 +353,7 @@ pub fn benchmarks(deno_exe: &Path) -> Result<HashMap<String, u64>, AnyError> {
times.push(bench_big_file_edits(deno_exe)?); times.push(bench_big_file_edits(deno_exe)?);
} }
let mean = let mean =
(times.iter().sum::<Duration>() / times.len() as u32).as_millis() as u64; (times.iter().sum::<Duration>() / times.len() as u32).as_millis() as i64;
println!(" ({} runs, mean: {}ms)", times.len(), mean); println!(" ({} runs, mean: {}ms)", times.len(), mean);
exec_times.insert("big_file_edits".to_string(), mean); exec_times.insert("big_file_edits".to_string(), mean);
@ -363,7 +363,7 @@ pub fn benchmarks(deno_exe: &Path) -> Result<HashMap<String, u64>, AnyError> {
times.push(bench_find_replace(deno_exe)?); times.push(bench_find_replace(deno_exe)?);
} }
let mean = let mean =
(times.iter().sum::<Duration>() / times.len() as u32).as_millis() as u64; (times.iter().sum::<Duration>() / times.len() as u32).as_millis() as i64;
println!(" ({} runs, mean: {}ms)", times.len(), mean); println!(" ({} runs, mean: {}ms)", times.len(), mean);
exec_times.insert("find_replace".to_string(), mean); exec_times.insert("find_replace".to_string(), mean);
@ -373,7 +373,7 @@ pub fn benchmarks(deno_exe: &Path) -> Result<HashMap<String, u64>, AnyError> {
times.push(bench_code_lens(deno_exe)?); times.push(bench_code_lens(deno_exe)?);
} }
let mean = let mean =
(times.iter().sum::<Duration>() / times.len() as u32).as_millis() as u64; (times.iter().sum::<Duration>() / times.len() as u32).as_millis() as i64;
println!(" ({} runs, mean: {}ms)", times.len(), mean); println!(" ({} runs, mean: {}ms)", times.len(), mean);
exec_times.insert("code_lens".to_string(), mean); exec_times.insert("code_lens".to_string(), mean);

View file

@ -3,7 +3,6 @@
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::serde_json::Value; use deno_core::serde_json::Value;
use serde::Serialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::From; use std::convert::From;
use std::env; use std::env;
@ -16,6 +15,7 @@ use std::time::SystemTime;
mod http; mod http;
mod lsp; mod lsp;
mod metrics;
fn read_json(filename: &str) -> Result<Value> { fn read_json(filename: &str) -> Result<Value> {
let f = fs::File::open(filename)?; let f = fs::File::open(filename)?;
@ -162,7 +162,7 @@ const RESULT_KEYS: &[&str] =
fn run_exec_time( fn run_exec_time(
deno_exe: &Path, deno_exe: &Path,
target_dir: &Path, target_dir: &Path,
) -> Result<HashMap<String, HashMap<String, f64>>> { ) -> Result<HashMap<String, HashMap<String, i64>>> {
let hyperfine_exe = test_util::prebuilt_tool_path("hyperfine"); let hyperfine_exe = test_util::prebuilt_tool_path("hyperfine");
let benchmark_file = target_dir.join("hyperfine_results.json"); let benchmark_file = target_dir.join("hyperfine_results.json");
@ -203,7 +203,7 @@ fn run_exec_time(
true, true,
); );
let mut results = HashMap::<String, HashMap<String, f64>>::new(); let mut results = HashMap::<String, HashMap<String, i64>>::new();
let hyperfine_results = read_json(benchmark_file)?; let hyperfine_results = read_json(benchmark_file)?;
for ((name, _, _), data) in EXEC_TIME_BENCHMARKS.iter().zip( for ((name, _, _), data) in EXEC_TIME_BENCHMARKS.iter().zip(
hyperfine_results hyperfine_results
@ -220,7 +220,7 @@ fn run_exec_time(
data data
.into_iter() .into_iter()
.filter(|(key, _)| RESULT_KEYS.contains(&key.as_str())) .filter(|(key, _)| RESULT_KEYS.contains(&key.as_str()))
.map(|(key, val)| (key, val.as_f64().unwrap())) .map(|(key, val)| (key, val.as_f64().unwrap() as i64))
.collect(), .collect(),
); );
} }
@ -228,7 +228,7 @@ fn run_exec_time(
Ok(results) Ok(results)
} }
fn rlib_size(target_dir: &std::path::Path, prefix: &str) -> u64 { fn rlib_size(target_dir: &std::path::Path, prefix: &str) -> i64 {
let mut size = 0; let mut size = 0;
let mut seen = std::collections::HashSet::new(); let mut seen = std::collections::HashSet::new();
for entry in std::fs::read_dir(target_dir.join("deps")).unwrap() { for entry in std::fs::read_dir(target_dir.join("deps")).unwrap() {
@ -247,18 +247,18 @@ fn rlib_size(target_dir: &std::path::Path, prefix: &str) -> u64 {
} }
} }
assert!(size > 0); assert!(size > 0);
size size as i64
} }
const BINARY_TARGET_FILES: &[&str] = const BINARY_TARGET_FILES: &[&str] =
&["CLI_SNAPSHOT.bin", "COMPILER_SNAPSHOT.bin"]; &["CLI_SNAPSHOT.bin", "COMPILER_SNAPSHOT.bin"];
fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, u64>> { fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, i64>> {
let mut sizes = HashMap::<String, u64>::new(); let mut sizes = HashMap::<String, i64>::new();
let mut mtimes = HashMap::<String, SystemTime>::new(); let mut mtimes = HashMap::<String, SystemTime>::new();
sizes.insert( sizes.insert(
"deno".to_string(), "deno".to_string(),
test_util::deno_exe_path().metadata()?.len(), test_util::deno_exe_path().metadata()?.len() as i64,
); );
// add up size for everything in target/release/deps/libswc* // add up size for everything in target/release/deps/libswc*
@ -294,7 +294,7 @@ fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, u64>> {
} }
mtimes.insert(filename.clone(), file_mtime); mtimes.insert(filename.clone(), file_mtime);
sizes.insert(filename, meta.len()); sizes.insert(filename, meta.len() as i64);
} }
Ok(sizes) Ok(sizes)
@ -304,8 +304,8 @@ const BUNDLES: &[(&str, &str)] = &[
("file_server", "./test_util/std/http/file_server.ts"), ("file_server", "./test_util/std/http/file_server.ts"),
("gist", "./test_util/std/examples/gist.ts"), ("gist", "./test_util/std/examples/gist.ts"),
]; ];
fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> { fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, i64>> {
let mut sizes = HashMap::<String, u64>::new(); let mut sizes = HashMap::<String, i64>::new();
for (name, url) in BUNDLES { for (name, url) in BUNDLES {
let path = format!("{}.bundle.js", name); let path = format!("{}.bundle.js", name);
@ -325,37 +325,182 @@ fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
let file = PathBuf::from(path); let file = PathBuf::from(path);
assert!(file.is_file()); assert!(file.is_file());
sizes.insert(name.to_string(), file.metadata()?.len()); sizes.insert(name.to_string(), file.metadata()?.len() as i64);
let _ = fs::remove_file(file); let _ = fs::remove_file(file);
} }
Ok(sizes) Ok(sizes)
} }
fn run_http(target_dir: &Path, new_data: &mut BenchResult) -> Result<()> { fn run_max_mem_benchmark(deno_exe: &Path) -> Result<HashMap<String, i64>> {
let stats = http::benchmark(target_dir)?; let mut results = HashMap::<String, i64>::new();
new_data.req_per_sec = stats for (name, args, return_code) in EXEC_TIME_BENCHMARKS {
.iter() let proc = Command::new("time")
.map(|(name, result)| (name.clone(), result.requests)) .args(&["-v", deno_exe.to_str().unwrap()])
.collect(); .args(args.iter())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()?;
new_data.max_latency = stats let proc_result = proc.wait_with_output()?;
.iter() if let Some(code) = return_code {
.map(|(name, result)| (name.clone(), result.latency)) assert_eq!(proc_result.status.code().unwrap(), *code);
.collect(); }
let out = String::from_utf8(proc_result.stderr)?;
Ok(()) results.insert(
name.to_string(),
test_util::parse_max_mem(&out).unwrap() as i64,
);
} }
fn run_strace_benchmarks( Ok(results)
deno_exe: &Path, }
new_data: &mut BenchResult,
) -> Result<()> { fn cargo_deps() -> usize {
let cargo_lock = test_util::root_path().join("Cargo.lock");
let mut count = 0;
let file = std::fs::File::open(cargo_lock).unwrap();
use std::io::BufRead;
for line in std::io::BufReader::new(file).lines() {
if line.unwrap().starts_with("[[package]]") {
count += 1
}
}
println!("cargo_deps {}", count);
assert!(count > 10); // Sanity check.
count
}
// TODO(@littledivy): Remove this, denoland/benchmark_data is deprecated.
#[derive(Default, serde::Serialize)]
struct BenchResult {
created_at: String,
sha1: String,
// TODO(ry) The "benchmark" benchmark should actually be called "exec_time".
// When this is changed, the historical data in gh-pages branch needs to be
// changed too.
benchmark: HashMap<String, HashMap<String, i64>>,
binary_size: HashMap<String, i64>,
bundle_size: HashMap<String, i64>,
cargo_deps: usize,
max_latency: HashMap<String, i64>,
max_memory: HashMap<String, i64>,
lsp_exec_time: HashMap<String, i64>,
req_per_sec: HashMap<String, i64>,
syscall_count: HashMap<String, i64>,
thread_count: HashMap<String, i64>,
}
#[tokio::main]
async fn main() -> Result<()> {
let mut args = env::args();
let mut benchmarks = vec![
"bundle",
"exec_time",
"binary_size",
"cargo_deps",
"lsp",
"http",
"strace",
"mem_usage",
];
let mut found_bench = false;
let filter = args.nth(1);
if let Some(filter) = filter {
if filter != "--bench" {
benchmarks.retain(|s| s == &filter);
} else {
found_bench = true;
}
}
if !found_bench && !args.any(|s| s == "--bench") {
return Ok(());
}
println!("Starting Deno benchmark");
let target_dir = test_util::target_dir();
let deno_exe = test_util::deno_exe_path();
env::set_current_dir(&test_util::root_path())?;
let mut new_data = BenchResult {
created_at: chrono::Utc::now()
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
sha1: test_util::run_collect(
&["git", "rev-parse", "HEAD"],
None,
None,
None,
true,
)
.0
.trim()
.to_string(),
..Default::default()
};
let mut reporter = metrics::Reporter::new().await;
if benchmarks.contains(&"bundle") {
let bundle_size = bundle_benchmark(&deno_exe)?;
reporter.write("bundle_size", &bundle_size);
new_data.bundle_size = bundle_size;
}
if benchmarks.contains(&"exec_time") {
let exec_times = run_exec_time(&deno_exe, &target_dir)?;
for (name, data) in exec_times.iter() {
reporter.write_one("exec_time", name, *data.get("mean").unwrap());
}
new_data.benchmark = exec_times;
}
if benchmarks.contains(&"binary_size") {
let binary_sizes = get_binary_sizes(&target_dir)?;
reporter.write("binary_size", &binary_sizes);
new_data.binary_size = binary_sizes;
}
if benchmarks.contains(&"cargo_deps") {
let cargo_deps = cargo_deps();
reporter.write_one("cargo_deps", "cargo_deps", cargo_deps as i64);
new_data.cargo_deps = cargo_deps;
}
if benchmarks.contains(&"lsp") {
let lsp_exec_times = lsp::benchmarks(&deno_exe)?;
reporter.write("lsp_exec_time", &lsp_exec_times);
new_data.lsp_exec_time = lsp_exec_times;
}
if benchmarks.contains(&"http") && cfg!(not(target_os = "windows")) {
let stats = http::benchmark(&target_dir)?;
let req_per_sec = stats
.iter()
.map(|(name, result)| (name.clone(), result.requests as i64))
.collect();
reporter.write("req_per_sec", &req_per_sec);
new_data.req_per_sec = req_per_sec;
let max_latency = stats
.iter()
.map(|(name, result)| (name.clone(), result.latency as i64))
.collect();
reporter.write("max_latency", &max_latency);
new_data.max_latency = max_latency;
}
if cfg!(target_os = "linux") && benchmarks.contains(&"strace") {
use std::io::Read; use std::io::Read;
let mut thread_count = HashMap::<String, u64>::new(); let mut thread_count = HashMap::<String, i64>::new();
let mut syscall_count = HashMap::<String, u64>::new(); let mut syscall_count = HashMap::<String, i64>::new();
for (name, args, expected_exit_code) in EXEC_TIME_BENCHMARKS { for (name, args, expected_exit_code) in EXEC_TIME_BENCHMARKS {
let mut file = secure_tempfile::NamedTempFile::new()?; let mut file = secure_tempfile::NamedTempFile::new()?;
@ -381,127 +526,23 @@ fn run_strace_benchmarks(
let strace_result = test_util::parse_strace_output(&output); let strace_result = test_util::parse_strace_output(&output);
let clone = strace_result.get("clone").map(|d| d.calls).unwrap_or(0) + 1; let clone = strace_result.get("clone").map(|d| d.calls).unwrap_or(0) + 1;
let total = strace_result.get("total").unwrap().calls; let total = strace_result.get("total").unwrap().calls;
thread_count.insert(name.to_string(), clone); thread_count.insert(name.to_string(), clone as i64);
syscall_count.insert(name.to_string(), total); syscall_count.insert(name.to_string(), total as i64);
} }
reporter.write("thread_count", &thread_count);
new_data.thread_count = thread_count; new_data.thread_count = thread_count;
reporter.write("syscall_count", &syscall_count);
new_data.syscall_count = syscall_count; new_data.syscall_count = syscall_count;
Ok(())
} }
fn run_max_mem_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> { if benchmarks.contains(&"mem_usage") {
let mut results = HashMap::<String, u64>::new(); let max_memory = run_max_mem_benchmark(&deno_exe)?;
reporter.write("max_memory", &max_memory);
for (name, args, return_code) in EXEC_TIME_BENCHMARKS { new_data.max_memory = max_memory;
let proc = Command::new("time")
.args(&["-v", deno_exe.to_str().unwrap()])
.args(args.iter())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()?;
let proc_result = proc.wait_with_output()?;
if let Some(code) = return_code {
assert_eq!(proc_result.status.code().unwrap(), *code);
}
let out = String::from_utf8(proc_result.stderr)?;
results.insert(name.to_string(), test_util::parse_max_mem(&out).unwrap());
} }
Ok(results) reporter.submit().await;
}
fn cargo_deps() -> usize {
let cargo_lock = test_util::root_path().join("Cargo.lock");
let mut count = 0;
let file = std::fs::File::open(cargo_lock).unwrap();
use std::io::BufRead;
for line in std::io::BufReader::new(file).lines() {
if line.unwrap().starts_with("[[package]]") {
count += 1
}
}
println!("cargo_deps {}", count);
assert!(count > 10); // Sanity check.
count
}
#[derive(Default, Serialize)]
struct BenchResult {
created_at: String,
sha1: String,
// TODO(ry) The "benchmark" benchmark should actually be called "exec_time".
// When this is changed, the historical data in gh-pages branch needs to be
// changed too.
benchmark: HashMap<String, HashMap<String, f64>>,
binary_size: HashMap<String, u64>,
bundle_size: HashMap<String, u64>,
cargo_deps: usize,
max_latency: HashMap<String, f64>,
max_memory: HashMap<String, u64>,
lsp_exec_time: HashMap<String, u64>,
req_per_sec: HashMap<String, u64>,
syscall_count: HashMap<String, u64>,
thread_count: HashMap<String, u64>,
}
/*
TODO(SyrupThinker)
Switch to the #[bench] attribute once
it is stabilized.
Before that the #[test] tests won't be run because
we replace the harness with our own runner here.
*/
fn main() -> Result<()> {
if !env::args().any(|s| s == "--bench") {
return Ok(());
}
println!("Starting Deno benchmark");
let target_dir = test_util::target_dir();
let deno_exe = test_util::deno_exe_path();
env::set_current_dir(&test_util::root_path())?;
let mut new_data = BenchResult {
created_at: chrono::Utc::now()
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
sha1: test_util::run_collect(
&["git", "rev-parse", "HEAD"],
None,
None,
None,
true,
)
.0
.trim()
.to_string(),
benchmark: run_exec_time(&deno_exe, &target_dir)?,
binary_size: get_binary_sizes(&target_dir)?,
bundle_size: bundle_benchmark(&deno_exe)?,
cargo_deps: cargo_deps(),
lsp_exec_time: lsp::benchmarks(&deno_exe)?,
..Default::default()
};
if cfg!(not(target_os = "windows")) {
run_http(&target_dir, &mut new_data)?;
}
if cfg!(target_os = "linux") {
run_strace_benchmarks(&deno_exe, &mut new_data)?;
new_data.max_memory = run_max_mem_benchmark(&deno_exe)?;
}
println!("===== <BENCHMARK RESULTS>");
serde_json::to_writer_pretty(std::io::stdout(), &new_data)?;
println!("\n===== </BENCHMARK RESULTS>");
if let Some(filename) = target_dir.join("bench.json").to_str() { if let Some(filename) = target_dir.join("bench.json").to_str() {
write_json(filename, &serde_json::to_value(&new_data)?)?; write_json(filename, &serde_json::to_value(&new_data)?)?;
} else { } else {

99
cli/bench/metrics.rs Normal file
View file

@ -0,0 +1,99 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use google_storage1::api::Object;
use google_storage1::hyper;
use google_storage1::hyper_rustls;
use google_storage1::oauth2;
use google_storage1::Storage;
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::io::Cursor;
static GIT_HASH: Lazy<String> = Lazy::new(|| {
test_util::run_collect(&["git", "rev-parse", "HEAD"], None, None, None, true)
.0
.trim()
.to_string()
});
#[derive(serde::Serialize)]
struct Metric {
name: String,
value: i64,
sha1: String,
#[serde(rename = "type")]
type_: String,
time: i64,
}
pub struct Reporter {
wtr: csv::Writer<Vec<u8>>,
gcloud_client: Option<Storage>,
}
impl Reporter {
pub async fn new() -> Self {
dotenv::dotenv().ok();
let gcloud_client =
match std::env::var("CI").map(|_| std::env::var("GOOGLE_SVC_KEY")) {
Ok(Ok(key_str)) => {
let secret = oauth2::parse_service_account_key(key_str)
.expect("Failed to load service account key");
let auth =
oauth2::authenticator::ServiceAccountAuthenticator::builder(secret)
.build()
.await
.unwrap();
let client = hyper::Client::builder().build(
hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.https_or_http()
.enable_http1()
.enable_http2()
.build(),
);
Some(Storage::new(client, auth))
}
_ => None,
};
Self {
wtr: csv::Writer::from_writer(vec![]),
gcloud_client,
}
}
pub fn write_one(&mut self, type_: &str, name: &str, value: i64) {
self
.wtr
.serialize(Metric {
name: name.to_string(),
type_: type_.to_string(),
value,
sha1: GIT_HASH.clone(),
time: chrono::Utc::now().timestamp_millis(),
})
.unwrap();
}
pub fn write(&mut self, type_: &str, hashmap: &HashMap<String, i64>) {
for (name, value) in hashmap {
self.write_one(type_, name, *value);
}
}
pub async fn submit(mut self) {
self.wtr.flush().unwrap();
if let Some(client) = self.gcloud_client.take() {
let mut reader = Cursor::new(self.wtr.into_inner().unwrap());
let object: Object = Object::default();
client
.objects()
.insert(object, "deno_benchmark_data")
.name(&format!("{}.csv", *GIT_HASH))
.param("uploadType", "multipart")
.upload(&mut reader, "text/csv".parse().unwrap())
.await
.unwrap();
}
}
}