Skip to content

Commit

Permalink
Merge branch 'timings'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertzui123 committed Jul 25, 2024
2 parents d66d22c + 7134742 commit 4e58728
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 66 deletions.
2 changes: 2 additions & 0 deletions cli/main.aspl
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
14 changes: 12 additions & 2 deletions stdlib/aspl/compiler/main.aspl
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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){
Expand All @@ -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){
Expand All @@ -159,6 +166,9 @@ function compile(string main) returns CompilationResult{
if(!Options:keepTemporary){
io.delete_file(tempFile)
}
if(Options:showTimings){
Timings:show()
}
}
}
return result
Expand Down
4 changes: 4 additions & 0 deletions stdlib/aspl/parser/Options.aspl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class Options {
[public]
[static]
[threadlocal]
property bool showTimings = false
[public]
[static]
[threadlocal]
property string backend = "ail"
[public]
[static]
Expand Down
89 changes: 25 additions & 64 deletions stdlib/aspl/parser/Timings.aspl
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, long> 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 ---")
}

}
1 change: 1 addition & 0 deletions stdlib/aspl/parser/main.aspl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4e58728

Please sign in to comment.