Skip to content

Commit 6006454

Browse files
committed
Add a bunch more trace logs to workspace state generator
1 parent d703c60 commit 6006454

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectWorkspaceStateGenerator.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void Dispose()
5959
// Release before dispose to ensure we don't throw exceptions from the background thread trying to release
6060
// while we're disposing. Multiple releases are fine, and if we release and it lets something passed the lock
6161
// our cancellation token check will mean its a no-op.
62+
_logger.LogTrace($"Releasing the semaphore in Dispose");
6263
_semaphore.Release();
6364
_semaphore.Dispose();
6465

@@ -116,14 +117,19 @@ private async Task UpdateWorkspaceStateAsync(Project? workspaceProject, IProject
116117
// So if we now do multiple requests to resolve TagHelpers simultaneously it results in only a
117118
// single one executing at a time so that we don't have N number of requests in flight with these
118119
// 10mb payloads waiting to be processed.
120+
_logger.LogTrace($"In UpdateWorkspaceStateAsync, waiting for the semaphore, for '{projectSnapshot.Key}'");
119121
await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
120122
}
121123
catch (Exception)
122124
{
125+
_logger.LogTrace($"Exception waiting for the semaphore '{projectSnapshot.Key}'");
126+
123127
// Object disposed or task cancelled exceptions should be swallowed/no-op'd
124128
return;
125129
}
126130

131+
_logger.LogTrace($"Got the semaphore '{projectSnapshot.Key}'");
132+
127133
try
128134
{
129135
OnStartingBackgroundWork();
@@ -135,54 +141,71 @@ private async Task UpdateWorkspaceStateAsync(Project? workspaceProject, IProject
135141

136142
var workspaceState = await GetProjectWorkspaceStateAsync(workspaceProject, projectSnapshot, cancellationToken);
137143

138-
if (workspaceState is null || cancellationToken.IsCancellationRequested)
144+
if (workspaceState is null)
145+
{
146+
_logger.LogTrace($"Couldn't get any state for '{projectSnapshot.Key}'");
147+
return;
148+
}
149+
else if (cancellationToken.IsCancellationRequested)
139150
{
151+
_logger.LogTrace($"Got a cancellation request during discovery for '{projectSnapshot.Key}'");
140152
return;
141153
}
142154

155+
_logger.LogTrace($"Updating project info with {workspaceState.TagHelpers.Length} tag helpers for '{projectSnapshot.Key}'");
156+
143157
await _projectManager
144158
.UpdateAsync(
145159
static (updater, state) =>
146160
{
147-
var (projectKey, workspaceState, cancellationToken) = state;
161+
var (projectKey, workspaceState, logger, cancellationToken) = state;
148162

149163
if (cancellationToken.IsCancellationRequested)
150164
{
151165
return;
152166
}
153167

168+
logger.LogTrace($"Really updating project info with {workspaceState.TagHelpers.Length} tag helpers for '{projectKey}'");
154169
updater.ProjectWorkspaceStateChanged(projectKey, workspaceState);
155170
},
156-
state: (projectSnapshot.Key, workspaceState, cancellationToken),
171+
state: (projectSnapshot.Key, workspaceState, _logger, cancellationToken),
157172
cancellationToken)
158173
.ConfigureAwait(false);
159174
}
160175
catch (OperationCanceledException)
161176
{
177+
_logger.LogTrace($"Got an OperationCancelledException, for '{projectSnapshot.Key}'");
162178
// Abort work if we get a task canceled exception
163179
return;
164180
}
165181
catch (Exception ex)
166182
{
183+
_logger.LogTrace($"Got an exception, for '{projectSnapshot.Key}'");
167184
_logger.LogError(ex);
168185
}
169186
finally
170187
{
171188
try
172189
{
190+
_logger.LogTrace($"Felt cute, might release a semaphore later, for '{projectSnapshot.Key}'");
191+
173192
// Prevent ObjectDisposedException if we've disposed before we got here. The dispose method will release
174193
// anyway, so we're all good.
175194
if (!cancellationToken.IsCancellationRequested)
176195
{
196+
_logger.LogTrace($"Releasing the semaphore, for '{projectSnapshot.Key}'");
177197
_semaphore.Release();
178198
}
199+
200+
_logger.LogTrace($"If you didn't see a log message about releasing a semaphore, we have a problem. (for '{projectSnapshot.Key}')");
179201
}
180202
catch
181203
{
182204
// Swallow exceptions that happen from releasing the semaphore.
183205
}
184206
}
185207

208+
_logger.LogTrace($"All finished for '{projectSnapshot.Key}'");
186209
OnBackgroundWorkCompleted();
187210
}
188211

@@ -202,6 +225,8 @@ await _projectManager
202225
return ProjectWorkspaceState.Default;
203226
}
204227

228+
_logger.LogTrace($"Starting tag helper discovery for {projectSnapshot.FilePath}");
229+
205230
// Specifically not using BeginBlock because we want to capture cases where tag helper discovery never finishes.
206231
var telemetryId = Guid.NewGuid();
207232

0 commit comments

Comments
 (0)