Skip to content

Commit 6e173bb

Browse files
committed
Improve server statistics retrieval
* Don't always force GC * Cancel pending requests if the request is automatic (i.e. comes from a "server state changed" event).
1 parent 75f79ec commit 6e173bb

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

src/VsChromium/Features/IndexServerInfo/IShowServerInfoService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace VsChromium.Features.IndexServerInfo {
99
public interface IShowServerInfoService {
10-
void ShowServerStatusDialog();
10+
void ShowServerStatusDialog(bool forceGarbageCollection);
1111
void ShowProjectIndexDetailsDialog(string path);
1212
void ShowDirectoryIndexDetailsDialog(string path);
1313

14-
void FetchDatabaseStatistics(bool forceGarbageCollect, Action<GetDatabaseStatisticsResponse> callback);
14+
void FetchDatabaseStatistics(Action<GetDatabaseStatisticsResponse> callback);
1515

1616
string GetIndexStatusText(GetDatabaseStatisticsResponse response);
1717
string GetIndexingServerStatusText(GetDatabaseStatisticsResponse response);

src/VsChromium/Features/IndexServerInfo/ShowServerInfoService.cs

+39-21
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ShowServerInfoService(IDispatchThreadServerRequestExecutor dispatchThread
2828
_shellHost = shellHost;
2929
}
3030

31-
public void ShowServerStatusDialog() {
31+
public void ShowServerStatusDialog(bool forceGarbageCollection) {
3232
var dialog = new ServerStatusDialog();
3333
dialog.HasMinimizeButton = false;
3434
dialog.HasMaximizeButton = false;
@@ -38,7 +38,7 @@ public void ShowServerStatusDialog() {
3838
var isClosed = false;
3939
dialog.Closed += (sender, args) => isClosed = true;
4040

41-
FetchDatabaseStatistics(true, response => {
41+
FetchDatabaseStatisticsImpl(Guid.NewGuid().ToString(), TimeSpan.Zero, forceGarbageCollection, response => {
4242
if (isClosed) {
4343
return;
4444
}
@@ -69,11 +69,12 @@ public void ShowServerStatusDialog() {
6969
} else {
7070
message.AppendFormat("Last updated: {0}\r\n", "n/a (index is empty)");
7171
}
72+
7273
dialog.ViewModel.IndexStatus = message.ToString().TrimSuffix("\r\n");
7374
message.Clear();
7475

75-
message.AppendFormat("Managed memory: {0:n2} MB\r\n", (double)response.ServerGcMemoryUsage / (1024 * 1024));
76-
message.AppendFormat("Native memory: {0:n2} MB\r\n", (double)response.ServerNativeMemoryUsage / (1024 * 1024));
76+
message.AppendFormat("Managed memory: {0:n2} MB\r\n", (double) response.ServerGcMemoryUsage / (1024 * 1024));
77+
message.AppendFormat("Native memory: {0:n2} MB\r\n", (double) response.ServerNativeMemoryUsage / (1024 * 1024));
7778
dialog.ViewModel.MemoryStatus = message.ToString().TrimSuffix("\r\n");
7879
});
7980

@@ -101,19 +102,19 @@ private void OnShowServerDetailsInvoked() {
101102
dialog.ViewModel.Waiting = false;
102103
},
103104
OnDispatchThreadSuccess = typedResponse => {
104-
var response = (GetDatabaseDetailsResponse)typedResponse;
105+
var response = (GetDatabaseDetailsResponse) typedResponse;
105106
var projectDetails = response.Projects.Select(x => new ProjectDetailsViewModel {
106107
ProjectDetails = x
107108
}).ToList();
108109
foreach (var x in projectDetails) {
109-
x.ShowProjectConfigurationInvoked += (sender, args) => {
110-
ShowProjectConfiguration(x);
111-
};
110+
x.ShowProjectConfigurationInvoked += (sender, args) => { ShowProjectConfiguration(x); };
112111
}
112+
113113
dialog.ViewModel.Projects.AddRange(projectDetails);
114114
if (dialog.ViewModel.Projects.Count > 0) {
115115
dialog.ViewModel.SelectedProject = dialog.ViewModel.Projects[0];
116116
}
117+
117118
dialog.ViewModel.Waiting = false;
118119
}
119120
});
@@ -147,7 +148,7 @@ public void ShowProjectIndexDetailsDialog(string path) {
147148
_shellHost.ShowErrorMessageBox("Error", error.Message);
148149
},
149150
OnDispatchThreadSuccess = typedResponse => {
150-
var response = (GetProjectDetailsResponse)typedResponse;
151+
var response = (GetProjectDetailsResponse) typedResponse;
151152
dialog.ViewModel.ProjectDetails = response.ProjectDetails;
152153
dialog.ViewModel.Waiting = false;
153154
},
@@ -179,7 +180,7 @@ public void ShowDirectoryIndexDetailsDialog(string path) {
179180
_shellHost.ShowErrorMessageBox("Error", error.Message);
180181
},
181182
OnDispatchThreadSuccess = typedResponse => {
182-
var response1 = (GetDirectoryDetailsResponse)typedResponse;
183+
var response1 = (GetDirectoryDetailsResponse) typedResponse;
183184
dialog.ViewModel.DirectoryDetails = response1.DirectoryDetails;
184185
dialog.ViewModel.Waiting = false;
185186
},
@@ -199,20 +200,12 @@ private void ShowProjectConfiguration(ProjectDetailsViewModel projectDetailsView
199200
dialog.ShowModal();
200201
}
201202

202-
public void FetchDatabaseStatistics(bool forceGarbageCollect, Action<GetDatabaseStatisticsResponse> callback) {
203-
_dispatchThreadServerRequestExecutor.Post(
204-
new DispatchThreadServerRequest {
205-
Id = Guid.NewGuid().ToString(),
206-
Request = new GetDatabaseStatisticsRequest { ForceGabageCollection = forceGarbageCollect },
207-
OnDispatchThreadSuccess = typedResponse => {
208-
var response = (GetDatabaseStatisticsResponse)typedResponse;
209-
callback(response);
210-
}
211-
});
203+
public void FetchDatabaseStatistics(Action<GetDatabaseStatisticsResponse> callback) {
204+
FetchDatabaseStatisticsImpl(nameof(FetchDatabaseStatistics), null, false, callback);
212205
}
213206

214207
public string GetIndexStatusText(GetDatabaseStatisticsResponse response) {
215-
var memoryUsageMb = (double)response.ServerNativeMemoryUsage / 1024L / 1024L;
208+
var memoryUsageMb = (double) response.ServerNativeMemoryUsage / 1024L / 1024L;
216209
var message = String.Format("Index: {0:n0} files - {1:n0} MB", response.SearchableFileCount, memoryUsageMb);
217210
return message;
218211
}
@@ -259,22 +252,47 @@ public string HumanReadableDuration(DateTime utcTime) {
259252
if (span.TotalSeconds <= 5) {
260253
return "a few seconds ago";
261254
}
255+
262256
if (span.TotalSeconds <= 50) {
263257
return "less than 1 minute ago";
264258
}
259+
265260
if (span.TotalMinutes <= 1) {
266261
return "about 1 minute ago";
267262
}
263+
268264
if (span.TotalMinutes <= 60) {
269265
return string.Format("about {0:n0} minutes ago", Math.Ceiling(span.TotalMinutes));
270266
}
267+
271268
if (span.TotalHours <= 1.5) {
272269
return "about one hour ago";
273270
}
271+
274272
if (span.TotalHours <= 24) {
275273
return string.Format("about {0:n0} hours ago", Math.Ceiling(span.TotalHours));
276274
}
275+
277276
return "more than one day ago";
278277
}
278+
279+
public void FetchDatabaseStatisticsImpl(string requestId, TimeSpan? delay, bool forceGarbageCollect,
280+
Action<GetDatabaseStatisticsResponse> callback) {
281+
var request = new DispatchThreadServerRequest {
282+
Id = requestId,
283+
Request = new GetDatabaseStatisticsRequest {
284+
ForceGabageCollection = forceGarbageCollect
285+
},
286+
OnDispatchThreadSuccess = typedResponse => {
287+
var response = (GetDatabaseStatisticsResponse) typedResponse;
288+
callback(response);
289+
}
290+
};
291+
if (delay != null) {
292+
request.Delay = delay.Value;
293+
}
294+
295+
_dispatchThreadServerRequestExecutor.Post(request);
296+
}
279297
}
280298
}

src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ private void PauseResumeIndexingButton_Click(object sender, RoutedEventArgs e) {
329329
}
330330

331331
private void ServerInfo_Click(object sender, RoutedEventArgs e) {
332-
Logger.WrapActionInvocation(() => Controller.ShowServerInfo());
332+
var forceGarbageCollection = Keyboard.Modifiers.HasFlag(ModifierKeys.Shift);
333+
Logger.WrapActionInvocation(() => Controller.ShowServerInfo(forceGarbageCollection));
333334
}
334335
}
335336
}

src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ public void CancelSearch() {
221221
ViewModel.SwitchToInformationMessages();
222222
}
223223

224-
public void ShowServerInfo() {
225-
_showServerInfoService.ShowServerStatusDialog();
224+
public void ShowServerInfo(bool forceGarbageCollection) {
225+
_showServerInfoService.ShowServerStatusDialog(forceGarbageCollection);
226226
}
227227

228228
public void RefreshFileSystemTree() {
@@ -701,7 +701,7 @@ private void SearchWorker(SearchWorkerParams workerParams) {
701701
}
702702

703703
private void FetchDatabaseStatistics() {
704-
_showServerInfoService.FetchDatabaseStatistics(false, UpdateIndexingServerToolbarStatus);
704+
_showServerInfoService.FetchDatabaseStatistics(UpdateIndexingServerToolbarStatus);
705705
}
706706

707707
private void UpdateIndexingServerToolbarStatus(GetDatabaseStatisticsResponse response) {

src/VsChromium/Features/ToolWindows/CodeSearch/ICodeSearchController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface ICodeSearchController : IDisposable {
2525

2626
void RefreshFileSystemTree();
2727
void PauseResumeIndexing();
28-
void ShowServerInfo();
28+
void ShowServerInfo(bool forceGarbageCollection);
2929

3030
void PerformSearch(bool immediate);
3131
void QuickSearchCode(string searchPattern);

0 commit comments

Comments
 (0)