Skip to content

Commit 328b3db

Browse files
authored
Benchmark and send telemetry events for indexing and resolution (#4074)
1 parent 9ca38db commit 328b3db

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

lib/ruby_lsp/server.rb

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
15761602
end

test/server_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ def test_initialized_recovers_from_indexing_failures
194194
@server.process_message({ method: "initialized" })
195195
end
196196

197-
notification = @server.pop_response
198-
assert_equal("window/showMessage", notification.method)
197+
notification = find_message(RubyLsp::Notification, "window/showMessage")
199198
expected_message = "Error while indexing (see [troubleshooting steps]" \
200199
"(https://shopify.github.io/ruby-lsp/troubleshooting#indexing)): boom!"
201200
assert_equal(
@@ -576,7 +575,7 @@ def version
576575
},
577576
})
578577

579-
message = @server.pop_response.params.message
578+
message = find_message(RubyLsp::Notification, "window/logMessage").params.message
580579
assert_match("Error in Foo add-on while processing watched file notifications", message)
581580
assert_match("boom", message)
582581
ensure

0 commit comments

Comments
 (0)