Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 0 additions & 197 deletions bench/src/sjsonnet/bench/ProfilingEvaluator.scala

This file was deleted.

88 changes: 0 additions & 88 deletions bench/src/sjsonnet/bench/RunProfiler.scala

This file was deleted.

6 changes: 3 additions & 3 deletions sjsonnet/src-jvm-native/sjsonnet/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ final case class Config(
)
maxStack: Int = 500,
@arg(
name = "flamegraph",
name = "profile",
doc =
"Write a flame graph profile in folded stack format to the given file. Use with https://github.com/brendangregg/FlameGraph"
"Profile evaluation and write results to a file. Format: --profile <file> or --profile <format>:<file> where format is 'text' (default) or 'flamegraph'"
)
flamegraph: Option[String] = None,
profile: Option[String] = None,
@arg(
doc = "The jsonnet file you wish to evaluate",
positional = true
Expand Down
29 changes: 21 additions & 8 deletions sjsonnet/src-jvm-native/sjsonnet/SjsonnetMainBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object SjsonnetMainBase {
warn,
std,
debugStats = debugStats,
flamegraphFile = config.flamegraph
profileOpt = config.profile
)
res <- {
if (hasWarnings && config.fatalWarnings.value) Left("")
Expand Down Expand Up @@ -320,7 +320,7 @@ object SjsonnetMainBase {
std: Val.Obj,
evaluatorOverride: Option[Evaluator] = None,
debugStats: DebugStats = null,
flamegraphFile: Option[String] = None): Either[String, String] = {
profileOpt: Option[String] = None): Either[String, String] = {

val (jsonnetCode, path) =
if (config.exec.value) (file, wd / Util.wrapInLessThanGreaterThan("exec"))
Expand Down Expand Up @@ -349,8 +349,19 @@ object SjsonnetMainBase {
wd
)

val (profileFormat, profileFile) = profileOpt match {
case Some(s) if s.startsWith("flamegraph:") =>
(Some(ProfileOutputFormat.FlameGraph), Some(s.stripPrefix("flamegraph:")))
case Some(s) if s.startsWith("text:") =>
(Some(ProfileOutputFormat.Text), Some(s.stripPrefix("text:")))
case Some(s) =>
(Some(ProfileOutputFormat.Text), Some(s))
case None =>
(None, None)
}

var currentPos: Position = null
var profiler: FlameGraphProfiler = null
var profilerInstance: Profiler = null
val interp = new Interpreter(
queryExtVar = (key: String) => extBinding.get(key).map(ExternalVariable.code),
queryTlaVar = (key: String) => tlaBinding.get(key).map(ExternalVariable.code),
Expand All @@ -372,9 +383,9 @@ object SjsonnetMainBase {
val ev = evaluatorOverride.getOrElse(
super.createEvaluator(resolver, extVars, wd, settings)
)
if (flamegraphFile.isDefined) {
profiler = new FlameGraphProfiler
ev.flameGraphProfiler = profiler
profileFormat.foreach { fmt =>
profilerInstance = new Profiler(fmt, wd)
ev.profiler = profilerInstance
}
ev
}
Expand Down Expand Up @@ -448,8 +459,10 @@ object SjsonnetMainBase {
case _ => renderNormal(config, interp, jsonnetCode, path, wd, () => currentPos)
}

if (profiler != null)
flamegraphFile.foreach(profiler.writeTo)
if (profilerInstance != null)
profileFile.foreach(f =>
profilerInstance.writeTo(f, pos => interp.evaluator.prettyIndex(pos))
)

result
}
Expand Down
Loading