Skip to content

[Github] Add ability to record jobs over time to job counting script #82137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions llvm/utils/count_running_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import argparse
import github
import sys
import time


def main(token, filter_gha_runners):
Expand Down Expand Up @@ -44,6 +46,8 @@ def main(token, filter_gha_runners):

print(f"\nFound {in_progress_jobs} running jobs.")

return in_progress_jobs


if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand All @@ -56,6 +60,20 @@ def main(token, filter_gha_runners):
default=None,
nargs="?",
)
parser.add_argument(
"--output-file",
type=str,
help="The output file to write time-series data to",
default=None,
nargs="?",
)
parser.add_argument(
"--data-collection-interval",
type=int,
help="The number of seconds between data collection intervals",
default=None,
nargs="?",
)
parser.add_argument(
"--filter-gha-runners",
help="Only consider jobs running on hosted Github actions runners",
Expand All @@ -68,6 +86,31 @@ def main(token, filter_gha_runners):
help="Consider all running jobs",
)
parser.set_defaults(filter_gha_runners=False)

args = parser.parse_args()
main(args.token, args.filter_gha_runners)

# Perform some basic argument validation

# If an output file is specified, the user must also specify the data
# collection interval.
if bool(args.output_file) and not bool(args.data_collection_interval):
print("A data collection interval must be specified when --output_file is used")
sys.exit(1)

if args.data_collection_interval:
while True:
current_time = time.localtime()
current_time_string = time.strftime("%Y/%m/%d %H:%M:%S", current_time)

print(f"Collecting data at {current_time_string}")

current_job_count = main(args.token, args.filter_gha_runners)

if args.output_file:
with open(args.output_file, "a") as output_file_handle:
output_file_handle.write(
f"{current_time_string},{current_job_count}\n"
)

time.sleep(args.data_collection_interval)
else:
main(args.token, args.filter_gha_runners)