Ai
3 Star 6 Fork 0

Gitee 极速下载/viztracer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/gaogaotiantian/viztracer
克隆/下载
util.py 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/gaogaotiantian/viztracer/blob/master/NOTICE.txt
import json
import os
import re
import subprocess
import sys
def generate_json(filename):
data_dir = os.path.join(os.path.dirname(__file__), "data")
cwd = os.getcwd()
os.chdir(data_dir)
path = os.path.join(os.path.dirname(__file__), "data", filename)
subprocess.run([sys.executable, path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
os.chdir(cwd)
def adapt_json_file(filename):
path = os.path.join(os.path.dirname(__file__), "data", filename)
py_filename = ".".join(filename.split(".")[:-1] + ["py"])
py_path_lst = path.split(".")
py_path_lst[-1] = "py"
py_path = ".".join(py_path_lst)
with open(path) as f:
data = json.loads(f.read())
name_regex = re.compile(r"(.*) \((.*):([0-9]*)\)")
for event in data["traceEvents"]:
if event["ph"] == "X":
try:
m = name_regex.match(event["name"])
if m and py_filename in event["name"]:
event["name"] = f"{m.group(1)} ({py_path}:{m.group(3)})"
except ValueError:
pass
with open(path, "w") as f:
f.write(json.dumps(data))
def get_tests_data_file_path(filename):
return os.path.join(os.path.dirname(__file__), "data", filename)
def cmd_with_coverage(cmd):
assert "python" not in cmd, \
"Do not use unqualified 'python' to launch intrepreter. Passing sys.executable is the recommended way."
if os.getenv("COVERAGE_RUN"):
if cmd[0] == sys.executable:
return ["coverage", "run", "--source", "viztracer", "--parallel-mode"] + cmd[1:]
elif cmd[0] == "viztracer":
return ["coverage", "run", "--source", "viztracer", "--parallel-mode", "-m"] + cmd
else:
raise ValueError(f"can't get cmd with coverage for {cmd}")
return cmd
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/viztracer.git
git@gitee.com:mirrors/viztracer.git
mirrors
viztracer
viztracer
master

搜索帮助