55 */
66
77import { inputTargetIndexCacheMetrics } from "../../project/project-index.ts" ;
8+ import { functionTimes } from "./function-times.ts" ;
89import { Stats } from "./stats.ts" ;
910
1011type FileReadRecord = {
@@ -30,51 +31,6 @@ export function captureFileReads() {
3031 } ;
3132}
3233
33- const functionTimes : Record < string , Stats > = { } ;
34- // deno-lint-ignore no-explicit-any
35- export const makeTimedFunction = < T extends ( ...args : any [ ] ) => any > (
36- name : string ,
37- fn : T ,
38- ) : T => {
39- if ( Deno . env . get ( "QUARTO_REPORT_PERFORMANCE_METRICS" ) === undefined ) {
40- return fn ;
41- }
42- functionTimes [ name ] = new Stats ( ) ;
43- return function ( ...args : Parameters < T > ) : ReturnType < T > {
44- const start = performance . now ( ) ;
45- try {
46- const result = fn ( ...args ) ;
47- return result ;
48- } finally {
49- const end = performance . now ( ) ;
50- functionTimes [ name ] . add ( end - start ) ;
51- }
52- } as T ;
53- } ;
54-
55- export const makeTimedFunctionAsync = <
56- // deno-lint-ignore no-explicit-any
57- T extends ( ...args : any [ ] ) => Promise < any > ,
58- > (
59- name : string ,
60- fn : T ,
61- ) : T => {
62- if ( Deno . env . get ( "QUARTO_REPORT_PERFORMANCE_METRICS" ) === undefined ) {
63- return fn ;
64- }
65- functionTimes [ name ] = new Stats ( ) ;
66- return async function ( ...args : Parameters < T > ) : Promise < ReturnType < T > > {
67- const start = performance . now ( ) ;
68- try {
69- const result = await fn ( ...args ) ;
70- return result ;
71- } finally {
72- const end = performance . now ( ) ;
73- functionTimes [ name ] . add ( end - start ) ;
74- }
75- } as T ;
76- } ;
77-
7834const metricsObject = {
7935 inputTargetIndexCache : inputTargetIndexCacheMetrics ,
8036 fileReads,
@@ -102,14 +58,14 @@ export function quartoPerformanceMetrics(keys?: MetricsKeys[]) {
10258}
10359
10460export function reportPerformanceMetrics ( keys ?: MetricsKeys [ ] ) {
105- console . log ( "---" ) ;
106- console . log ( "Performance metrics" ) ;
107- console . log ( "Quarto:" ) ;
10861 const content = JSON . stringify ( quartoPerformanceMetrics ( keys ) , null , 2 ) ;
10962 const outFile = Deno . env . get ( "QUARTO_REPORT_PERFORMANCE_METRICS_FILE" ) ;
11063 if ( outFile ) {
11164 Deno . writeTextFileSync ( outFile , content ) ;
11265 } else {
66+ console . log ( "---" ) ;
67+ console . log ( "Performance metrics" ) ;
68+ console . log ( "Quarto:" ) ;
11369 console . log ( content ) ;
11470 }
11571}
0 commit comments