Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty profile function #10

Merged
merged 1 commit into from
May 22, 2012
Merged
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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@ object Profile {
counterList.sortWith(_.key > _.key).toList counterList.sortWith(_.key > _.key).toList
} }


def apply[T](name: String, f: => T, output: Boolean): T = { def apply[T](name: String, f: => T, output: Boolean = false): T = {
doProfile(name, f, output)
}

def profile[T](name: String, output: Boolean = false)(f: => T): T = {
doProfile(name, f, output)
}

private def doProfile[T](name:String, f: => T, output: Boolean):T = {
val p = Profile(name) val p = Profile(name)
try f try f
finally { finally {
p.finish p.finish
output match { output match {
case true => println(name, p.getDuration) case true => println(name, p.getDuration)
case _ => case _ =>
} }
} }
} }


def apply[T](name: String, f: => T): T = {
val p = Profile(name)
try f
finally p.finish
}

def processTriggers(counter: ProfileCounter) = { def processTriggers(counter: ProfileCounter) = {
triggers.foreach(t => t.apply(counter)) triggers.foreach(t => t.apply(counter))
} }
Expand Down Expand Up @@ -129,4 +131,4 @@ case class Profile(key: String) {
case _ => end - start case _ => end - start
} }
} }
} }