Skip to content

Commit 2a030ba

Browse files
committed
chore: add some tracing to project loading
1 parent af1fd88 commit 2a030ba

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/load-cargo/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use itertools::Itertools;
1717
use proc_macro_api::{MacroDylib, ProcMacroServer};
1818
use project_model::{CargoConfig, PackageRoot, ProjectManifest, ProjectWorkspace};
1919
use span::Span;
20+
use tracing::{instrument, Level};
2021
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
2122

2223
pub struct LoadCargoConfig {
@@ -50,6 +51,7 @@ pub fn load_workspace_at(
5051
load_workspace(workspace, &cargo_config.extra_env, load_config)
5152
}
5253

54+
#[instrument(skip_all)]
5355
pub fn load_workspace(
5456
ws: ProjectWorkspace,
5557
extra_env: &FxHashMap<String, String>,
@@ -352,6 +354,7 @@ fn load_crate_graph(
352354
}
353355
}
354356
vfs::loader::Message::Loaded { files } | vfs::loader::Message::Changed { files } => {
357+
let _p = tracing::span!(Level::INFO, "LoadCargo::load_file_contents").entered();
355358
for (path, contents) in files {
356359
vfs.set_file_contents(path.into(), contents);
357360
}

crates/project-model/src/workspace.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use semver::Version;
1616
use span::Edition;
1717
use stdx::always;
1818
use toolchain::Tool;
19+
use tracing::instrument;
1920
use triomphe::Arc;
2021

2122
use crate::{
@@ -863,6 +864,7 @@ impl ProjectWorkspace {
863864
}
864865
}
865866

867+
#[instrument(skip_all)]
866868
fn project_json_to_crate_graph(
867869
rustc_cfg: Vec<CfgFlag>,
868870
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,

crates/rust-analyzer/src/global_state.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use parking_lot::{
2020
use proc_macro_api::ProcMacroServer;
2121
use project_model::{CargoWorkspace, ProjectWorkspace, Target, WorkspaceBuildScripts};
2222
use rustc_hash::{FxHashMap, FxHashSet};
23+
use tracing::{span, Level};
2324
use triomphe::Arc;
2425
use vfs::{AnchoredPathBuf, ChangedFile, Vfs};
2526

@@ -247,8 +248,7 @@ impl GlobalState {
247248
}
248249

249250
pub(crate) fn process_changes(&mut self) -> bool {
250-
let _p = tracing::span!(tracing::Level::INFO, "GlobalState::process_changes").entered();
251-
251+
let _p = span!(Level::INFO, "GlobalState::process_changes").entered();
252252
let mut file_changes = FxHashMap::<_, (bool, ChangedFile)>::default();
253253
let (change, modified_rust_files, workspace_structure_change) = {
254254
let mut change = ChangeWithProcMacros::new();
@@ -258,6 +258,8 @@ impl GlobalState {
258258
return false;
259259
}
260260

261+
let _p =
262+
span!(Level::INFO, "GlobalState::process_changes/gather_changed_files").entered();
261263
// downgrade to read lock to allow more readers while we are normalizing text
262264
let guard = RwLockWriteGuard::downgrade_to_upgradable(guard);
263265
let vfs: &Vfs = &guard.0;
@@ -296,6 +298,8 @@ impl GlobalState {
296298
}
297299
}
298300

301+
let _p = span!(Level::INFO, "GlobalState::process_changes/calculate_changed_files")
302+
.entered();
299303
let changed_files: Vec<_> = file_changes
300304
.into_iter()
301305
.filter(|(_, (just_created, change))| {
@@ -361,6 +365,7 @@ impl GlobalState {
361365
(change, modified_rust_files, workspace_structure_change)
362366
};
363367

368+
let _p = span!(Level::INFO, "GlobalState::process_changes/apply_change").entered();
364369
self.analysis_host.apply_change(change);
365370

366371
{
@@ -374,6 +379,9 @@ impl GlobalState {
374379
// but something's going wrong with the source root business when we add a new local
375380
// crate see https://github.com/rust-lang/rust-analyzer/issues/13029
376381
if let Some((path, force_crate_graph_reload)) = workspace_structure_change {
382+
let _p = span!(Level::INFO, "GlobalState::process_changes/ws_structure_change")
383+
.entered();
384+
377385
self.fetch_workspaces_queue.request_op(
378386
format!("workspace vfs file change: {path}"),
379387
force_crate_graph_reload,

crates/rust-analyzer/src/main_loop.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use ide_db::base_db::{SourceDatabase, SourceDatabaseExt, VfsPath};
1212
use lsp_server::{Connection, Notification, Request};
1313
use lsp_types::{notification::Notification as _, TextDocumentIdentifier};
1414
use stdx::thread::ThreadIntent;
15+
use tracing::{span, Level};
1516
use vfs::FileId;
1617

1718
use crate::{
@@ -229,8 +230,7 @@ impl GlobalState {
229230
fn handle_event(&mut self, event: Event) -> anyhow::Result<()> {
230231
let loop_start = Instant::now();
231232
// NOTE: don't count blocking select! call as a loop-turn time
232-
let _p = tracing::span!(tracing::Level::INFO, "GlobalState::handle_event", event = %event)
233-
.entered();
233+
let _p = tracing::span!(Level::INFO, "GlobalState::handle_event", event = %event).entered();
234234

235235
let event_dbg_msg = format!("{event:?}");
236236
tracing::debug!(?loop_start, ?event, "handle_event");
@@ -669,9 +669,12 @@ impl GlobalState {
669669
}
670670

671671
fn handle_vfs_msg(&mut self, message: vfs::loader::Message) {
672+
let _p = tracing::span!(Level::INFO, "GlobalState::handle_vfs_msg").entered();
672673
let is_changed = matches!(message, vfs::loader::Message::Changed { .. });
673674
match message {
674675
vfs::loader::Message::Changed { files } | vfs::loader::Message::Loaded { files } => {
676+
let _p = tracing::span!(Level::INFO, "GlobalState::handle_vfs_msg{changed/load}")
677+
.entered();
675678
let vfs = &mut self.vfs.write().0;
676679
for (path, contents) in files {
677680
let path = VfsPath::from(path);
@@ -685,6 +688,8 @@ impl GlobalState {
685688
}
686689
}
687690
vfs::loader::Message::Progress { n_total, n_done, dir, config_version } => {
691+
let _p =
692+
tracing::span!(Level::INFO, "GlobalState::handle_vfs_mgs/progress").entered();
688693
always!(config_version <= self.vfs_config_version);
689694

690695
let state = match n_done {
@@ -867,6 +872,8 @@ impl GlobalState {
867872

868873
/// Registers and handles a request. This should only be called once per incoming request.
869874
fn on_new_request(&mut self, request_received: Instant, req: Request) {
875+
let _p =
876+
span!(Level::INFO, "GlobalState::on_new_request", req.method = ?req.method).entered();
870877
self.register_request(&req, request_received);
871878
self.on_request(req);
872879
}
@@ -980,6 +987,8 @@ impl GlobalState {
980987

981988
/// Handles an incoming notification.
982989
fn on_notification(&mut self, not: Notification) -> anyhow::Result<()> {
990+
let _p =
991+
span!(Level::INFO, "GlobalState::on_notification", not.method = ?not.method).entered();
983992
use crate::handlers::notification as handlers;
984993
use lsp_types::notification as notifs;
985994

crates/vfs/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ doctest = false
1313

1414
[dependencies]
1515
rustc-hash.workspace = true
16+
tracing.workspace = true
1617
fst = "0.4.7"
1718
indexmap.workspace = true
1819
nohash-hasher.workspace = true
@@ -21,4 +22,4 @@ paths.workspace = true
2122
stdx.workspace = true
2223

2324
[lints]
24-
workspace = true
25+
workspace = true

crates/vfs/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub use crate::{
5656
};
5757
pub use paths::{AbsPath, AbsPathBuf};
5858

59+
use tracing::{span, Level};
60+
5961
/// Handle to a file in [`Vfs`]
6062
///
6163
/// Most functions in rust-analyzer use this when they need to refer to a file.
@@ -210,6 +212,7 @@ impl Vfs {
210212
/// If the path does not currently exists in the `Vfs`, allocates a new
211213
/// [`FileId`] for it.
212214
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) -> bool {
215+
let _p = span!(Level::INFO, "Vfs::set_file_contents").entered();
213216
let file_id = self.alloc_file_id(path);
214217
let state = self.get(file_id);
215218
let change_kind = match (state, contents) {
@@ -236,6 +239,7 @@ impl Vfs {
236239

237240
/// Drain and returns all the changes in the `Vfs`.
238241
pub fn take_changes(&mut self) -> Vec<ChangedFile> {
242+
let _p = span!(Level::INFO, "Vfs::take_changes").entered();
239243
for file_id in self.created_this_cycle.drain(..) {
240244
if self.data[file_id.0 as usize] == FileState::Created {
241245
// downgrade the file from `Created` to `Exists` as the cycle is done

0 commit comments

Comments
 (0)