All Downloads are FREE. Search and download functionalities are using the official Maven repository.

au.csiro.pbdava.ssparkle.common.utils.Prof.scala Maven / Gradle / Ivy

The newest version!
package au.csiro.pbdava.ssparkle.common.utils

trait Prof extends Logging {

  lazy val profEnable: Boolean = System.getProperty("sparkle.prof", "false").toBoolean

  var prevStartTime: Long = 0L

  def profReset(): Unit = if (!profEnable) {} else {
    prevStartTime = System.currentTimeMillis()
  }

  def profPoint(msg: => String): Unit = if (!profEnable) {} else {
    val duration = System.currentTimeMillis() - prevStartTime
    logInfo(s"${msg}: ${duration}")
    profReset()
  }

  def profIt[R](msg: => String)(f: => R): R =
    if (!profEnable) f
    else {
      val st = System.currentTimeMillis()
      val r = f
      val duration = System.currentTimeMillis() - st
      logInfo(s"${msg}: ${duration}")
      r
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy