Skip to content

Commit 9c6df7d

Browse files
[Github] Add ability to record jobs over time to job counting script (#82137)
This patch adds new flags to the count_running_jobs.py script to enable the collection of data over a period of time. Specifically, the --output_file flag is added to enable writing output data to a file, and the --data-collection-interval flag is added to configure the frequency that the script checks the job count.
1 parent 76a2472 commit 9c6df7d

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

llvm/utils/count_running_jobs.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import argparse
1616
import github
17+
import sys
18+
import time
1719

1820

1921
def main(token, filter_gha_runners):
@@ -44,6 +46,8 @@ def main(token, filter_gha_runners):
4446

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

49+
return in_progress_jobs
50+
4751

4852
if __name__ == "__main__":
4953
parser = argparse.ArgumentParser(
@@ -56,6 +60,20 @@ def main(token, filter_gha_runners):
5660
default=None,
5761
nargs="?",
5862
)
63+
parser.add_argument(
64+
"--output-file",
65+
type=str,
66+
help="The output file to write time-series data to",
67+
default=None,
68+
nargs="?",
69+
)
70+
parser.add_argument(
71+
"--data-collection-interval",
72+
type=int,
73+
help="The number of seconds between data collection intervals",
74+
default=None,
75+
nargs="?",
76+
)
5977
parser.add_argument(
6078
"--filter-gha-runners",
6179
help="Only consider jobs running on hosted Github actions runners",
@@ -68,6 +86,31 @@ def main(token, filter_gha_runners):
6886
help="Consider all running jobs",
6987
)
7088
parser.set_defaults(filter_gha_runners=False)
71-
7289
args = parser.parse_args()
73-
main(args.token, args.filter_gha_runners)
90+
91+
# Perform some basic argument validation
92+
93+
# If an output file is specified, the user must also specify the data
94+
# collection interval.
95+
if bool(args.output_file) and not bool(args.data_collection_interval):
96+
print("A data collection interval must be specified when --output_file is used")
97+
sys.exit(1)
98+
99+
if args.data_collection_interval:
100+
while True:
101+
current_time = time.localtime()
102+
current_time_string = time.strftime("%Y/%m/%d %H:%M:%S", current_time)
103+
104+
print(f"Collecting data at {current_time_string}")
105+
106+
current_job_count = main(args.token, args.filter_gha_runners)
107+
108+
if args.output_file:
109+
with open(args.output_file, "a") as output_file_handle:
110+
output_file_handle.write(
111+
f"{current_time_string},{current_job_count}\n"
112+
)
113+
114+
time.sleep(args.data_collection_interval)
115+
else:
116+
main(args.token, args.filter_gha_runners)

0 commit comments

Comments
 (0)