Deno 開(kāi)發(fā)工具

2020-06-24 17:06 更新

測(cè)試

測(cè)試 deno:

  1. ## 運(yùn)行所有測(cè)試套件:
  2. cargo test
  3. ## 只測(cè)試 cli/js/:
  4. cargo test js_unit_tests

測(cè)試 std/:

  1. cargo test std_tests

代碼檢查與格式化 檢查

./tools/lint.py 格式化

  1. ./tools/format.py

性能分析

  1. ## 確認(rèn)我們正在構(gòu)建發(fā)布版 (release)。
  2. ## 構(gòu)建 deno 和 V8 的 d8。
  3. ninja -C target/release d8
  4. ## 使用 --prof 選項(xiàng)運(yùn)行想要分析的程序。
  5. ./target/release/deno run tests/http_bench.ts --allow-net --v8-flags=--prof &
  6. ## 施加壓力。
  7. third_party/wrk/linux/wrk http://localhost:4500/
  8. kill `pgrep deno`

V8 將在當(dāng)前目錄寫(xiě)入一個(gè)文件,像這樣 isolate-0x7fad98242400-v8.log。查看這個(gè)文件:

  1. D8_PATH=target/release/ ./third_party/v8/tools/linux-tick-processor
  2. isolate-0x7fad98242400-v8.log > prof.log
  3. ## 在 macOS 上, 使用 ./third_party/v8/tools/mac-tick-processor

prof.log 將包含不用調(diào)用的 tick 分布。 用 Web UI 查看這個(gè)日志,先生成 JSON 文件:

  1. D8_PATH=target/release/ ./third_party/v8/tools/linux-tick-processor
  2. isolate-0x7fad98242400-v8.log --preprocess > prof.json

在您的瀏覽器中打開(kāi) third_party/v8/tools/profview/index.html,選擇 prof.json 以查看分布圖。 在性能分析時(shí)有用的 V8 選項(xiàng):

使用 LLDB 調(diào)試

Debugging with LLDB

  1. $ lldb -- target/debug/deno run tests/worker.js
  2. \> run
  3. \> bt
  4. \> up
  5. \> up
  6. \> l

調(diào)試 Rust 代碼,可以用 rust-lldb。

  1. $ rust-lldb -- ./target/debug/deno run --allow-net tests/http_bench.ts
  2. ## 在 macOS 上,您可能看到像這樣的警告:
  3. ## `ImportError: cannot import name _remove_dead_weakref`
  4. ## 在這種情況下,設(shè)置 PATH 以使用系統(tǒng) python,例如
  5. ## PATH=/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
  6. (lldb) command script import "/Users/kevinqian/.rustup/toolchains/1.36.0-x86_64-apple-darwin/lib/rustlib/etc/lldb_rust_formatters.py"
  7. (lldb) type summary add --no-value --python-function lldb_rust_formatters.print_val -x ".*" --category Rust
  8. (lldb) type category enable Rust
  9. (lldb) target create "../deno/target/debug/deno"
  10. Current executable set to '../deno/target/debug/deno' (x86_64).
  11. (lldb) settings set -- target.run-args "tests/http_bench.ts" "--allow-net"
  12. (lldb) b op_start
  13. (lldb) r

V8 選項(xiàng)

V8 有很多內(nèi)部的命令行選項(xiàng)。

  1. ## 列出可用的 V8 選項(xiàng)
  2. $ deno --v8-flags=--help
  3. ## 使用多個(gè)選項(xiàng)的示例
  4. $ deno --v8-flags=--expose-gc,--use-strict

特別有用的: --async-stack-trace

持續(xù)的性能測(cè)試

參考我們的測(cè)試 https://deno.land/benchmarks 測(cè)試圖表假設(shè) https://github.com/denoland/benchmark_data/blob/gh-pages/data.json 有著 BenchmarkData[] 類(lèi)型。以下是 BenchmarkData 的定義:

  1. interface ExecTimeData {
  2. mean: number;
  3. stddev: number;
  4. user: number;
  5. system: number;
  6. min: number;
  7. max: number;
  8. }
  9. interface BenchmarkData {
  10. created_at: string;
  11. sha1: string;
  12. benchmark: {
  13. [key: string]: ExecTimeData;
  14. };
  15. binarySizeData: {
  16. [key: string]: number;
  17. };
  18. threadCountData: {
  19. [key: string]: number;
  20. };
  21. syscallCountData: {
  22. [key: string]: number;
  23. };
  24. }
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)