Skip to content

Instantly share code, notes, and snippets.

@Jaa-c
Last active February 27, 2019 18:40
Show Gist options
  • Select an option

  • Save Jaa-c/65604e573bf6862526e97d06d2828d3c to your computer and use it in GitHub Desktop.

Select an option

Save Jaa-c/65604e573bf6862526e97d06d2828d3c to your computer and use it in GitHub Desktop.
Fixing compilation output for UECompileTimesVisualizer
import sys
log_file = "log.txt" if len(sys.argv) < 2 else sys.argv[1]
result = list() # this is the result file
insertPosition = dict()
currentBlock = list() # current text that will be moved as soon as we encounter next time()
parseBlock = False # true if inside the section that should be moved
with open(log_file, 'r') as file:
for line in file:
if line.lstrip().startswith(('link', 'cl', 'rc', 'Compiling...')): # string after last time() entry before compilation continues
parseBlock = False
if line.strip().startswith('lib '):
continue
# mostly Qt specific stuff we want to ignore in the resulting log
if any(s in line for s in ("Generating Code...", "Compiling...", "jom.exe", "rcc -binary", "uic.exe", "rcc.exe", "moc.exe", "time::build::")):
continue
if parseBlock:
currentBlock.append(line)
else:
result.append(line)
if line.startswith("time("):
line = line.rstrip()
currentFile = line[line.rfind('[')+1:-1]
if currentFile not in insertPosition: # this is the first entry for this file (c1xx)
# if this asserts, just check whats your first entry after last time() and add it to the first if
assert not parseBlock, "entry should already exist! line: {}".format(line)
insertPosition[currentFile] = len(result)
else: # this is the second entry for this file (c2), we move all previous code to the correct location
index = insertPosition[currentFile]
result[index:index] = currentBlock # this works only because the time of c2 is in reverse order compared to c1xx (we write from the end so the indices are not invalidated)
insertPosition.pop(currentFile)
currentBlock.clear()
parseBlock = True
print("moved " + currentFile + " to position " + str(index))
with open('result-' + log_file, 'w') as file:
print('Writing result to file...')
for line in result:
file.write(line)
print("ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment