Skip to content

Commit

Permalink
Microsecond precision in chrome profile (#2827)
Browse files Browse the repository at this point in the history
Chrome profiles support microsecond precision, so we can use
`System.nanoTime` instead of `System.currentTimeMillis` to have better
profiles

Pull Request: #2827
  • Loading branch information
lolgab authored Oct 5, 2023
1 parent ff5335e commit e703b7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions main/eval/src/mill/eval/EvaluatorCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
.flatMap(_.iterator.flatMap(_.newResults))
.toMap

val startTime = System.currentTimeMillis()
val startTime = System.nanoTime() / 1000
val threadId = threadNumberer.getThreadId(Thread.currentThread())
val counterMsg = s"${count.getAndIncrement()}/${terminals.size}"
val contextLogger = PrefixLogger(
Expand All @@ -119,21 +119,23 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
if (failFast && res.newResults.values.exists(_.result.asSuccess.isEmpty))
failed.set(true)

val endTime = System.currentTimeMillis()
val endTime = System.nanoTime() / 1000

val duration = endTime - startTime

chromeProfileLogger.log(
task = Terminal.printTerm(terminal),
cat = "job",
startTime = startTime,
endTime = endTime,
duration = duration,
threadId = threadNumberer.getThreadId(Thread.currentThread()),
cached = res.cached
)

profileLogger.log(
ProfileLogger.Timing(
terminal.render,
(endTime - startTime).toInt,
(duration / 1000).toInt,
res.cached,
deps.map(_.render),
res.inputsHash,
Expand Down
6 changes: 3 additions & 3 deletions main/eval/src/mill/eval/JsonArrayLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private class ChromeProfileLogger(outPath: os.Path)
task: String,
cat: String,
startTime: Long,
endTime: Long,
duration: Long,
threadId: Int,
cached: Boolean
): Unit = {
Expand All @@ -68,8 +68,8 @@ private class ChromeProfileLogger(outPath: os.Path)
name = task,
cat = cat,
ph = "X",
ts = startTime * 1000,
dur = (endTime - startTime) * 1000 /*chrome treats the duration as microseconds*/,
ts = startTime,
dur = duration,
pid = 1,
tid = threadId,
args = if (cached) Seq("cached") else Seq()
Expand Down

0 comments on commit e703b7a

Please sign in to comment.