From b78440f07e94f9b780aaf14b50f26ef2a6533050 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Mon, 26 Feb 2018 14:45:15 -0500 Subject: [PATCH] Wrap result of tracktime in a struct to have a custom show method and avoid unconditional printing of timing results --- src/diagnostics.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/diagnostics.jl b/src/diagnostics.jl index db800b1e..93279730 100644 --- a/src/diagnostics.jl +++ b/src/diagnostics.jl @@ -84,6 +84,12 @@ function stop_tracking_time() compute_context[] = nothing end +struct TrackTime + obj +end + +Base.show(io::IO, ::MIME"text/plain", t::TrackTime) = show_timings(t.obj, maxdepth=5) + """ `tracktime(f)` @@ -96,8 +102,7 @@ function tracktime(f; profile=false, maxdepth=5) ctx = compute_context[] stop_tracking_time() t = fetch_timings!(ctx, profile=profile) - show_timings(t, maxdepth=maxdepth) - t, res + TrackTime(t), res end function fetch_timings!(ctx=get_context(); profile=true)