@@ -436,8 +436,11 @@ def text_document_did_change(message)
436436
437437 if [ :ruby , :rbs ] . include? ( language_id )
438438 graph = @global_state . graph
439- graph . index_source ( text_document [ :uri ] . to_s , document . source , language_id . to_s )
440- graph . resolve
439+
440+ benchmark ( "index_source" ) do
441+ graph . index_source ( text_document [ :uri ] . to_s , document . source , language_id . to_s )
442+ end
443+ benchmark ( "incremental_resolve" ) { graph . resolve }
441444 end
442445 end
443446
@@ -1070,8 +1073,8 @@ def workspace_did_change_watched_files(message)
10701073 acc << path
10711074 end
10721075 end
1073- graph . index_all ( additions_and_changes )
1074- graph . resolve
1076+ benchmark ( "index_all" ) { graph . index_all ( additions_and_changes ) }
1077+ benchmark ( "incremental_resolve" ) { graph . resolve }
10751078
10761079 index = @global_state . index
10771080 changes . each do |change |
@@ -1269,10 +1272,10 @@ def shutdown
12691272 #: -> void
12701273 def perform_initial_indexing
12711274 progress ( "indexing-progress" , message : "Indexing workspace..." )
1272- @global_state . graph . index_workspace
1275+ benchmark ( "index_workspace" ) { @global_state . graph . index_workspace }
12731276
12741277 progress ( "indexing-progress" , message : "Resolving graph..." )
1275- @global_state . graph . resolve
1278+ benchmark ( "full_resolve" ) { @global_state . graph . resolve }
12761279
12771280 # The begin progress invocation happens during `initialize`, so that the notification is sent before we are
12781281 # stuck indexing files
@@ -1572,5 +1575,28 @@ def code_lens_resolve(message)
15721575 response : code_lens ,
15731576 ) )
15741577 end
1578+
1579+ #: [T] (String) { () -> T } -> T
1580+ def benchmark ( label , &block )
1581+ start = Process . clock_gettime ( Process ::CLOCK_MONOTONIC , :float_millisecond )
1582+ result = block . call
1583+ duration = Process . clock_gettime ( Process ::CLOCK_MONOTONIC , :float_millisecond ) - start
1584+
1585+ send_message ( Notification . telemetry ( {
1586+ type : "data" ,
1587+ eventName : "ruby_lsp.response_time" ,
1588+ data : {
1589+ type : "histogram" ,
1590+ value : duration ,
1591+ attributes : {
1592+ message : label ,
1593+ lspVersion : RubyLsp ::VERSION ,
1594+ rubyVersion : RUBY_VERSION ,
1595+ } ,
1596+ } ,
1597+ } ) )
1598+
1599+ result
1600+ end
15751601 end
15761602end
0 commit comments