@@ -64,7 +64,8 @@ pv_debrief <- function(x, n = 10) {
6464# ' @param n_paths Number of hot paths to show (default 5).
6565# ' @param n_memory Number of memory hotspots to show (default 5).
6666# '
67- # ' @return Invisibly returns the result of [pv_debrief()].
67+ # ' @return Invisibly returns a `debrief_debrief` object. Use
68+ # ' `capture.output()` to capture the formatted text output.
6869# '
6970# ' @examples
7071# ' p <- pv_example()
@@ -95,6 +96,52 @@ pv_print_debrief <- function(
9596 memory_funcs <- pv_memory(x )
9697 memory_lines <- if (has_source ) pv_memory_lines(x ) else NULL
9798
99+ obj <- structure(
100+ list (
101+ interval_ms = interval_ms ,
102+ total_samples = total_samples ,
103+ total_time_ms = total_time_ms ,
104+ has_source = has_source ,
105+ file_contents = file_contents ,
106+ self_time = self_time ,
107+ total_time = total_time ,
108+ hot_lines = hot_lines ,
109+ hot_paths = hot_paths ,
110+ memory_funcs = memory_funcs ,
111+ memory_lines = memory_lines ,
112+ n_functions = n_functions ,
113+ n_lines = n_lines ,
114+ n_paths = n_paths ,
115+ n_memory = n_memory ,
116+ debrief = pv_debrief(
117+ x ,
118+ n = max(n_functions , n_lines , n_paths , n_memory )
119+ )
120+ ),
121+ class = " debrief_debrief"
122+ )
123+ print(obj )
124+ invisible (obj )
125+ }
126+
127+ # ' @exportS3Method
128+ print.debrief_debrief <- function (x , ... ) {
129+ interval_ms <- x $ interval_ms
130+ total_samples <- x $ total_samples
131+ total_time_ms <- x $ total_time_ms
132+ has_source <- x $ has_source
133+ file_contents <- x $ file_contents
134+ self_time <- x $ self_time
135+ total_time <- x $ total_time
136+ hot_lines <- x $ hot_lines
137+ hot_paths <- x $ hot_paths
138+ memory_funcs <- x $ memory_funcs
139+ memory_lines <- x $ memory_lines
140+ n_functions <- x $ n_functions
141+ n_lines <- x $ n_lines
142+ n_paths <- x $ n_paths
143+ n_memory <- x $ n_memory
144+
98145 # Print output
99146 cat_header(" PROFILING SUMMARY" )
100147 cat(" \n " )
@@ -152,7 +199,7 @@ pv_print_debrief <- function(
152199 suggestions <- c(suggestions , " pv_suggestions(p)" , " pv_help()" )
153200 cat_next_steps(suggestions )
154201
155- invisible (pv_debrief( x , n = max( n_functions , n_lines , n_paths , n_memory )) )
202+ invisible (x )
156203}
157204
158205# Print helpers for debrief
0 commit comments