From c7920c9ebf0031dd2c7664ea5cc128af51e64167 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 4 Jun 2023 15:39:36 -0700 Subject: Initial support for writing --debug=time, count into a JSON file --- SCons/Debug.py | 1 + SCons/Script/Main.py | 6 +++++- SCons/Util/stats.py | 38 ++++++++++++++++++++++++++++++++------ SCons/__init__.py | 6 +++--- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/SCons/Debug.py b/SCons/Debug.py index fa07743..ea359f6 100644 --- a/SCons/Debug.py +++ b/SCons/Debug.py @@ -196,6 +196,7 @@ TimeStampDefault = False StartTime = time.perf_counter() PreviousTime = StartTime + def Trace(msg, tracefile=None, mode='w', tstamp=False): """Write a trace message. diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py index ec34c12..572a2e7 100644 --- a/SCons/Script/Main.py +++ b/SCons/Script/Main.py @@ -62,7 +62,7 @@ import SCons.Taskmaster import SCons.Util import SCons.Warnings import SCons.Script.Interactive -from SCons.Util.stats import COUNT_STATS, MEMORY_STATS, ENABLE_JSON, WriteJsonFile +from SCons.Util.stats import COUNT_STATS, MEMORY_STATS, TIME_STATS, ENABLE_JSON, WriteJsonFile from SCons import __version__ as SConsVersion @@ -208,6 +208,7 @@ class BuildTask(SCons.Taskmaster.OutOfDateTask): "Command execution end timestamp: %s: %f\n" % (str(self.node), finish_time) ) + TIME_STATS.add_command(str(self.node), (finish_time - start_time)) sys.stdout.write( "Command execution time: %s: %f seconds\n" % (str(self.node), (finish_time - start_time)) @@ -646,6 +647,7 @@ def _set_debug_values(options): options.tree_printers.append(TreePrinter(status=True)) if "time" in debug_values: print_time = True + TIME_STATS.enable(sys.stdout) if "action-timestamps" in debug_values: print_time = True print_action_timestamps = True @@ -1419,6 +1421,8 @@ def main(): print("Total SConscript file execution time: %f seconds"%sconscript_time) print("Total SCons execution time: %f seconds"%scons_time) print("Total command execution time: %f seconds"%ct) + TIME_STATS.total_times(total_time, sconscript_time, scons_time, ct) + if SCons.Util.stats.ENABLE_JSON: WriteJsonFile() diff --git a/SCons/Util/stats.py b/SCons/Util/stats.py index ccad165..177f363 100644 --- a/SCons/Util/stats.py +++ b/SCons/Util/stats.py @@ -51,11 +51,6 @@ def AddStatType(name, stat_object): ALL_STATS[name] = stat_object -# Local Variables: -# tab-width:4 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=4 shiftwidth=4: class Stats: def __init__(self): self.stats = [] @@ -126,8 +121,29 @@ class MemStats(Stats): self.outfp.write(fmt % (label, stats)) +class TimeStats(Stats): + def __init__(self): + super().__init__() + self.totals = {} + self.commands = {} # we get order from insertion order, and can address individual via dict + + def total_times(self, build_time, sconscript_time, scons_exec_time, command_exec_time): + self.totals = { + 'build_time': build_time, + 'sconscript_time': sconscript_time, + 'scons_exec_time': scons_exec_time, + 'command_exec_time': command_exec_time + } + + def add_command(self, command, command_time): + if command in self.commands: + print("Duplicate command %s" % command) + self.commands[command] = command_time + + COUNT_STATS = CountStats() MEMORY_STATS = MemStats() +TIME_STATS = TimeStats() def WriteJsonFile(): @@ -150,7 +166,17 @@ def WriteJsonFile(): m = json_structure['Memory'] for label, stats in zip(MEMORY_STATS.labels, MEMORY_STATS.stats): - m[label] =stats + m[label] = stats + + if TIME_STATS.enabled: + json_structure['Time'] = {'Commands': TIME_STATS.commands, + 'Totals': TIME_STATS.totals} with open("scons_stats.json", 'w') as sf: sf.write(json.dumps(json_structure)) + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/SCons/__init__.py b/SCons/__init__.py index 9804f4f..f0f241d 100644 --- a/SCons/__init__.py +++ b/SCons/__init__.py @@ -1,9 +1,9 @@ __version__="4.5.2" __copyright__="Copyright (c) 2001 - 2023 The SCons Foundation" __developer__="bdbaddog" -__date__="Sat, 22 Apr 2023 16:48:09 -0700" +__date__="Sun, 04 Jun 2023 15:36:48 -0700" __buildsys__="M1Dog2021" -__revision__="176711bd1fde814e9c441ae44132eb600063ec7a" -__build__="176711bd1fde814e9c441ae44132eb600063ec7a" +__revision__="b3744e8862927899e3d0ebcb41297f9b4c142c63" +__build__="b3744e8862927899e3d0ebcb41297f9b4c142c63" # make sure compatibility is always in place import SCons.compat # noqa \ No newline at end of file -- cgit v0.12