-
Notifications
You must be signed in to change notification settings - Fork 34
Dev script - Extract fatimage.yml logs to analyse packer build times #435
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0302eb6
Create extract_logs.py
bertiethorpe 415cc59
Update extract_logs.py
bertiethorpe ba60b0c
Ignore irrelevant paths in workflow trigger
sd109 a96f3cc
Update extract_logs.py
bertiethorpe c4ad768
Update extract_logs.py
bertiethorpe 9fd5db8
Update stackhpc.yml
bertiethorpe c3f49c9
Update stackhpc.yml
bertiethorpe a090ce9
Update stackhpc.yml
bertiethorpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,82 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Process packer build workflow logs into CSV. Useful for timing | ||
dissemination. | ||
|
||
Usage: | ||
extract_logs.py <logs.txt> | ||
|
||
Where logs.txt is the name of the workflow log downloaded. | ||
It will list task name, against task directory path, against time to complete. | ||
""" | ||
|
||
import csv | ||
import re | ||
import os | ||
import sys | ||
|
||
def convert_time_to_seconds(time_str): | ||
h, m, s = time_str.split(':') | ||
return int(h) * 3600 + int(m) * 60 + float(s) | ||
|
||
def extract_log_info_and_generate_csv(log_file_path, output_csv_path, target_directory): | ||
data = [] | ||
|
||
unwanted_chars = re.compile(r'(\x1B\[[0-9;]*m)|([^\x00-\x7F])') | ||
|
||
with open(log_file_path, 'r') as file: | ||
lines = file.readlines() | ||
|
||
previous_task = None | ||
|
||
for i in range(len(lines)): | ||
if "TASK [" in lines[i]: | ||
task_name = lines[i].strip().split('TASK [')[1].split(']')[0] | ||
|
||
full_task_path = lines[i + 1].strip().split('task path: ')[1] | ||
if target_directory in full_task_path: | ||
start_index = full_task_path.find(target_directory) + len(target_directory) | ||
partial_task_path = full_task_path[start_index:] | ||
else: | ||
partial_task_path = full_task_path | ||
|
||
partial_task_path = unwanted_chars.sub('', partial_task_path).strip() | ||
|
||
time_to_complete = lines[i + 2].strip().split('(')[1].split(')')[0] | ||
|
||
if previous_task: | ||
previous_task[2] = time_to_complete # Shift the time to the previous task | ||
data.append(previous_task) | ||
|
||
previous_task = [task_name, partial_task_path, None] # Placeholder for the next time_to_complete | ||
|
||
if previous_task: | ||
previous_task[2] = time_to_complete if time_to_complete else 'N/A' | ||
data.append(previous_task) | ||
|
||
for row in data: | ||
if row[2] != 'N/A': | ||
row[2] = convert_time_to_seconds(row[2]) | ||
|
||
data.sort(key=lambda x: x[2], reverse=True) | ||
|
||
for row in data: | ||
if isinstance(row[2], float): | ||
row[2] = f'{int(row[2] // 3600):02}:{int((row[2] % 3600) // 60):02}:{row[2] % 60:.3f}' | ||
|
||
with open(output_csv_path, 'w', newline='') as csvfile: | ||
csvwriter = csv.writer(csvfile) | ||
csvwriter.writerow(['Task Name', 'Task Path', 'Time to Complete']) | ||
csvwriter.writerows(data) | ||
|
||
print(f"Data extracted, sorted, and saved to {output_csv_path}") | ||
|
||
if len(sys.argv) != 2: | ||
print("Path to workflow log plain text file should be provided as the only arg to this script") | ||
sys.exit(1) | ||
log_file_path = sys.argv[1] # Input workflow log name | ||
output_csv_path = log_file_path.replace('.txt.', '.csv') # Output CSV name | ||
target_directory = '/ansible/' # Shared directory for task path | ||
|
||
extract_log_info_and_generate_csv(log_file_path, output_csv_path, target_directory) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.