-
- - + + -
- - -
+ +
+
+
+ + Connection Settings +
+ +
+
+
+
+ + +
+ +
+ + +
+ + + + + + +
+
-
- - + +
+ +
+ + + +
+ +
-
- - -
+ +
+
+ Captured Events +
-
- - -
+ +
+
+ Total + 0 +
+
+ Avg Duration + +
+
+ Max Duration + +
+
+ Max Reads + +
+
-
- - - - - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EventClassTextDataApplicationNameHostNameNTUserNameLoginNameClientProcessIDSPIDStartTimeCPUReadsWritesDuration (ms) ↕DatabaseIDDatabaseName
+ 🔍 + No events captured yet.
Configure connection and click Start to begin profiling. +
+
-
-
-
Captured Events
-
- - - - - - - - - - - - - - - - - - -
EventTimestampDuration (ms)CPU (µs)ReadsDatabaseApplicationHost
No events captured yet. Click Start to begin profiling.
+ + - -
+ +
From e8894422229267eff54b798365ce869f87a34b63 Mon Sep 17 00:00:00 2001 From: Hildebrando Chavez Date: Wed, 11 Mar 2026 19:56:19 -0600 Subject: [PATCH 2/4] feat: add event filtering and search functionality to profiler panel - Introduced EventFilter interface to define filter criteria for profiler events. - Added commands for applying and clearing filters from the webview. - Implemented handleApplyFilters and handleClearFilters methods to manage filter state. - Enhanced event polling to apply filters dynamically, allowing for case-insensitive substring matches. - Added a search bar to the profiler panel for quick event searching, with navigation for previous and next matches. - Updated UI to include filter modal and search bar, improving user experience for managing event data. - Refactored event rendering to support new filtering and searching capabilities. --- LICENSE.md | 36 + .../media/highlight-vs2015.min.css | 1 + .../src/views/profiler-panel-provider.ts | 878 ++++++++++++++++-- 3 files changed, 828 insertions(+), 87 deletions(-) create mode 100644 vscode-extension/media/highlight-vs2015.min.css diff --git a/LICENSE.md b/LICENSE.md index e44375e..cd52441 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -19,3 +19,39 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +--- + +## Third-Party Notices + +### highlight.js + +BSD 3-Clause License + +Copyright (c) 2006, Ivan Sagalaev. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vscode-extension/media/highlight-vs2015.min.css b/vscode-extension/media/highlight-vs2015.min.css new file mode 100644 index 0000000..7f6fe11 --- /dev/null +++ b/vscode-extension/media/highlight-vs2015.min.css @@ -0,0 +1 @@ +pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#1e1e1e;color:#dcdcdc}.hljs-keyword,.hljs-literal,.hljs-name,.hljs-symbol{color:#569cd6}.hljs-link{color:#569cd6;text-decoration:underline}.hljs-built_in,.hljs-type{color:#4ec9b0}.hljs-class,.hljs-number{color:#b8d7a3}.hljs-meta .hljs-string,.hljs-string{color:#d69d85}.hljs-regexp,.hljs-template-tag{color:#9a5334}.hljs-formula,.hljs-function,.hljs-params,.hljs-subst,.hljs-title{color:#dcdcdc}.hljs-comment,.hljs-quote{color:#57a64a;font-style:italic}.hljs-doctag{color:#608b4e}.hljs-meta,.hljs-meta .hljs-keyword,.hljs-tag{color:#9b9b9b}.hljs-template-variable,.hljs-variable{color:#bd63c5}.hljs-attr,.hljs-attribute{color:#9cdcfe}.hljs-section{color:gold}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-bullet,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-selector-pseudo,.hljs-selector-tag{color:#d7ba7d}.hljs-addition{background-color:#144212;display:inline-block;width:100%}.hljs-deletion{background-color:#600;display:inline-block;width:100%} \ No newline at end of file diff --git a/vscode-extension/src/views/profiler-panel-provider.ts b/vscode-extension/src/views/profiler-panel-provider.ts index 0046c4a..5e85c9e 100644 --- a/vscode-extension/src/views/profiler-panel-provider.ts +++ b/vscode-extension/src/views/profiler-panel-provider.ts @@ -26,12 +26,25 @@ enum ProfilerState { Paused = "paused", } +/** + * Filter criteria for profiler events — mirrors WinForms EventFilter model. + * All fields are optional substrings (case-insensitive contains match, AND logic). + */ +interface EventFilter { + eventClass: string; + textData: string; + applicationName: string; + ntUserName: string; + loginName: string; + databaseName: string; +} + /** * Message types sent from webview to extension */ interface WebviewIncomingMessage { - command: "start" | "stop" | "pause" | "resume" | "clear"; - data?: ConnectionSettings; + command: "start" | "stop" | "pause" | "resume" | "clear" | "applyFilters" | "clearFilters"; + data?: ConnectionSettings | EventFilter; } /** @@ -43,6 +56,7 @@ interface WebviewOutgoingMessage { | "updateEventCount" | "addEvents" | "clearEvents" + | "updateFilter" | "error"; data?: unknown; } @@ -66,7 +80,15 @@ export class ProfilerPanelProvider { private pollingInterval: NodeJS.Timeout | null = null; private readonly pollingIntervalMs = 900; // Match WinForms implementation private eventCount = 0; - private readonly seenEventKeys = new Set(); + private readonly sessionEventKeys = new Set(); + private eventFilter: EventFilter = { + eventClass: "", + textData: "", + applicationName: "", + ntUserName: "", + loginName: "", + databaseName: "", + }; constructor( extensionUri: vscode.Uri, @@ -159,6 +181,14 @@ export class ProfilerPanelProvider { case "clear": await this.handleClear(); break; + case "applyFilters": + if (message.data && this.isEventFilter(message.data)) { + await this.handleApplyFilters(message.data); + } + break; + case "clearFilters": + await this.handleClearFilters(); + break; default: this.logError(`Unknown command: ${String(message.command)}`); } @@ -190,10 +220,13 @@ export class ProfilerPanelProvider { // Start profiling await this.profilerClient.startProfiling(this.sessionName, settings); + // Clear previous events before showing new session results + this.eventCount = 0; + this.sessionEventKeys.clear(); + await this.postMessage({ command: "clearEvents" }); + // Update state this.state = ProfilerState.Running; - this.eventCount = 0; - this.seenEventKeys.clear(); await this.updateState(); // Start polling for events @@ -205,8 +238,9 @@ export class ProfilerPanelProvider { const errorMessage = error instanceof Error ? error.message : String(error); this.logError(`Failed to start profiling: ${errorMessage}`); + this.state = ProfilerState.Stopped; + await this.updateState(); await this.showError(`Failed to start profiling: ${errorMessage}`); - throw error; } } @@ -256,8 +290,6 @@ export class ProfilerPanelProvider { } this.state = ProfilerState.Stopped; - this.eventCount = 0; - this.seenEventKeys.clear(); await this.updateState(); this.log("Profiling stopped"); @@ -291,12 +323,59 @@ export class ProfilerPanelProvider { private async handleClear(): Promise { this.log("Clearing events"); this.eventCount = 0; - this.seenEventKeys.clear(); + // sessionEventKeys intentionally NOT cleared — session cache must survive Clear + // so that already-seen ring_buffer events cannot re-appear after a clear. await this.postMessage({ command: "clearEvents", }); } + /** + * Applies event filters — takes effect on the next poll cycle. + * Works regardless of profiling state (before start, while running, while paused, after stop). + * @param filter - Filter criteria to apply + */ + private async handleApplyFilters(filter: EventFilter): Promise { + this.eventFilter = filter; + this.log( + `Filters applied: ${JSON.stringify(filter)}`, + ); + await this.postMessage({ command: "updateFilter", data: filter }); + } + + /** + * Clears all active filters. Future events are captured without any filter. + * Already-displayed events in the table are NOT removed. + */ + private async handleClearFilters(): Promise { + this.eventFilter = { + eventClass: "", + textData: "", + applicationName: "", + ntUserName: "", + loginName: "", + databaseName: "", + }; + this.log("Filters cleared"); + await this.postMessage({ command: "updateFilter", data: this.eventFilter }); + } + + /** + * Type guard — checks that a message data object is a valid EventFilter + */ + private isEventFilter(data: unknown): data is EventFilter { + return ( + typeof data === "object" && + data !== null && + "eventClass" in data && + "textData" in data && + "applicationName" in data && + "ntUserName" in data && + "loginName" in data && + "databaseName" in data + ); + } + /** * Starts polling for events * @remarks Polls every 900ms to match WinForms implementation timing @@ -398,12 +477,31 @@ export class ProfilerPanelProvider { ? `seq:${seqKey}` : activityKey ? `activity:${activityKey}` - : `${displayEvent.startTime}|${displayEvent.eventClass}|${sessionId}`; + : `${event.timestamp ?? ""}|${event.name ?? ""}|${sessionId}`; - if (!this.seenEventKeys.has(eventKey)) { - this.seenEventKeys.add(eventKey); - newEvents.push(displayEvent); + if (this.sessionEventKeys.has(eventKey)) { + continue; } + this.sessionEventKeys.add(eventKey); + + // Apply active filters (case-insensitive contains, AND logic). + // Filtered-out events are still added to sessionEventKeys so they won't + // re-surface if the filter is relaxed later in the same session. + const fil = this.eventFilter; + const contains = (value: string, term: string): boolean => + !term || value.toLowerCase().includes(term.toLowerCase()); + if ( + !contains(displayEvent.eventClass, fil.eventClass) || + !contains(displayEvent.textData, fil.textData) || + !contains(displayEvent.applicationName, fil.applicationName) || + !contains(displayEvent.ntUserName, fil.ntUserName) || + !contains(displayEvent.loginName, fil.loginName) || + !contains(displayEvent.databaseName, fil.databaseName) + ) { + continue; + } + + newEvents.push(displayEvent); } if (newEvents.length > 0) { @@ -508,6 +606,16 @@ export class ProfilerPanelProvider { private getHtmlContent(webview: vscode.Webview): string { const authModes = getAllAuthenticationModes(); + const hlJsUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.extensionUri, "media", "highlight.min.js"), + ).toString(); + const hlSqlUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.extensionUri, "media", "highlight-sql.min.js"), + ).toString(); + const hlCssUri = webview.asWebviewUri( + vscode.Uri.joinPath(this.extensionUri, "media", "highlight-vs2015.min.css"), + ).toString(); + return ` @@ -515,6 +623,9 @@ export class ProfilerPanelProvider { Light Query Profiler + + + @@ -1240,6 +1522,13 @@ export class ProfilerPanelProvider { +
+ +
@@ -1269,6 +1558,16 @@ export class ProfilerPanelProvider {