This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
Basic analysis progress reporting #687
Merged
Mikhail Arkhipov (MikhailArkhipov)
merged 4 commits into
microsoft:master
from
MikhailArkhipov:progress
Mar 5, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/Analysis/Ast/Impl/Analyzer/Definitions/IProgressReporter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright(c) Microsoft Corporation | ||
| // All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the License); you may not use | ||
| // this file except in compliance with the License. You may obtain a copy of the | ||
| // License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
| // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY | ||
| // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| // MERCHANTABILITY OR NON-INFRINGEMENT. | ||
| // | ||
| // See the Apache Version 2.0 License for specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| namespace Microsoft.Python.Analysis.Analyzer { | ||
| internal interface IProgressReporter { | ||
| void ReportRemaining(int count = -1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Copyright(c) Microsoft Corporation | ||
| // All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the License); you may not use | ||
| // this file except in compliance with the License. You may obtain a copy of the | ||
| // License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
| // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY | ||
| // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| // MERCHANTABILITY OR NON-INFRINGEMENT. | ||
| // | ||
| // See the Apache Version 2.0 License for specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using Microsoft.Python.Core; | ||
| using Microsoft.Python.Core.Services; | ||
|
|
||
| namespace Microsoft.Python.Analysis.Analyzer { | ||
| internal sealed class ProgressReporter : IProgressReporter, IDisposable { | ||
| private const int _initialDelay = 100; | ||
| private const int _reportingInterval = 200; | ||
| private const int _disposeInterval = 2000; | ||
|
|
||
| private readonly IProgressService _progressService; | ||
| private readonly object _lock = new object(); | ||
| private int _lastReportedCount; | ||
| private int _lastReportedToClient; | ||
| private IProgress _progress; | ||
| private Timer _reportTimer; | ||
| private Timer _disposeTimer; | ||
| private bool _running; | ||
| private int _disposedId; | ||
|
|
||
| public ProgressReporter(IProgressService progressService) { | ||
| _progressService = progressService; | ||
| } | ||
|
|
||
| public void Dispose() { | ||
| lock (_lock) { | ||
| EndReport(); | ||
| } | ||
| } | ||
|
|
||
| public void ReportRemaining(int count = -1) { | ||
| lock (_lock) { | ||
| if (!_running) { | ||
| // Delay reporting a bit in case the analysis is short in order to reduce UI flicker. | ||
| _running = true; | ||
| _reportTimer?.Dispose(); | ||
| _reportTimer = new Timer(OnReportTimer, null, _initialDelay, _reportingInterval); | ||
| } | ||
|
|
||
| _disposeTimer?.Dispose(); | ||
| _disposeTimer = new Timer(OnDisposeTimer, ++_disposedId, _disposeInterval, Timeout.Infinite); | ||
| if (count >= 0) { | ||
| _lastReportedCount = count; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void OnReportTimer(object o) { | ||
| lock (_lock) { | ||
| if (_running && _lastReportedToClient != _lastReportedCount) { | ||
| _lastReportedToClient = _lastReportedCount; | ||
| _progress = _progress ?? _progressService.BeginProgress(); | ||
| if (_lastReportedCount > 0) { | ||
| _progress?.Report(Resources.AnalysisProgress.FormatUI(_lastReportedCount)).DoNotWait(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void OnDisposeTimer(object o) { | ||
| lock (_lock) { | ||
| if (_disposedId == (int)o) { | ||
| EndReport(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void EndReport() { | ||
| if (_running) { | ||
| _running = false; | ||
| _progress?.Dispose(); | ||
| _progress = null; | ||
|
|
||
| _reportTimer?.Dispose(); | ||
| _disposeTimer?.Dispose(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.