Last active
May 12, 2020 09:55
-
-
Save mkorpela/0a38a0442e601766568eb7823297d44c to your computer and use it in GitHub Desktop.
Robot Framework output file size statistics
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
import xml.etree.ElementTree as ET | |
def sizes(element, result): | |
if element.tag not in result: | |
result[element.tag] = [0, 0] | |
result[element.tag][1] += 1 | |
size_before = result[element.tag][0] | |
this_size = 5 + 2*len(element.tag) + \ | |
len(element.text or "") + \ | |
sum(4 + len(k) + len(v) for k, v in element.attrib.items()) + \ | |
sum(1 + sizes(child, result) for child in element) | |
result[element.tag][0] = size_before + this_size | |
return this_size | |
def print_stats(filename): | |
root = ET.parse(filename).getroot() | |
result = {} | |
sizes(root, result) | |
res = reversed(sorted([(size, calls, k) for (k, [size, calls]) in result.items()])) | |
print("Element\t\tSize\t\tCount") | |
print("="*80) | |
for s, c, name in res: | |
print("%s\t\t%s\t\t%s" % (name, s, c)) | |
print("-"*80) | |
if __name__ == "__main__": | |
import sys | |
print_stats(sys.argv[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment