From 7134742ad7c78ab29a662fdfc9cb4e637cb833e6 Mon Sep 17 00:00:00 2001 From: Wertzui123 <46199283+Wertzui123@users.noreply.github.com> Date: Tue, 23 Jul 2024 01:17:53 +0200 Subject: [PATCH] aspl: add a simple timing mechanism for the different compilation passes --- cli/main.aspl | 2 + stdlib/aspl/compiler/main.aspl | 14 +++++- stdlib/aspl/parser/Options.aspl | 4 ++ stdlib/aspl/parser/Timings.aspl | 89 +++++++++------------------------ stdlib/aspl/parser/main.aspl | 1 + 5 files changed, 44 insertions(+), 66 deletions(-) diff --git a/cli/main.aspl b/cli/main.aspl index 2b423ff..f4922f9 100644 --- a/cli/main.aspl +++ b/cli/main.aspl @@ -59,6 +59,8 @@ if(os.args()[1].startsWith("-")){ Options:production = true }elseif(option == "-gui"){ Options:guiApp = true + }elseif(option == "-showtimings"){ + Options:showTimings = true }elseif(option == "-backend"){ i++ if(i >= os.args().length){ diff --git a/stdlib/aspl/compiler/main.aspl b/stdlib/aspl/compiler/main.aspl index 34ae4fa..a9e27fd 100644 --- a/stdlib/aspl/compiler/main.aspl +++ b/stdlib/aspl/compiler/main.aspl @@ -17,7 +17,6 @@ $if main{ } var main = io.abs(os.args()[1]) compile(main) - //print("Took: " + (Timings:total / 1000) + " seconds") var string? mainOutFile = null var tempFile = aspl.compiler.utils.out_temp_name(main) var tempFileParts = tempFile.replace("\\", "/").split("/") @@ -51,7 +50,9 @@ function compile(string main) returns CompilationResult{ }elseif(Options:backend == "c"){ backend = new CBackend() } - var result = backend.compile(aspl.parser.parse()) + var parserResult = aspl.parser.parse() + Timings:startPass("compile") + var result = backend.compile(parserResult) var tempFile = aspl.compiler.utils.out_temp_name(main) var tempFileParts = tempFile.replace("\\", "/").split("/") tempFile = tempFileParts[tempFileParts.length - 1] @@ -125,6 +126,7 @@ function compile(string main) returns CompilationResult{ if(Options:showCCommand){ print("cc: " + ccmd) } + Timings:startPass("c compiler (building template)") var ccmdResult = os.execute(ccmd) print(ccmdResult.output, false) if(ccmdResult.exitCode != 0){ @@ -141,16 +143,21 @@ function compile(string main) returns CompilationResult{ io.write_file_bytes(exeFile, io.read_file_bytes(template)) } if(!Options:internalDoNotBundle){ + Timings:startPass("bundle") os.chmod(exeFile, 509) var Bundle bundle = new Bundle(exeFile) bundle.addResource("AIL Code", result.output) bundle.generate() } + if(Options:showTimings){ + Timings:show() + } }elseif(Options:backend == "c"){ var ccmd = build_ccmd(tempFile, exeFile) if(Options:showCCommand){ print("cc: " + ccmd) } + Timings:startPass("c compiler") var ccmdResult = os.execute(ccmd) print(ccmdResult.output, false) if(ccmdResult.exitCode != 0){ @@ -159,6 +166,9 @@ function compile(string main) returns CompilationResult{ if(!Options:keepTemporary){ io.delete_file(tempFile) } + if(Options:showTimings){ + Timings:show() + } } } return result diff --git a/stdlib/aspl/parser/Options.aspl b/stdlib/aspl/parser/Options.aspl index 4219bc3..c786753 100644 --- a/stdlib/aspl/parser/Options.aspl +++ b/stdlib/aspl/parser/Options.aspl @@ -70,6 +70,10 @@ class Options { [public] [static] [threadlocal] + property bool showTimings = false + [public] + [static] + [threadlocal] property string backend = "ail" [public] [static] diff --git a/stdlib/aspl/parser/Timings.aspl b/stdlib/aspl/parser/Timings.aspl index c2512da..d25e77b 100644 --- a/stdlib/aspl/parser/Timings.aspl +++ b/stdlib/aspl/parser/Timings.aspl @@ -6,86 +6,47 @@ class Timings { [static] [threadlocal] - property long lexer = 0 + property string? currentPassName [static] [threadlocal] - property long lexerStart = 0 + property Timestamp? currentPassStart [static] [threadlocal] - property long preprocessorTypes = 0 - [static] - [threadlocal] - property long preprocessorTypesStart = 0 - [static] - [threadlocal] - property long preprocessor = 0 - [static] - [threadlocal] - property long preprocessorStart = 0 - [static] - [threadlocal] - property long parser = 0 - [static] - [threadlocal] - property long parserStart = 0 + property map passDurations [public] [static] - property long total{ + property long totalDuration{ get{ - return self:lexer + self:lexerStart + self:preprocessorTypes + self:preprocessor + self:parser + var long total = 0 + foreach(passDurations as duration){ + total += duration + } } } [public] [static] - method startLexer(){ - self:lexerStart = time.now().milliseconds - } - - [public] - [static] - method stopLexer(){ - self:lexer = time.now().milliseconds - self:lexerStart - self:lexerStart = 0 - } - - [public] - [static] - method startPreprocessorTypes(){ - self:preprocessorTypesStart = time.now().milliseconds - } - - [public] - [static] - method stopPreprocessorTypes(){ - self:preprocessorTypes = time.now().milliseconds - self:preprocessorTypesStart - self:preprocessorTypes = 0 - } - - [public] - [static] - method startPreprocessor(){ - self:preprocessorStart = time.now().milliseconds - } - - [public] - [static] - method stopPreprocessor(){ - self:preprocessor = time.now().milliseconds - self:preprocessorStart - self:preprocessorStart = 0 - } - - [public] - [static] - method startParser(){ - self:parserStart = time.now().milliseconds + method startPass(string name){ + if(self:currentPassName != null){ + self:passDurations[self:currentPassName?!] = time.now().milliseconds - currentPassStart?!.milliseconds + } + self:currentPassName = name + self:currentPassStart = time.now() } [public] [static] - method stopParser(){ - self:parser = time.now().milliseconds - self:parserStart - self:parserStart = 0 + method show(){ + if(self:currentPassName != null){ + self:passDurations[self:currentPassName?!] = time.now().milliseconds - currentPassStart?!.milliseconds + } + self:currentPassName = null + self:currentPassStart = null + print("+++ Timings +++") + foreach(passDurations as name => duration){ + print(name + ": " + duration + "ms") + } + print("--- Timings ---") } } \ No newline at end of file diff --git a/stdlib/aspl/parser/main.aspl b/stdlib/aspl/parser/main.aspl index 94db914..5c34902 100644 --- a/stdlib/aspl/parser/main.aspl +++ b/stdlib/aspl/parser/main.aspl @@ -28,6 +28,7 @@ $if main{ [public] function parse() returns ParserResult { + Timings:startPass("parse") foreach(DirectoryUtils:index(Module:mainModule.directory) as file){ if(!Parser:importProcessedFiles.contains(file)){ Parser:importProcessedFiles.add(file)