-
Notifications
You must be signed in to change notification settings - Fork 8
Periodic Refresh Timer per Session and and use with CPU Time Info #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d2240c0
Add Periodic Refresh Timer
jreineckearm cd54a47
Start Refresh Timer on step operations (DAP does not mandate continue…
jreineckearm 0c67124
copilot feedback
jreineckearm 0b54797
Test CPU states on periodic refresh
jreineckearm a9f436f
Periodic refresh timer tests
jreineckearm cef50ac
refresh timer management tests in debug tracker
jreineckearm 3847694
copilot feedback
jreineckearm 56f74c5
fix snapshot name after moving test around
jreineckearm 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
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
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,83 @@ | ||
| /** | ||
| * Copyright 2025 Arm Limited | ||
| * | ||
| * 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 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { PeriodicRefreshTimer } from './periodic-refresh-timer'; | ||
|
|
||
| describe('PeriodicRefreshTimer', () => { | ||
| let refreshTimer: PeriodicRefreshTimer<string>; | ||
|
|
||
| beforeEach(() => { | ||
| refreshTimer = new PeriodicRefreshTimer<string>('test-timer', 10); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Ensure underlying node timer is cleaned up. | ||
| refreshTimer.stop(); | ||
| }); | ||
|
|
||
| it('returns correct enabled state through getter function', () => { | ||
| refreshTimer.enabled = true; | ||
| expect(refreshTimer.enabled).toBe(true); | ||
| refreshTimer.enabled = false; | ||
| expect(refreshTimer.enabled).toBe(false); | ||
| }); | ||
|
|
||
| it('does not start if not enabled', () => { | ||
| // Start timer when not enabled | ||
| refreshTimer.start(); | ||
| expect(refreshTimer.isRunning).toBe(false); | ||
| }); | ||
|
|
||
| it('starts if enabled and stops', () => { | ||
| // Start timer when enabled | ||
| refreshTimer.enabled = true; | ||
| refreshTimer.start(); | ||
| expect(refreshTimer.isRunning).toBe(true); | ||
| // Stop timer | ||
| refreshTimer.stop(); | ||
| expect(refreshTimer.isRunning).toBe(false); | ||
| }); | ||
|
|
||
| it('starts if enabled and stops when disabled', () => { | ||
| // Start timer when enabled | ||
| refreshTimer.enabled = true; | ||
| refreshTimer.start(); | ||
| expect(refreshTimer.isRunning).toBe(true); | ||
| // Disable timer | ||
| refreshTimer.enabled = false; | ||
| expect(refreshTimer.isRunning).toBe(false); | ||
| }); | ||
|
|
||
| it('fires periodic refresh events', async () => { | ||
| // Register listener function | ||
| const refreshListener = jest.fn(); | ||
| refreshTimer.onRefresh(refreshListener); | ||
| // Start timer when enabled | ||
| refreshTimer.enabled = true; | ||
| refreshTimer.start(); | ||
| expect(refreshTimer.isRunning).toBe(true); | ||
| // Wait for a few intervals | ||
| await new Promise((resolve) => setTimeout(resolve, 25)); | ||
| // Stop timer | ||
| refreshTimer.stop(); | ||
| // Between one and two calls should have been made. | ||
| // Timing sensitive, so only check we are in an expected range rather | ||
| // than full accuracy. | ||
| expect(refreshListener.mock.calls.length).toBeGreaterThanOrEqual(1); | ||
| expect(refreshListener.mock.calls.length).toBeLessThanOrEqual(2); | ||
| expect(refreshListener).toHaveBeenCalledWith('test-timer'); | ||
| }); | ||
| }); |
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,64 @@ | ||
| /** | ||
| * Copyright 2025 Arm Limited | ||
| * | ||
| * 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 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as vscode from 'vscode'; | ||
|
|
||
| const DEFAULT_REFRESH_INTERVAL = 500; | ||
|
|
||
| export class PeriodicRefreshTimer<T> { | ||
| private _enabled: boolean = false; | ||
| private _timer: NodeJS.Timeout|undefined; | ||
|
|
||
| private readonly _onRefresh: vscode.EventEmitter<T> = new vscode.EventEmitter<T>(); | ||
| public readonly onRefresh: vscode.Event<T> = this._onRefresh.event; | ||
|
|
||
| public get enabled(): boolean { | ||
| return this._enabled; | ||
| } | ||
|
|
||
| public set enabled(value: boolean) { | ||
| this._enabled = value; | ||
| if (!value) { | ||
| this.stop(); | ||
| } | ||
| } | ||
|
|
||
| public get isRunning(): boolean { | ||
| return !!this._timer; | ||
| } | ||
|
|
||
| constructor(public session: T, public interval: number = DEFAULT_REFRESH_INTERVAL) { | ||
| } | ||
|
|
||
| public start(): void { | ||
| this.stop(); | ||
| if (!this._enabled) { | ||
| return; | ||
| } | ||
| const doPeriodicRefresh = () => { | ||
| this._onRefresh.fire(this.session); | ||
| this._timer = setTimeout(doPeriodicRefresh, this.interval); | ||
| }; | ||
| this._timer = setTimeout(doPeriodicRefresh, this.interval); | ||
| } | ||
|
|
||
| public stop(): void { | ||
| if (this._timer) { | ||
| clearTimeout(this._timer); | ||
| this._timer = undefined; | ||
| } | ||
| } | ||
| } |
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.