-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import copy | ||
import datetime | ||
import json | ||
import os | ||
import ydb | ||
import uuid | ||
import subprocess | ||
|
||
DATABASE_PATH = "/ru-central1/b1ggceeul2pkher8vhb6/etn6d1qbals0c29ho4lf" | ||
|
||
FROM_ENV_COLUMNS = [ | ||
"GITHUB_HEAD_REF", | ||
"GITHUB_WORKFLOW", | ||
"GITHUB_WORKFLOW_REF", | ||
"GITHUB_SHA", | ||
"GITHUB_REPOSITORY", | ||
"GITHUB_EVENT_NAME", | ||
"GITHUB_REF_TYPE", | ||
"GITHUB_REF_NAME", | ||
"GITHUB_REF", | ||
"build_preset", | ||
"build_target", | ||
] | ||
|
||
UTF8_COLUMNS = [val.lower() for val in FROM_ENV_COLUMNS] + [ | ||
"id", | ||
"git_commit_message", | ||
"path", | ||
] | ||
|
||
DATETIME_COLUMNS = [ | ||
"git_commit_time", | ||
] | ||
|
||
UINT64_COLUMNS = [] | ||
|
||
DOUBLE_COLUMNS = ["total_compilation_time_s", "compilation_time_s"] | ||
|
||
ALL_COLUMNS = UTF8_COLUMNS + DATETIME_COLUMNS + UINT64_COLUMNS | ||
|
||
|
||
def sanitize_str(s): | ||
return s or "N\\A" | ||
|
||
|
||
def generate_column_types(row): | ||
column_types = ydb.BulkUpsertColumns() | ||
for column_name in row: | ||
if column_name in UTF8_COLUMNS: | ||
column_types = column_types.add_column(column_name, ydb.PrimitiveType.Utf8) | ||
elif column_name in UINT64_COLUMNS: | ||
column_types = column_types.add_column(column_name, ydb.PrimitiveType.Uint64) | ||
elif column_name in DOUBLE_COLUMNS: | ||
column_types = column_types.add_column(column_name, ydb.PrimitiveType.Double) | ||
elif column_name in DATETIME_COLUMNS: | ||
column_types = column_types.add_column(column_name, ydb.PrimitiveType.Datetime) | ||
else: | ||
assert False | ||
return column_types | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-c", | ||
"--html-dir-cpp", | ||
required=True, | ||
help="Path to treemap view of compilation times", | ||
) | ||
parser.add_argument( | ||
"-i", | ||
"--html-dir-headers", | ||
required=False, | ||
default="html_headers_impact", | ||
help="Path to treemap view of headers impact on cpp compilation", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
|
||
if "CI_YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS" not in os.environ: | ||
print("Env variable CI_YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS is missing, skipping") | ||
return 1 | ||
|
||
# Do not set up 'real' variable from gh workflows because it interfere with ydb tests | ||
# So, set up it locally | ||
os.environ["YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"] = os.environ["CI_YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"] | ||
|
||
with ydb.Driver( | ||
endpoint="grpcs://ydb.serverless.yandexcloud.net:2135", | ||
database=DATABASE_PATH, | ||
credentials=ydb.credentials_from_env_variables(), | ||
) as driver: | ||
driver.wait(timeout=10, fail_fast=True) | ||
|
||
column_types = ydb.BulkUpsertColumns() | ||
for type_ in UTF8_COLUMNS: | ||
column_types = column_types.add_column(type_, ydb.PrimitiveType.Utf8) | ||
for type_ in UINT64_COLUMNS: | ||
column_types = column_types.add_column(type_, ydb.PrimitiveType.Uint64) | ||
for type_ in DATETIME_COLUMNS: | ||
column_types = column_types.add_column(type_, ydb.PrimitiveType.Datetime) | ||
for type_ in DOUBLE_COLUMNS: | ||
column_types = column_types.add_column(type_, ydb.PrimitiveType.Double) | ||
|
||
build_preset = os.environ.get("build_preset", None) | ||
github_sha = os.environ.get("GITHUB_SHA", None) | ||
|
||
if github_sha is not None: | ||
git_commit_time_bytes = subprocess.check_output(["git", "show", "--no-patch", "--format=%cI", github_sha]) | ||
git_commit_message_bytes = subprocess.check_output(["git", "log", "--format=%s", "-n", "1", github_sha]) | ||
git_commit_time = datetime.datetime.fromisoformat(git_commit_time_bytes.decode("utf-8").strip()) | ||
git_commit_message = git_commit_message_bytes.decode("utf-8").strip() | ||
git_commit_time_unix = int(git_commit_time.timestamp()) | ||
else: | ||
git_commit_time = None | ||
git_commit_message = None | ||
git_commit_time_unix = 0 | ||
|
||
common_parameters = { | ||
"build_preset": sanitize_str(build_preset), | ||
"git_commit_time": git_commit_time_unix, | ||
"git_commit_message": sanitize_str(git_commit_message), | ||
} | ||
|
||
for column in FROM_ENV_COLUMNS: | ||
value = os.environ.get(column, None) | ||
common_parameters[column.lower()] = sanitize_str(value) | ||
|
||
with open(os.path.join(args.html_dir_cpp, "output.json")) as f: | ||
cpp_stats = json.load(f) | ||
|
||
rows = [] | ||
|
||
for entry in cpp_stats["cpp_compilation_times"]: | ||
path = entry["path"] | ||
time_s = entry["time_s"] | ||
row = copy.copy(common_parameters) | ||
row["path"] = sanitize_str(path) | ||
row["compilation_time_s"] = time_s | ||
row["id"] = str(uuid.uuid4()) | ||
rows.append(copy.copy(row)) | ||
|
||
if rows: | ||
row = rows[0] | ||
driver.table_client.bulk_upsert(DATABASE_PATH + "/code-agility/cpp_compile_time", rows, generate_column_types(row)) | ||
|
||
row = copy.copy(common_parameters) | ||
row["id"] = str(uuid.uuid4()) | ||
row["total_compilation_time_s"] = cpp_stats["total_compilation_time"] | ||
|
||
driver.table_client.bulk_upsert(DATABASE_PATH + "/code-agility/total_compile_time", [row], generate_column_types(row)) | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |