-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
include "common.mc" | ||
include "ast.mc" | ||
include "json-debug.mc" | ||
|
||
lang PhaseStats = Ast | ||
lang PhaseStats = Ast + AstToJson | ||
type StatState = | ||
{ lastPhaseEnd : Ref Float | ||
, log : Bool | ||
, jsonDumpPhases : Set String | ||
} | ||
|
||
sem endPhaseStats : StatState -> String -> Expr -> () | ||
sem endPhaseStats state phaseLabel = | e -> | ||
if state.log then | ||
let before = deref state.lastPhaseEnd in | ||
let now = wallTimeMs () in | ||
let before = deref state.lastPhaseEnd in | ||
let now = wallTimeMs () in | ||
|
||
(if state.log then | ||
printLn phaseLabel; | ||
printLn (join [" Phase duration: ", float2string (subf now before), "ms"]); | ||
let preTraverse = wallTimeMs () in | ||
let size = countExprNodes 0 e in | ||
let postTraverse = wallTimeMs () in | ||
printLn (join [" Ast size: ", int2string size, " (Traversal takes ~", float2string (subf postTraverse preTraverse), "ms)"]); | ||
let newNow = wallTimeMs () in | ||
modref state.lastPhaseEnd newNow | ||
else () | ||
printLn (join [" Ast size: ", int2string size, " (Traversal takes ~", float2string (subf postTraverse preTraverse), "ms)"]) | ||
else ()); | ||
|
||
(if setMem phaseLabel state.jsonDumpPhases then | ||
printJsonLn (JsonString (concat "Computing AST after " phaseLabel)); | ||
let e = exprToJson e in | ||
printJsonLn (JsonString (concat "Printing AST after " phaseLabel)); | ||
printJsonLn e | ||
else ()); | ||
|
||
sem mkPhaseLogState : Bool -> StatState | ||
sem mkPhaseLogState = | log -> { lastPhaseEnd = ref (wallTimeMs ()), log = log } | ||
let newNow = wallTimeMs () in | ||
modref state.lastPhaseEnd newNow | ||
|
||
sem mkPhaseLogState : Set String -> Bool -> StatState | ||
sem mkPhaseLogState jsonDumpPhases = | log -> | ||
{ lastPhaseEnd = ref (wallTimeMs ()) | ||
, jsonDumpPhases = jsonDumpPhases | ||
, log = log | ||
} | ||
end |
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