summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-09-24 18:12:52 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-09-24 18:12:52 -0400
commit1729bdb0d7f504436cacc07bedba642591fdb0cb (patch)
tree8d9fb23ef2b942e8df6fea7b6637185fa1a0d709 /tools
parentd6a97ae4f02a7150165877e304778c96b90ddd5a (diff)
Add thread count benchmark (#811)
Diffstat (limited to 'tools')
-rwxr-xr-xtools/benchmark.py25
-rw-r--r--tools/benchmark_test.py10
-rwxr-xr-xtools/test.py13
3 files changed, 42 insertions, 6 deletions
diff --git a/tools/benchmark.py b/tools/benchmark.py
index d9decefbb..837a86180 100755
--- a/tools/benchmark.py
+++ b/tools/benchmark.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# Performs benchmark and append data to //website/data.json.
# If //website/data.json doesn't exist, this script tries to import it from gh-pages branch.
# To view the results locally run ./tools/http_server.py and visit
@@ -10,6 +11,7 @@ import json
import time
import shutil
from util import run, run_output, root_path, build_path
+import tempfile
# The list of the tuples of the benchmark name and arguments
benchmarks = [("hello", ["tests/002_hello.ts", "--reload"]),
@@ -43,6 +45,23 @@ def import_data_from_gh_pages():
write_json(data_file, []) # writes empty json data
+# run strace with test_args and record times a syscall record appears in out file
+# based on syscall_line_matcher. Should be reusable
+def count_strace_syscall(syscall_name, syscall_line_matcher, test_args):
+ f = tempfile.NamedTemporaryFile()
+ run(["strace", "-f", "-o", f.name, "-e", "trace=" + syscall_name] +
+ test_args)
+ return len(filter(syscall_line_matcher, f))
+
+
+def run_thread_count_benchmark(deno_path):
+ thread_count_map = {}
+ thread_count_map["set_timeout"] = count_strace_syscall(
+ "clone", lambda line: "clone(" in line,
+ [deno_path, "tests/004_set_timeout.ts", "--reload"]) + 1
+ return thread_count_map
+
+
def main(argv):
if len(argv) == 2:
build_dir = sys.argv[1]
@@ -67,6 +86,7 @@ def main(argv):
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ"),
"sha1": sha1,
"binary_size": os.path.getsize(deno_path),
+ "thread_count": {},
"benchmark": {}
}
for [[name, _], data] in zip(benchmarks, benchmark_data["results"]):
@@ -78,6 +98,11 @@ def main(argv):
"min": data["min"],
"max": data["max"]
}
+
+ if "linux" in sys.platform:
+ # Thread count test, only on linux
+ new_data["thread_count"] = run_thread_count_benchmark(deno_path)
+
all_data.append(new_data)
write_json(data_file, all_data)
diff --git a/tools/benchmark_test.py b/tools/benchmark_test.py
new file mode 100644
index 000000000..017314fbb
--- /dev/null
+++ b/tools/benchmark_test.py
@@ -0,0 +1,10 @@
+import sys
+import os
+from benchmark import run_thread_count_benchmark
+
+
+def benchmark_test(deno_path):
+ if "linux" in sys.platform:
+ thread_count_dict = run_thread_count_benchmark(deno_path)
+ assert "set_timeout" in thread_count_dict
+ assert thread_count_dict["set_timeout"] > 1
diff --git a/tools/test.py b/tools/test.py
index 3cd03e916..ac3a5ca95 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -8,6 +8,7 @@ from setup_test import setup_test
from util import build_path, enable_ansi_colors, executable_suffix, run
from unit_tests import unit_tests
from util_test import util_test
+from benchmark_test import benchmark_test
import subprocess
import http_server
@@ -32,9 +33,15 @@ def main(argv):
http_server.spawn()
+ deno_exe = os.path.join(build_dir, "deno" + executable_suffix)
+ check_exists(deno_exe)
+ deno_ns_exe = os.path.join(build_dir, "deno_ns" + executable_suffix)
+ check_exists(deno_ns_exe)
+
# Internal tools testing
setup_test()
util_test()
+ benchmark_test(deno_exe)
test_cc = os.path.join(build_dir, "test_cc" + executable_suffix)
check_exists(test_cc)
@@ -44,15 +51,9 @@ def main(argv):
check_exists(test_rs)
run([test_rs])
- deno_exe = os.path.join(build_dir, "deno" + executable_suffix)
- check_exists(deno_exe)
unit_tests(deno_exe)
- check_exists(deno_exe)
check_output_test(deno_exe)
-
- deno_ns_exe = os.path.join(build_dir, "deno_ns" + executable_suffix)
- check_exists(deno_ns_exe)
check_output_test(deno_ns_exe)