Skip to content

Commit

Permalink
Remove xml from sort_ninja_log.py utility (#16274)
Browse files Browse the repository at this point in the history
Removes xml support from the `sort_ninja_log.py` utility. The xml support was experimental for possible use with Jenkins reporting that never materialized.
This script is used in build.sh generally when running local builds.

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Srinivas Yadav (https://github.com/srinivasyadav18)
  - Bradley Dice (https://github.com/bdice)

URL: #16274
  • Loading branch information
davidwendt authored Jul 17, 2024
1 parent 6a954e2 commit 2f8d514
Showing 1 changed file with 9 additions and 49 deletions.
58 changes: 9 additions & 49 deletions cpp/scripts/sort_ninja_log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
#
import argparse
import os
Expand All @@ -9,14 +9,12 @@
from xml.dom import minidom

parser = argparse.ArgumentParser()
parser.add_argument(
"log_file", type=str, default=".ninja_log", help=".ninja_log file"
)
parser.add_argument("log_file", type=str, default=".ninja_log", help=".ninja_log file")
parser.add_argument(
"--fmt",
type=str,
default="csv",
choices=["csv", "xml", "html"],
choices=["csv", "html"],
help="output format (to stdout)",
)
parser.add_argument(
Expand All @@ -37,6 +35,7 @@
output_fmt = args.fmt
cmp_file = args.cmp_log


# build a map of the log entries
def build_log_map(log_file):
entries = {}
Expand Down Expand Up @@ -68,37 +67,6 @@ def build_log_map(log_file):
return entries


# output results in XML format
def output_xml(entries, sorted_list, args):
root = ET.Element("testsuites")
testsuite = ET.Element(
"testsuite",
attrib={
"name": "build-time",
"tests": str(len(sorted_list)),
"failures": str(0),
"errors": str(0),
},
)
root.append(testsuite)
for name in sorted_list:
entry = entries[name]
build_time = float(entry[1] - entry[0]) / 1000
item = ET.Element(
"testcase",
attrib={
"classname": "BuildTime",
"name": name,
"time": str(build_time),
},
)
testsuite.append(item)

tree = ET.ElementTree(root)
xmlstr = minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ")
print(xmlstr)


# utility converts a millisecond value to a column width in pixels
def time_to_width(value, end):
# map a value from (0,end) to (0,1000)
Expand Down Expand Up @@ -282,9 +250,7 @@ def output_html(entries, sorted_list, cmp_entries, args):

# output detail table in build-time descending order
print("<table id='detail' bgcolor='#EEEEEE'>")
print(
"<tr><th>File</th>", "<th>Compile time</th>", "<th>Size</th>", sep=""
)
print("<tr><th>File</th>", "<th>Compile time</th>", "<th>Size</th>", sep="")
if cmp_entries:
print("<th>t-cmp</th>", sep="")
print("</tr>")
Expand All @@ -303,9 +269,7 @@ def output_html(entries, sorted_list, cmp_entries, args):
print("<td align='right'>", build_time_str, "</td>", sep="", end="")
print("<td align='right'>", file_size_str, "</td>", sep="", end="")
# output diff column
cmp_entry = (
cmp_entries[name] if cmp_entries and name in cmp_entries else None
)
cmp_entry = cmp_entries[name] if cmp_entries and name in cmp_entries else None
if cmp_entry:
diff_time = build_time - (cmp_entry[1] - cmp_entry[0])
diff_time_str = format_build_time(diff_time)
Expand Down Expand Up @@ -353,7 +317,7 @@ def output_html(entries, sorted_list, cmp_entries, args):
print(
"<tr><td",
white,
">time change &lt; 20%% or build time &lt; 1 minute</td></tr>",
">time change &lt; 20% or build time &lt; 1 minute</td></tr>",
)
print("</table>")

Expand All @@ -370,9 +334,7 @@ def output_csv(entries, sorted_list, cmp_entries, args):
entry = entries[name]
build_time = entry[1] - entry[0]
file_size = entry[2]
cmp_entry = (
cmp_entries[name] if cmp_entries and name in cmp_entries else None
)
cmp_entry = cmp_entries[name] if cmp_entries and name in cmp_entries else None
print(build_time, file_size, name, sep=",", end="")
if cmp_entry:
diff_time = build_time - (cmp_entry[1] - cmp_entry[0])
Expand All @@ -396,9 +358,7 @@ def output_csv(entries, sorted_list, cmp_entries, args):
# load the comparison build log if available
cmp_entries = build_log_map(cmp_file) if cmp_file else None

if output_fmt == "xml":
output_xml(entries, sorted_list, args)
elif output_fmt == "html":
if output_fmt == "html":
output_html(entries, sorted_list, cmp_entries, args)
else:
output_csv(entries, sorted_list, cmp_entries, args)

0 comments on commit 2f8d514

Please sign in to comment.