bm_main.py 1.27 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
#!/usr/bin/env python3
2
# Copyright (c) Meta Platforms, Inc. and affiliates.
Patrick Labatut's avatar
Patrick Labatut committed
3
4
5
6
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
facebook-github-bot's avatar
facebook-github-bot committed
7
8

import glob
Christoph Lassner's avatar
Christoph Lassner committed
9
10
11
12
import os
import subprocess
import sys
from os.path import dirname, isfile, join
facebook-github-bot's avatar
facebook-github-bot committed
13

14

generatedunixname89002005287564's avatar
generatedunixname89002005287564 committed
15
def main() -> None:
facebook-github-bot's avatar
facebook-github-bot committed
16
17
18
19
    # pyre-ignore[16]
    if len(sys.argv) > 1:
        # Parse from flags.
        # pyre-ignore[16]
Christoph Lassner's avatar
Christoph Lassner committed
20
21
22
        file_names = [
            join(dirname(__file__), n) for n in sys.argv if n.startswith("bm_")
        ]
facebook-github-bot's avatar
facebook-github-bot committed
23
24
25
    else:
        # Get all the benchmark files (starting with "bm_").
        bm_files = glob.glob(join(dirname(__file__), "bm_*.py"))
Christoph Lassner's avatar
Christoph Lassner committed
26
27
28
        file_names = sorted(
            f for f in bm_files if isfile(f) and not f.endswith("bm_main.py")
        )
facebook-github-bot's avatar
facebook-github-bot committed
29

Christoph Lassner's avatar
Christoph Lassner committed
30
31
32
33
34
35
36
37
38
    # Forward all important path information to the subprocesses through the
    # environment.
    os.environ["PATH"] = sys.path[0] + ":" + os.environ.get("PATH", "")
    os.environ["LD_LIBRARY_PATH"] = (
        sys.path[0] + ":" + os.environ.get("LD_LIBRARY_PATH", "")
    )
    os.environ["PYTHONPATH"] = ":".join(sys.path)
    for file_name in file_names:
        subprocess.check_call([sys.executable, file_name])
generatedunixname89002005287564's avatar
generatedunixname89002005287564 committed
39
40
41
42


if __name__ == "__main__":
    main()  # pragma: no cover