Skip to content

Commit

Permalink
improve profiler interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbackrack committed Jan 24, 2025
1 parent b0aa576 commit 7fd1535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 5 additions & 4 deletions compiler/main.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ defn run-with-timing-log<?T> (body:() -> ?T, cmd-args:CommandArgs) -> T :
;If -profile-compiler flag is provided, then execute the body
;with support for profiling.
defn run-with-profiler<?T> (body:() -> ?T, cmd-args:CommandArgs) -> T :
if flag?(cmd-args, "profile-compiler") :
profiling(body, 100, { stack-collapse(_, cmd-args["profile-compiler"]) })
else :
body()
generate<T> :
if flag?(cmd-args, "profile-compiler") :
stack-collapse(profiling({ yield(body()) }, 100), cmd-args["profile-compiler"])
else :
body()

;============================================================
;====================== Verbosity ===========================
Expand Down
7 changes: 3 additions & 4 deletions core/profiler.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,10 @@ public defn stop-profiling () -> ProfileResult:
collect-profiling(do-stop-sample-profiling())

;Profiling wrapper to be called with within
public defn profiling<?T> (f:() -> ?T, msecs:Int, g:ProfileResult -> ? = { false }) -> T :
public defn profiling (f:() -> ?, msecs:Int) -> ProfileResult :
start-profiling(msecs)
val res = f()
g(stop-profiling())
res
f()
stop-profiling()

;;; convert to flame-graph format using traditional stack-collapse function

Expand Down

0 comments on commit 7fd1535

Please sign in to comment.